@@ -2125,17 +2125,23 @@ def test_fromisocalendar_type_errors(self):
2125
2125
self .theclass .fromisocalendar (* isocal )
2126
2126
2127
2127
def test_strftime_strptime_roundtrip_concerning_locale_specific_year (self ):
2128
- concerned_formats = '%c' , '%x' # gh-124529
2128
+ concerned_formats = '%c' , '%x'
2129
2129
2130
2130
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"
2134
2135
initial = expected = self .theclass .strptime (f'{ year :04} ' , '%Y' )
2135
2136
with self .subTest (reason = reason ):
2136
2137
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
+ else :
2144
+ self .assertEqual (parsed , expected , fail_msg )
2139
2145
2140
2146
sample = self .theclass .strptime (f'1999-03-17' , '%Y-%m-%d' )
2141
2147
for fmt in concerned_formats :
@@ -2161,17 +2167,23 @@ def run_subtest():
2161
2167
f"severely wrong with current locale?)" )
2162
2168
2163
2169
def test_strptime_accepting_locale_specific_year_with_fewer_digits (self ):
2164
- concerned_formats = '%c' , '%x' # gh-124529
2170
+ concerned_formats = '%c' , '%x'
2165
2171
2166
2172
def run_subtest ():
2167
2173
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 = } )' )
2174
+ reason = (f"test strptime accepting locale-specific "
2175
+ f"year representation with fewer digits "
2176
+ f"- for { fmt = } and { input_str = } ({ year = } )" )
2177
+ fail_msg = f"{ reason } - failed"
2171
2178
expected = sample .replace (year = year )
2172
2179
with self .subTest (reason = reason ):
2173
- parsed = self .theclass .strptime (input_str , fmt )
2174
- self .assertEqual (parsed , expected , msg = reason )
2180
+ try :
2181
+ parsed = self .theclass .strptime (input_str , fmt )
2182
+ except ValueError as exc :
2183
+ # gh-124529
2184
+ self .fail (f"{ fail_msg } ; parsing error: { exc !r} " )
2185
+ else :
2186
+ self .assertEqual (parsed , expected , fail_msg )
2175
2187
2176
2188
sample = self .theclass .strptime (f'1999-03-17' , '%Y-%m-%d' )
2177
2189
for fmt in concerned_formats :
0 commit comments