try to fix most buildbot failures on test_locale + add a debug output for the solaris buildbot

This commit is contained in:
Antoine Pitrou 2008-07-26 10:29:43 +00:00
parent 92f8216ba1
commit 524f4135dc
1 changed files with 70 additions and 48 deletions

View File

@ -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 locale
import sys
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):
#
# 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):
if sys.platform == 'darwin':
raise TestSkipped(
"Locale support on MacOSX is minimal and cannot be tested")
self.oldlocale = locale.setlocale(self.locale_type)
for tloc in self.tlocs:
try:
locale.setlocale(self.locale_type, tloc)
except locale.Error:
continue
break
else:
raise TestSkipped(
"Test locale not supported (tried %s)" % (', '.join(self.tlocs)))
locale.setlocale(self.locale_type, enUS_locale)
if verbose:
print "testing with \"%s\"..." % tloc,
print "testing with \"%s\"..." % enUS_locale,
def tearDown(self):
locale.setlocale(self.locale_type, self.oldlocale)
@ -132,10 +140,17 @@ class EnUSNumberFormatting(BaseFormattingTest):
def test_grouping_and_padding(self):
self._test_format("%20.f", -42, grouping=1, out='-42'.rjust(20))
try:
self._test_format("%+10.f", -4200, grouping=1,
out=('-4%s200' % self.sep).rjust(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):
self._test_format("%d", 4200, grouping=True, out='4%s200' % self.sep)
@ -209,6 +224,7 @@ class TestCNumberFormatting(CCookedTest, BaseFormattingTest):
self._test_format("%9.2f", 12345.67, grouping=True, out=' 12345.67')
if sys.platform != 'sunos5':
class TestStringMethods(BaseLocalizedTest):
locale_type = locale.LC_CTYPE
@ -216,8 +232,6 @@ class TestStringMethods(BaseLocalizedTest):
def test_isspace(self):
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('\xa1'.isspace(), False)
@ -261,7 +275,15 @@ class TestMiscellaneous(unittest.TestCase):
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__':
test_main()