Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Do not run tests on default locale if it does not worl on all locales.
  • Loading branch information
serhiy-storchaka committed Oct 4, 2024
commit dafd06c8ce1ce4a9777d457f66c26512f3604fa9
10 changes: 5 additions & 5 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,15 +942,15 @@ def run_with_locale(catstr, *locales):
except AttributeError:
# if the test author gives us an invalid category string
raise
except:
except Exception:
# cannot retrieve original locale, so do nothing
locale = orig_locale = None
else:
for loc in locales:
try:
locale.setlocale(category, loc)
break
except:
except locale.Error:
pass

try:
Expand All @@ -967,15 +967,15 @@ def run_with_locales(catstr, *locales):
def deco(func):
@functools.wraps(func)
def wrapper(self, /, *args, **kwargs):
dry_run = True
dry_run = '' in locales
try:
import locale
category = getattr(locale, catstr)
orig_locale = locale.setlocale(category)
except AttributeError:
# if the test author gives us an invalid category string
raise
except:
except Exception:
# cannot retrieve original locale, so do nothing
pass
else:
Expand All @@ -984,7 +984,7 @@ def wrapper(self, /, *args, **kwargs):
with self.subTest(locale=loc):
try:
locale.setlocale(category, loc)
except:
except locale.Error:
self.skipTest(f'no locale {loc!r}')
else:
dry_run = False
Expand Down
16 changes: 9 additions & 7 deletions Lib/test/test_strptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,14 @@ def test_month(self):
# Test for month directives
self.roundtrip('%m', 1)

@run_with_locales('LC_TIME', 'en_US', 'fr_FR', 'de_DE', 'ja_JP', 'he_IL', '')
@run_with_locales('LC_TIME', 'C', 'en_US', 'fr_FR', 'de_DE', 'ja_JP', 'he_IL', '')
def test_month_locale(self):
# Test for month directives
self.roundtrip('%B', 1)
self.roundtrip('%b', 1)
for m in range(1, 13):
self.roundtrip('%B', 1, (1900, m, 1, 0, 0, 0, 0, 1, 0))
self.roundtrip('%b', 1, (1900, m, 1, 0, 0, 0, 0, 1, 0))

def test_day(self):
# Test for day directives
Expand All @@ -336,7 +339,7 @@ def test_hour(self):
self.roundtrip('%H', 3)

# NB: Only works on locales with AM/PM
@run_with_locales('LC_TIME', 'en_US', 'ja_JP')
@run_with_locales('LC_TIME', 'C', 'en_US', 'ja_JP')
def test_hour_locale(self):
# Test hour directives
self.roundtrip('%I %p', 3)
Expand All @@ -361,7 +364,7 @@ def test_weekday(self):
self.roundtrip('%w', 6)
self.roundtrip('%u', 6)

@run_with_locales('LC_TIME', 'en_US', 'fr_FR', 'de_DE', 'ja_JP', '')
@run_with_locales('LC_TIME', 'C', 'en_US', 'fr_FR', 'de_DE', 'ja_JP', '')
def test_weekday_locale(self):
# Test weekday directives
self.roundtrip('%A', 6)
Expand Down Expand Up @@ -467,22 +470,21 @@ def test_bad_timezone(self):
(time.tzname, tz_value, time.daylight, tz_name))

# NB: Does not roundtrip on some locales like hif_FJ.
@run_with_locales('LC_TIME', 'en_US', 'fr_FR', 'de_DE', 'ja_JP', 'he_IL', '')
@run_with_locales('LC_TIME', 'C', 'en_US', 'fr_FR', 'de_DE', 'ja_JP', 'he_IL', '')
def test_date_time_locale(self):
# Test %c directive
self.roundtrip('%c', slice(0, 6))
self.roundtrip('%c', slice(0, 6), (1900, 1, 1, 0, 0, 0, 0, 1, 0))

# NB: Dates before 1969 do not work on locales: C, POSIX,
# az_IR, fa_IR, sd_PK, uk_UA.
# NB: Dates before 1969 do not work on a number of locales, including C.
@run_with_locales('LC_TIME', 'en_US', 'fr_FR', 'de_DE', 'ja_JP')
def test_date_locale(self):
# Test %x directive
self.roundtrip('%x', slice(0, 3))
self.roundtrip('%x', slice(0, 3), (1900, 1, 1, 0, 0, 0, 0, 1, 0))

# NB: Does not distinguish AM/PM time on a number of locales.
@run_with_locales('LC_TIME', 'en_US', 'fr_FR', 'de_DE', 'ja_JP')
@run_with_locales('LC_TIME', 'C', 'en_US', 'fr_FR', 'de_DE', 'ja_JP')
def test_time_locale(self):
# Test %X directive
self.roundtrip('%X', slice(3, 6))
Expand Down