Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/test/test_locale.py

    r2 r391  
    1 from test.test_support import run_unittest, verbose, TestSkipped
     1from test.test_support import run_unittest, verbose
    22import unittest
    33import locale
     
    1111    global enUS_locale
    1212    if sys.platform == 'darwin':
    13         raise TestSkipped("Locale support on MacOSX is minimal")
     13        import os
     14        tlocs = ("en_US.UTF-8", "en_US.ISO8859-1", "en_US")
     15        if int(os.uname()[2].split('.')[0]) < 10:
     16            # The locale test work fine on OSX 10.6, I (ronaldoussoren)
     17            # haven't had time yet to verify if tests work on OSX 10.5
     18            # (10.4 is known to be bad)
     19            raise unittest.SkipTest("Locale support on MacOSX is minimal")
    1420    if sys.platform.startswith("win"):
    1521        tlocs = ("En", "English")
     
    2430        break
    2531    else:
    26         raise TestSkipped(
     32        raise unittest.SkipTest(
    2733            "Test locale not supported (tried %s)" % (', '.join(tlocs)))
    2834    enUS_locale = tloc
     
    222228
    223229
     230class TestFormatPatternArg(unittest.TestCase):
     231    # Test handling of pattern argument of format
     232
     233    def test_onlyOnePattern(self):
     234        # Issue 2522: accept exactly one % pattern, and no extra chars.
     235        self.assertRaises(ValueError, locale.format, "%f\n", 'foo')
     236        self.assertRaises(ValueError, locale.format, "%f\r", 'foo')
     237        self.assertRaises(ValueError, locale.format, "%f\r\n", 'foo')
     238        self.assertRaises(ValueError, locale.format, " %f", 'foo')
     239        self.assertRaises(ValueError, locale.format, "%fg", 'foo')
     240        self.assertRaises(ValueError, locale.format, "%^g", 'foo')
     241        self.assertRaises(ValueError, locale.format, "%f%%", 'foo')
     242
     243
     244class TestLocaleFormatString(unittest.TestCase):
     245    """General tests on locale.format_string"""
     246
     247    def test_percent_escape(self):
     248        self.assertEqual(locale.format_string('%f%%', 1.0), '%f%%' % 1.0)
     249        self.assertEqual(locale.format_string('%d %f%%d', (1, 1.0)),
     250            '%d %f%%d' % (1, 1.0))
     251        self.assertEqual(locale.format_string('%(foo)s %%d', {'foo': 'bar'}),
     252            ('%(foo)s %%d' % {'foo': 'bar'}))
     253
     254    def test_mapping(self):
     255        self.assertEqual(locale.format_string('%(foo)s bing.', {'foo': 'bar'}),
     256            ('%(foo)s bing.' % {'foo': 'bar'}))
     257        self.assertEqual(locale.format_string('%(foo)s', {'foo': 'bar'}),
     258            ('%(foo)s' % {'foo': 'bar'}))
     259
     260
     261
    224262class TestNumberFormatting(BaseLocalizedTest, EnUSNumberFormatting):
    225263    # Test number formatting with a real English locale.
     
    348386            self.assertRaises(TypeError, locale.strcoll, u"a", None)
    349387
     388    def test_setlocale_category(self):
     389        locale.setlocale(locale.LC_ALL)
     390        locale.setlocale(locale.LC_TIME)
     391        locale.setlocale(locale.LC_CTYPE)
     392        locale.setlocale(locale.LC_COLLATE)
     393        locale.setlocale(locale.LC_MONETARY)
     394        locale.setlocale(locale.LC_NUMERIC)
     395
     396        # crasher from bug #7419
     397        self.assertRaises(locale.Error, locale.setlocale, 12345)
     398
     399    def test_getsetlocale_issue1813(self):
     400        # Issue #1813: setting and getting the locale under a Turkish locale
     401        oldlocale = locale.getlocale()
     402        self.addCleanup(locale.setlocale, locale.LC_CTYPE, oldlocale)
     403        try:
     404            locale.setlocale(locale.LC_CTYPE, 'tr_TR')
     405        except locale.Error:
     406            # Unsupported locale on this system
     407            self.skipTest('test needs Turkish locale')
     408        loc = locale.getlocale()
     409        locale.setlocale(locale.LC_CTYPE, loc)
     410        self.assertEqual(loc, locale.getlocale())
     411
     412    def test_normalize_issue12752(self):
     413        # Issue #1813 caused a regression where locale.normalize() would no
     414        # longer accept unicode strings.
     415        self.assertEqual(locale.normalize(u'en_US'), 'en_US.ISO8859-1')
     416
    350417
    351418def test_main():
    352419    tests = [
    353420        TestMiscellaneous,
     421        TestFormatPatternArg,
     422        TestLocaleFormatString,
    354423        TestEnUSNumberFormatting,
    355424        TestCNumberFormatting,
    356425        TestFrFRNumberFormatting,
    357426    ]
    358     # TestSkipped can't be raised inside unittests, handle it manually instead
     427    # SkipTest can't be raised inside unittests, handle it manually instead
    359428    try:
    360429        get_enUS_locale()
    361     except TestSkipped as e:
     430    except unittest.SkipTest as e:
    362431        if verbose:
    363432            print "Some tests will be disabled: %s" % e
Note: See TracChangeset for help on using the changeset viewer.