Changeset 391 for python/trunk/Lib/test/test_locale.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/test/test_locale.py
r2 r391 1 from test.test_support import run_unittest, verbose , TestSkipped1 from test.test_support import run_unittest, verbose 2 2 import unittest 3 3 import locale … … 11 11 global enUS_locale 12 12 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") 14 20 if sys.platform.startswith("win"): 15 21 tlocs = ("En", "English") … … 24 30 break 25 31 else: 26 raise TestSkipped(32 raise unittest.SkipTest( 27 33 "Test locale not supported (tried %s)" % (', '.join(tlocs))) 28 34 enUS_locale = tloc … … 222 228 223 229 230 class 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 244 class 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 224 262 class TestNumberFormatting(BaseLocalizedTest, EnUSNumberFormatting): 225 263 # Test number formatting with a real English locale. … … 348 386 self.assertRaises(TypeError, locale.strcoll, u"a", None) 349 387 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 350 417 351 418 def test_main(): 352 419 tests = [ 353 420 TestMiscellaneous, 421 TestFormatPatternArg, 422 TestLocaleFormatString, 354 423 TestEnUSNumberFormatting, 355 424 TestCNumberFormatting, 356 425 TestFrFRNumberFormatting, 357 426 ] 358 # TestSkippedcan't be raised inside unittests, handle it manually instead427 # SkipTest can't be raised inside unittests, handle it manually instead 359 428 try: 360 429 get_enUS_locale() 361 except TestSkippedas e:430 except unittest.SkipTest as e: 362 431 if verbose: 363 432 print "Some tests will be disabled: %s" % e
Note:
See TracChangeset
for help on using the changeset viewer.