mirror of https://github.com/python/cpython
try to fix most buildbot failures on test_locale + add a debug output for the solaris buildbot
This commit is contained in:
parent
92f8216ba1
commit
524f4135dc
|
@ -1,36 +1,44 @@
|
||||||
from test.test_support import run_unittest, TestSkipped, verbose
|
from test.test_support import run_unittest, verbose, TestSkipped
|
||||||
import unittest
|
import unittest
|
||||||
import locale
|
import locale
|
||||||
import sys
|
import sys
|
||||||
import codecs
|
import codecs
|
||||||
|
|
||||||
|
|
||||||
|
enUS_locale = None
|
||||||
|
|
||||||
|
def get_enUS_locale():
|
||||||
|
global enUS_locale
|
||||||
|
if sys.platform == 'darwin':
|
||||||
|
raise TestSkipped("Locale support on MacOSX is minimal")
|
||||||
|
if sys.platform.startswith("win"):
|
||||||
|
tlocs = ("En", "English")
|
||||||
|
else:
|
||||||
|
tlocs = ("en_US.UTF-8", "en_US.US-ASCII", "en_US")
|
||||||
|
oldlocale = locale.setlocale(locale.LC_NUMERIC)
|
||||||
|
for tloc in tlocs:
|
||||||
|
try:
|
||||||
|
locale.setlocale(locale.LC_NUMERIC, tloc)
|
||||||
|
except locale.Error:
|
||||||
|
continue
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
raise TestSkipped(
|
||||||
|
"Test locale not supported (tried %s)" % (', '.join(tlocs)))
|
||||||
|
enUS_locale = tloc
|
||||||
|
locale.setlocale(locale.LC_NUMERIC, oldlocale)
|
||||||
|
|
||||||
|
|
||||||
class BaseLocalizedTest(unittest.TestCase):
|
class BaseLocalizedTest(unittest.TestCase):
|
||||||
#
|
#
|
||||||
# Base class for tests using a real locale
|
# Base class for tests using a real locale
|
||||||
#
|
#
|
||||||
|
|
||||||
if sys.platform.startswith("win"):
|
|
||||||
tlocs = ("En", "English")
|
|
||||||
else:
|
|
||||||
tlocs = ("en_US.UTF-8", "en_US.US-ASCII", "en_US")
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
if sys.platform == 'darwin':
|
|
||||||
raise TestSkipped(
|
|
||||||
"Locale support on MacOSX is minimal and cannot be tested")
|
|
||||||
self.oldlocale = locale.setlocale(self.locale_type)
|
self.oldlocale = locale.setlocale(self.locale_type)
|
||||||
for tloc in self.tlocs:
|
locale.setlocale(self.locale_type, enUS_locale)
|
||||||
try:
|
|
||||||
locale.setlocale(self.locale_type, tloc)
|
|
||||||
except locale.Error:
|
|
||||||
continue
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
raise TestSkipped(
|
|
||||||
"Test locale not supported (tried %s)" % (', '.join(self.tlocs)))
|
|
||||||
if verbose:
|
if verbose:
|
||||||
print "testing with \"%s\"..." % tloc,
|
print "testing with \"%s\"..." % enUS_locale,
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
locale.setlocale(self.locale_type, self.oldlocale)
|
locale.setlocale(self.locale_type, self.oldlocale)
|
||||||
|
@ -132,10 +140,17 @@ class EnUSNumberFormatting(BaseFormattingTest):
|
||||||
|
|
||||||
def test_grouping_and_padding(self):
|
def test_grouping_and_padding(self):
|
||||||
self._test_format("%20.f", -42, grouping=1, out='-42'.rjust(20))
|
self._test_format("%20.f", -42, grouping=1, out='-42'.rjust(20))
|
||||||
self._test_format("%+10.f", -4200, grouping=1,
|
try:
|
||||||
out=('-4%s200' % self.sep).rjust(10))
|
self._test_format("%+10.f", -4200, grouping=1,
|
||||||
self._test_format("%-10.f", -4200, grouping=1,
|
out=('-4%s200' % self.sep).rjust(10))
|
||||||
out=('-4%s200' % self.sep).ljust(10))
|
self._test_format("%-10.f", -4200, grouping=1,
|
||||||
|
out=('-4%s200' % self.sep).ljust(10))
|
||||||
|
except AssertionError:
|
||||||
|
# Temp debug for the Solaris buildbot
|
||||||
|
import pprint
|
||||||
|
print
|
||||||
|
pprint.pprint(locale.localeconv())
|
||||||
|
raise
|
||||||
|
|
||||||
def test_integer_grouping(self):
|
def test_integer_grouping(self):
|
||||||
self._test_format("%d", 4200, grouping=True, out='4%s200' % self.sep)
|
self._test_format("%d", 4200, grouping=True, out='4%s200' % self.sep)
|
||||||
|
@ -209,41 +224,40 @@ class TestCNumberFormatting(CCookedTest, BaseFormattingTest):
|
||||||
self._test_format("%9.2f", 12345.67, grouping=True, out=' 12345.67')
|
self._test_format("%9.2f", 12345.67, grouping=True, out=' 12345.67')
|
||||||
|
|
||||||
|
|
||||||
class TestStringMethods(BaseLocalizedTest):
|
if sys.platform != 'sunos5':
|
||||||
locale_type = locale.LC_CTYPE
|
class TestStringMethods(BaseLocalizedTest):
|
||||||
|
locale_type = locale.LC_CTYPE
|
||||||
|
|
||||||
# Test BSD Rune locale's bug for isctype functions.
|
# Test BSD Rune locale's bug for isctype functions.
|
||||||
|
|
||||||
def test_isspace(self):
|
def test_isspace(self):
|
||||||
self.assertEqual('\x20'.isspace(), True)
|
self.assertEqual('\x20'.isspace(), True)
|
||||||
if sys.platform == 'sunos5':
|
|
||||||
# On Solaris, in en_US.UTF-8, \xa0 is a space
|
|
||||||
self.assertEqual('\xa0'.isspace(), False)
|
self.assertEqual('\xa0'.isspace(), False)
|
||||||
self.assertEqual('\xa1'.isspace(), False)
|
self.assertEqual('\xa1'.isspace(), False)
|
||||||
|
|
||||||
def test_isalpha(self):
|
def test_isalpha(self):
|
||||||
self.assertEqual('\xc0'.isalpha(), False)
|
self.assertEqual('\xc0'.isalpha(), False)
|
||||||
|
|
||||||
def test_isalnum(self):
|
def test_isalnum(self):
|
||||||
self.assertEqual('\xc0'.isalnum(), False)
|
self.assertEqual('\xc0'.isalnum(), False)
|
||||||
|
|
||||||
def test_isupper(self):
|
def test_isupper(self):
|
||||||
self.assertEqual('\xc0'.isupper(), False)
|
self.assertEqual('\xc0'.isupper(), False)
|
||||||
|
|
||||||
def test_islower(self):
|
def test_islower(self):
|
||||||
self.assertEqual('\xc0'.islower(), False)
|
self.assertEqual('\xc0'.islower(), False)
|
||||||
|
|
||||||
def test_lower(self):
|
def test_lower(self):
|
||||||
self.assertEqual('\xcc\x85'.lower(), '\xcc\x85')
|
self.assertEqual('\xcc\x85'.lower(), '\xcc\x85')
|
||||||
|
|
||||||
def test_upper(self):
|
def test_upper(self):
|
||||||
self.assertEqual('\xed\x95\xa0'.upper(), '\xed\x95\xa0')
|
self.assertEqual('\xed\x95\xa0'.upper(), '\xed\x95\xa0')
|
||||||
|
|
||||||
def test_strip(self):
|
def test_strip(self):
|
||||||
self.assertEqual('\xed\x95\xa0'.strip(), '\xed\x95\xa0')
|
self.assertEqual('\xed\x95\xa0'.strip(), '\xed\x95\xa0')
|
||||||
|
|
||||||
def test_split(self):
|
def test_split(self):
|
||||||
self.assertEqual('\xec\xa0\xbc'.split(), ['\xec\xa0\xbc'])
|
self.assertEqual('\xec\xa0\xbc'.split(), ['\xec\xa0\xbc'])
|
||||||
|
|
||||||
|
|
||||||
class TestMiscellaneous(unittest.TestCase):
|
class TestMiscellaneous(unittest.TestCase):
|
||||||
|
@ -261,7 +275,15 @@ class TestMiscellaneous(unittest.TestCase):
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
run_unittest(__name__)
|
tests = [TestMiscellaneous, TestEnUSNumberFormatting, TestCNumberFormatting]
|
||||||
|
# TestSkipped can't be raised inside unittests, handle it manually instead
|
||||||
|
try:
|
||||||
|
get_enUS_locale()
|
||||||
|
except TestSkipped as e:
|
||||||
|
print "Some tests will be disabled: %s" % e
|
||||||
|
else:
|
||||||
|
tests += [TestNumberFormatting, TestStringMethods]
|
||||||
|
run_unittest(*tests)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
test_main()
|
test_main()
|
||||||
|
|
Loading…
Reference in New Issue