@@ -1988,8 +1988,6 @@ def test_valuerror_messages(self):
1988
1988
r"(year|month|day) must be in \d+\.\.\d+, not \d+"
1989
1989
)
1990
1990
test_cases = [
1991
- (2009 , 1 , 32 ), # Day out of range
1992
- (2009 , 2 , 31 ), # Day out of range
1993
1991
(2009 , 13 , 1 ), # Month out of range
1994
1992
(2009 , 0 , 1 ), # Month out of range
1995
1993
(10000 , 12 , 31 ), # Year out of range
@@ -2000,6 +1998,11 @@ def test_valuerror_messages(self):
2000
1998
with self .assertRaisesRegex (ValueError , pattern ):
2001
1999
self .theclass (* case )
2002
2000
2001
+ # days out of range have their own error message, see issue 70647
2002
+ with self .assertRaises (ValueError ) as msg :
2003
+ self .theclass (2009 , 1 , 32 )
2004
+ self .assertIn (f"day 32 must be in range 1..31 for month 1 in year 2009" , str (msg .exception ))
2005
+
2003
2006
def test_fromisoformat (self ):
2004
2007
# Test that isoformat() is reversible
2005
2008
base_dates = [
@@ -3259,7 +3262,6 @@ def test_valuerror_messages(self):
3259
3262
(2009 , 4 , 1 , 12 , 30 , 90 ), # Second out of range
3260
3263
(2009 , 4 , 1 , 12 , 90 , 45 ), # Minute out of range
3261
3264
(2009 , 4 , 1 , 25 , 30 , 45 ), # Hour out of range
3262
- (2009 , 4 , 32 , 24 , 0 , 0 ), # Day out of range
3263
3265
(2009 , 13 , 1 , 24 , 0 , 0 ), # Month out of range
3264
3266
(9999 , 12 , 31 , 24 , 0 , 0 ), # Year out of range
3265
3267
]
@@ -3268,6 +3270,11 @@ def test_valuerror_messages(self):
3268
3270
with self .assertRaisesRegex (ValueError , pattern ):
3269
3271
self .theclass (* case )
3270
3272
3273
+ # days out of range have their own error message, see issue 70647
3274
+ with self .assertRaises (ValueError ) as msg :
3275
+ self .theclass (2009 , 4 , 32 , 24 , 0 , 0 )
3276
+ self .assertIn (f"day 32 must be in range 1..30 for month 4 in year 2009" , str (msg .exception ))
3277
+
3271
3278
def test_fromisoformat_datetime (self ):
3272
3279
# Test that isoformat() is reversible
3273
3280
base_dates = [
@@ -3575,7 +3582,6 @@ def test_fromisoformat_fails_datetime_valueerror(self):
3575
3582
"2009-04-01T12:30:90" , # Second out of range
3576
3583
"2009-04-01T12:90:45" , # Minute out of range
3577
3584
"2009-04-01T25:30:45" , # Hour out of range
3578
- "2009-04-32T24:00:00" , # Day out of range
3579
3585
"2009-13-01T24:00:00" , # Month out of range
3580
3586
"9999-12-31T24:00:00" , # Year out of range
3581
3587
]
@@ -3585,6 +3591,11 @@ def test_fromisoformat_fails_datetime_valueerror(self):
3585
3591
with self .assertRaisesRegex (ValueError , pattern ):
3586
3592
self .theclass .fromisoformat (bad_str )
3587
3593
3594
+ # days out of range have their own error message, see issue 70647
3595
+ with self .assertRaises (ValueError ) as msg :
3596
+ self .theclass .fromisoformat ("2009-04-32T24:00:00" )
3597
+ self .assertIn (f"day 32 must be in range 1..30 for month 4 in year 2009" , str (msg .exception ))
3598
+
3588
3599
def test_fromisoformat_fails_surrogate (self ):
3589
3600
# Test that when fromisoformat() fails with a surrogate character as
3590
3601
# the separator, the error message contains the original string
0 commit comments