Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 451ae18

Browse files
committed
[ 1197218 ] test_locale fix on modern linux
On more modern linuxes (and probably others) straight 'en_US' isn't a valid locale. Make the code try a couple of alternates. backport candidate
1 parent df88846 commit 451ae18

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

Lib/test/test_locale.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@
77
oldlocale = locale.setlocale(locale.LC_NUMERIC)
88

99
if sys.platform.startswith("win"):
10-
tloc = "en"
11-
elif sys.platform.startswith("freebsd"):
12-
tloc = "en_US.US-ASCII"
10+
tlocs = ("en",)
1311
else:
14-
tloc = "en_US"
12+
tlocs = ("en_US.UTF-8", "en_US.US-ASCII", "en_US")
1513

16-
try:
17-
locale.setlocale(locale.LC_NUMERIC, tloc)
18-
except locale.Error:
19-
raise ImportError, "test locale %s not supported" % tloc
14+
for tloc in tlocs:
15+
try:
16+
locale.setlocale(locale.LC_NUMERIC, tloc)
17+
break
18+
except locale.Error:
19+
continue
20+
else:
21+
raise ImportError, "test locale not supported (tried %s)"%(', '.join(tlocs))
2022

2123
def testformat(formatstr, value, grouping = 0, output=None):
2224
if verbose:

0 commit comments

Comments
 (0)