@@ -2125,6 +2125,7 @@ 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
+ # gh-124529
2128
2129
concerned_formats = '%c' , '%x'
2129
2130
2130
2131
def run_subtest ():
@@ -2138,38 +2139,40 @@ def run_subtest():
2138
2139
try :
2139
2140
parsed = self .theclass .strptime (formatted , fmt )
2140
2141
except ValueError as exc :
2141
- # gh-124529
2142
2142
self .fail (f"{ fail_msg } ; parsing error: { exc !r} " )
2143
2143
self .assertEqual (parsed , expected , fail_msg )
2144
2144
2145
- sample = self .theclass .strptime (f '1999-03-17 ' , '%Y-%m-%d ' )
2145
+ sample = self .theclass .strptime ('1999' , '%Y' )
2146
2146
for fmt in concerned_formats :
2147
2147
with self .subTest (fmt = fmt ):
2148
2148
sample_str = sample .strftime (fmt )
2149
2149
if '1999' in sample_str :
2150
2150
for year in [
2151
- 1 , 9 , 10 , 99 , 100 , 999 , # <- gh-124529
2152
2151
1000 , 1410 , 1989 , 2024 , 2095 , 9999 ,
2152
+ # gh-124529:
2153
+ 1 , 9 , 10 , 99 , 100 , 999 ,
2153
2154
]:
2154
2155
run_subtest ()
2155
2156
elif '99' in sample_str :
2156
2157
for year in [
2157
- 1969 , 1999 ,
2158
- 2000 , 2001 , 2009 , # <- gh-124529
2159
- 2068 ,
2158
+ 1969 , 1999 , 2068 ,
2159
+ # gh-124529:
2160
+ 2000 , 2001 , 2009 ,
2160
2161
]:
2161
2162
run_subtest ()
2162
2163
else :
2163
- self .fail (f"it seems that { sample .strftime (fmt )= } "
2164
- f"does not include year={ sample .year !r} in "
2165
- f"any expected format (is there something "
2166
- f"severely wrong with current locale?)" )
2164
+ self .fail (f"it seems that sample.strftime({ fmt !r} )="
2165
+ f"{ sample_str !r} does not include year="
2166
+ f"{ sample .year !r} in any expected format "
2167
+ f"(is there something severely wrong with "
2168
+ f"current locale?)" )
2167
2169
2168
2170
def test_strptime_accepting_locale_specific_year_with_fewer_digits (self ):
2171
+ # gh-124529
2169
2172
concerned_formats = '%c' , '%x'
2170
2173
2171
2174
def run_subtest ():
2172
- input_str = sample_str .replace (sample_digits , year_digits )
2175
+ input_str = sample_str .replace (sample_year_digits , year_digits )
2173
2176
reason = (f"test strptime accepting locale-specific "
2174
2177
f"year representation with fewer digits "
2175
2178
f"- for { fmt = } and { input_str = } ({ year = } )" )
@@ -2179,27 +2182,27 @@ def run_subtest():
2179
2182
try :
2180
2183
parsed = self .theclass .strptime (input_str , fmt )
2181
2184
except ValueError as exc :
2182
- # gh-124529
2183
2185
self .fail (f"{ fail_msg } ; parsing error: { exc !r} " )
2184
2186
self .assertEqual (parsed , expected , fail_msg )
2185
2187
2186
- sample = self .theclass .strptime (f '1999-03-17 ' , '%Y-%m-%d ' )
2188
+ sample = self .theclass .strptime ('1999' , '%Y' )
2187
2189
for fmt in concerned_formats :
2188
2190
with self .subTest (fmt = fmt ):
2189
2191
sample_str = sample .strftime (fmt )
2190
- if (sample_digits := '1999' ) in sample_str :
2192
+ if (sample_year_digits := '1999' ) in sample_str :
2191
2193
for year in [1 , 9 , 10 , 99 , 100 , 999 ]:
2192
2194
year_digits = str (year )
2193
2195
run_subtest ()
2194
- elif (sample_digits := '99' ) in sample_str :
2196
+ elif (sample_year_digits := '99' ) in sample_str :
2195
2197
for year in [2000 , 2001 , 2009 ]:
2196
2198
year_digits = str (year - 2000 )
2197
2199
run_subtest ()
2198
2200
else :
2199
- self .fail (f"it seems that { sample .strftime (fmt )= } "
2200
- f"does not include year={ sample .year !r} in "
2201
- f"any expected format (is there something "
2202
- f"severely wrong with current locale?)" )
2201
+ self .fail (f"it seems that sample.strftime({ fmt !r} )="
2202
+ f"{ sample_str !r} does not include year="
2203
+ f"{ sample .year !r} in any expected format "
2204
+ f"(is there something severely wrong with "
2205
+ f"current locale?)" )
2203
2206
2204
2207
2205
2208
#############################################################################
0 commit comments