0001 from test.test_support import verbose, TestSkipped 0002 import locale 0003 import sys 0004 0005 if sys.platform == 'darwin': 0006 raise TestSkipped("Locale support on MacOSX is minimal and cannot be tested") 0007 oldlocale = locale.setlocale(locale.LC_NUMERIC) 0008 0009 if sys.platform.startswith("win"): 0010 tloc = "en" 0011 elif sys.platform.startswith("freebsd"): 0012 tloc = "en_US.US-ASCII" 0013 else: 0014 tloc = "en_US" 0015 0016 try: 0017 locale.setlocale(locale.LC_NUMERIC, tloc) 0018 except locale.Error: 0019 raise ImportError, "test locale %s not supported" % tloc 0020 0021 def testformat(formatstr, value, grouping = 0, output=None): 0022 if verbose: 0023 if output: 0024 print "%s %% %s =? %s ..." %\ 0025 (repr(formatstr), repr(value), repr(output)), 0026 else: 0027 print "%s %% %s works? ..." % (repr(formatstr), repr(value)), 0028 result = locale.format(formatstr, value, grouping = grouping) 0029 if output and result != output: 0030 if verbose: 0031 print 'no' 0032 print "%s %% %s == %s != %s" %\ 0033 (repr(formatstr), repr(value), repr(result), repr(output)) 0034 else: 0035 if verbose: 0036 print "yes" 0037 0038 try: 0039 testformat("%f", 1024, grouping=1, output='1,024.000000') 0040 testformat("%f", 102, grouping=1, output='102.000000') 0041 testformat("%f", -42, grouping=1, output='-42.000000') 0042 testformat("%+f", -42, grouping=1, output='-42.000000') 0043 testformat("%20.f", -42, grouping=1, output=' -42') 0044 testformat("%+10.f", -4200, grouping=1, output=' -4,200') 0045 testformat("%-10.f", 4200, grouping=1, output='4,200 ') 0046 # Invoke getpreferredencoding to make sure it does not cause exceptions, 0047 locale.getpreferredencoding() 0048 finally: 0049 locale.setlocale(locale.LC_NUMERIC, oldlocale) 0050 0051 0052 # Test BSD Rune locale's bug for isctype functions. 0053 def teststrop(s, method, output): 0054 if verbose: 0055 print "%s.%s() =? %s ..." % (repr(s), method, repr(output)), 0056 result = getattr(s, method)() 0057 if result != output: 0058 if verbose: 0059 print "no" 0060 print "%s.%s() == %s != %s" % (repr(s), method, repr(result), 0061 repr(output)) 0062 elif verbose: 0063 print "yes" 0064 0065 try: 0066 oldlocale = locale.setlocale(locale.LC_CTYPE) 0067 locale.setlocale(locale.LC_CTYPE, 'en_US.UTF-8') 0068 except locale.Error: 0069 pass 0070 else: 0071 try: 0072 teststrop('\x20', 'isspace', True) 0073 teststrop('\xa0', 'isspace', False) 0074 teststrop('\xa1', 'isspace', False) 0075 teststrop('\xc0', 'isalpha', False) 0076 teststrop('\xc0', 'isalnum', False) 0077 teststrop('\xc0', 'isupper', False) 0078 teststrop('\xc0', 'islower', False) 0079 teststrop('\xec\xa0\xbc', 'split', ['\xec\xa0\xbc']) 0080 teststrop('\xed\x95\xa0', 'strip', '\xed\x95\xa0') 0081 teststrop('\xcc\x85', 'lower', '\xcc\x85') 0082 teststrop('\xed\x95\xa0', 'upper', '\xed\x95\xa0') 0083 finally: 0084 locale.setlocale(locale.LC_CTYPE, oldlocale) 0085
Generated by PyXR 0.9.4