Skip to content

Commit bce4b6d

Browse files
committed
Continue enhancing/improving tests
1 parent 6556bdf commit bce4b6d

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

Lib/test/datetimetester.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,17 +2125,23 @@ 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+
else:
2144+
self.assertEqual(parsed, expected, fail_msg)
21392145

21402146
sample = self.theclass.strptime(f'1999-03-17', '%Y-%m-%d')
21412147
for fmt in concerned_formats:
@@ -2161,17 +2167,23 @@ def run_subtest():
21612167
f"severely wrong with current locale?)")
21622168

21632169
def test_strptime_accepting_locale_specific_year_with_fewer_digits(self):
2164-
concerned_formats = '%c', '%x' # gh-124529
2170+
concerned_formats = '%c', '%x'
21652171

21662172
def run_subtest():
21672173
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"
21712178
expected = sample.replace(year=year)
21722179
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)
21752187

21762188
sample = self.theclass.strptime(f'1999-03-17', '%Y-%m-%d')
21772189
for fmt in concerned_formats:

Lib/test/test_strptime.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,22 +174,26 @@ def test_compile(self):
174174
# gh-124529
175175
params = _input_str_and_expected_year_for_few_digits_year(fmt)
176176
if params is None:
177-
self.skipTest(f"this subtest needs locale for which "
178-
f"{fmt!r} includes year in some variant")
177+
self.fail(f"it seems that using {fmt=} results in value "
178+
f"which does not include year representation "
179+
f"in any expected format (is there something "
180+
f"severely wrong with current locale?)")
179181
input_string, _ = params
180182
compiled = self.time_re.compile(fmt)
181183
found = compiled.match(input_string)
182184
self.assertTrue(found,
183185
(f"Matching failed on '{input_string}' "
184186
f"using '{compiled.pattern}' regex"))
185-
for directive in ('y', 'Y'):
187+
for directive in ('y', 'Y', 'G'):
186188
fmt = "%" + directive
187189
with self.subTest(f"{fmt!r} should not match input containing "
188190
f"year with fewer digits than usual"):
189191
params = _input_str_and_expected_year_for_few_digits_year(fmt)
190192
if params is None:
191-
self.skipTest(f"this subtest needs locale for which "
192-
f"{fmt!r} includes year in some variant")
193+
self.fail(f"it seems that using {fmt=} results in value "
194+
f"which does not include year representation "
195+
f"in any expected format (is there something "
196+
f"severely wrong with current locale?)")
193197
input_string, _ = params
194198
compiled = self.time_re.compile(fmt)
195199
found = compiled.match(input_string)
@@ -334,8 +338,10 @@ def helper_for_directives_accepting_few_digits_year(self, directive):
334338
fmt = "%" + directive
335339
params = _input_str_and_expected_year_for_few_digits_year(fmt)
336340
if params is None:
337-
self.skipTest(f"test needs locale for which {fmt!r} "
338-
f"includes year in some variant")
341+
self.fail(f"it seems that using {fmt=} results in value "
342+
f"which does not include year representation "
343+
f"in any expected format (is there something "
344+
f"severely wrong with current locale?)")
339345
input_string, expected_year = params
340346
try:
341347
output_year = _strptime._strptime(input_string, fmt)[0][0]

0 commit comments

Comments
 (0)