@@ -2125,17 +2125,22 @@ def test_fromisocalendar_type_errors(self):
21252125 self .theclass .fromisocalendar (* isocal )
21262126
21272127 def test_strftime_strptime_roundtrip_concerning_locale_specific_year (self ):
2128- concerned_formats = '%c' , '%x' # gh-124529
2128+ concerned_formats = '%c' , '%x'
21292129
21302130 def run_subtest ():
2131- reason = (f'test strftime/strptime roundtrip concerning '
2132- f'locale-specific year representation '
2133- f'- for { fmt = } and { year = } ' )
2131+ reason = (f"test strftime/strptime roundtrip concerning "
2132+ f"locale-specific year representation "
2133+ f"- for { fmt = } and { year = } " )
2134+ fail_msg = f"{ reason } - failed"
21342135 initial = expected = self .theclass .strptime (f'{ year :04} ' , '%Y' )
21352136 with self .subTest (reason = reason ):
21362137 formatted = initial .strftime (fmt )
2137- parsed = self .theclass .strptime (formatted , fmt )
2138- self .assertEqual (parsed , expected , msg = reason )
2138+ try :
2139+ parsed = self .theclass .strptime (formatted , fmt )
2140+ except ValueError as exc :
2141+ # gh-124529
2142+ self .fail (f"{ fail_msg } ; parsing error: { exc !r} " )
2143+ self .assertEqual (parsed , expected , fail_msg )
21392144
21402145 sample = self .theclass .strptime (f'1999-03-17' , '%Y-%m-%d' )
21412146 for fmt in concerned_formats :
@@ -2161,17 +2166,22 @@ def run_subtest():
21612166 f"severely wrong with current locale?)" )
21622167
21632168 def test_strptime_accepting_locale_specific_year_with_fewer_digits (self ):
2164- concerned_formats = '%c' , '%x' # gh-124529
2169+ concerned_formats = '%c' , '%x'
21652170
21662171 def run_subtest ():
21672172 input_str = sample_str .replace (sample_digits , year_digits )
2168- reason = (f'test strptime accepting locale-specific '
2169- f'year representation with fewer digits '
2170- f'- for { fmt = } and { input_str = } ({ year = } )' )
2173+ reason = (f"test strptime accepting locale-specific "
2174+ f"year representation with fewer digits "
2175+ f"- for { fmt = } and { input_str = } ({ year = } )" )
2176+ fail_msg = f"{ reason } - failed"
21712177 expected = sample .replace (year = year )
21722178 with self .subTest (reason = reason ):
2173- parsed = self .theclass .strptime (input_str , fmt )
2174- self .assertEqual (parsed , expected , msg = reason )
2179+ try :
2180+ parsed = self .theclass .strptime (input_str , fmt )
2181+ except ValueError as exc :
2182+ # gh-124529
2183+ self .fail (f"{ fail_msg } ; parsing error: { exc !r} " )
2184+ self .assertEqual (parsed , expected , fail_msg )
21752185
21762186 sample = self .theclass .strptime (f'1999-03-17' , '%Y-%m-%d' )
21772187 for fmt in concerned_formats :
0 commit comments