[Python-3000-checkins] r55826 - python/branches/py3k-struni/Lib/test/pickletester.py python/branches/py3k-struni/Lib/test/string_tests.py python/branches/py3k-struni/Lib/test/test_binascii.py python/branches/py3k-struni/Lib/test/test_support.py python/branches/py3k-struni/Lib/test/test_textwrap.py python/branches/py3k-struni/Lib/test/test_types.py python/branches/py3k-struni/Lib/test/test_xmlrpc.py

walter.doerwald python-3000-checkins at python.org
Fri Jun 8 16:31:04 CEST 2007


Author: walter.doerwald
Date: Fri Jun  8 16:30:53 2007
New Revision: 55826

Modified:
   python/branches/py3k-struni/Lib/test/pickletester.py
   python/branches/py3k-struni/Lib/test/string_tests.py
   python/branches/py3k-struni/Lib/test/test_binascii.py
   python/branches/py3k-struni/Lib/test/test_support.py
   python/branches/py3k-struni/Lib/test/test_textwrap.py
   python/branches/py3k-struni/Lib/test/test_types.py
   python/branches/py3k-struni/Lib/test/test_xmlrpc.py
Log:
Rename checks for test_support.have_unicode (we always
have unicode support now) and either drop the tests or
merge them into the existing tests.


Modified: python/branches/py3k-struni/Lib/test/pickletester.py
==============================================================================
--- python/branches/py3k-struni/Lib/test/pickletester.py	(original)
+++ python/branches/py3k-struni/Lib/test/pickletester.py	Fri Jun  8 16:30:53 2007
@@ -7,8 +7,7 @@
 import pickletools
 import copy_reg
 
-from test.test_support import TestFailed, have_unicode, TESTFN, \
-                              run_with_locale
+from test.test_support import TestFailed, TESTFN, run_with_locale
 
 # Tests that try a number of pickle protocols should have a
 #     for proto in protocols:
@@ -482,15 +481,13 @@
             buf = b"S" + bytes(s) + b"\012p0\012."
             self.assertRaises(ValueError, self.loads, buf)
 
-    if have_unicode:
-        def test_unicode(self):
-            endcases = [str(''), str('<\\u>'), str('<\\\u1234>'),
-                        str('<\n>'),  str('<\\>')]
-            for proto in protocols:
-                for u in endcases:
-                    p = self.dumps(u, proto)
-                    u2 = self.loads(p)
-                    self.assertEqual(u2, u)
+    def test_unicode(self):
+        endcases = ['', '<\\u>', '<\\\u1234>', '<\n>',  '<\\>']
+        for proto in protocols:
+            for u in endcases:
+                p = self.dumps(u, proto)
+                u2 = self.loads(p)
+                self.assertEqual(u2, u)
 
     def test_ints(self):
         import sys

Modified: python/branches/py3k-struni/Lib/test/string_tests.py
==============================================================================
--- python/branches/py3k-struni/Lib/test/string_tests.py	(original)
+++ python/branches/py3k-struni/Lib/test/string_tests.py	Fri Jun  8 16:30:53 2007
@@ -1100,27 +1100,26 @@
     # Additional tests that only work with
     # 8bit compatible object, i.e. str and UserString
 
-    if test_support.have_unicode:
-        def test_encoding_decoding(self):
-            codecs = [('rot13', b'uryyb jbeyq'),
-                      ('base64', b'aGVsbG8gd29ybGQ=\n'),
-                      ('hex', b'68656c6c6f20776f726c64'),
-                      ('uu', b'begin 666 <data>\n+:&5L;&\\@=V]R;&0 \n \nend\n')]
-            for encoding, data in codecs:
-                self.checkequal(data, 'hello world', 'encode', encoding)
-                self.checkequal('hello world', data, 'decode', encoding)
-            # zlib is optional, so we make the test optional too...
-            try:
-                import zlib
-            except ImportError:
-                pass
-            else:
-                data = b'x\x9c\xcbH\xcd\xc9\xc9W(\xcf/\xcaI\x01\x00\x1a\x0b\x04]'
-                self.checkequal(data, 'hello world', 'encode', 'zlib')
-                self.checkequal('hello world', data, 'decode', 'zlib')
+    def test_encoding_decoding(self):
+        codecs = [('rot13', b'uryyb jbeyq'),
+                  ('base64', b'aGVsbG8gd29ybGQ=\n'),
+                  ('hex', b'68656c6c6f20776f726c64'),
+                  ('uu', b'begin 666 <data>\n+:&5L;&\\@=V]R;&0 \n \nend\n')]
+        for encoding, data in codecs:
+            self.checkequal(data, 'hello world', 'encode', encoding)
+            self.checkequal('hello world', data, 'decode', encoding)
+        # zlib is optional, so we make the test optional too...
+        try:
+            import zlib
+        except ImportError:
+            pass
+        else:
+            data = b'x\x9c\xcbH\xcd\xc9\xc9W(\xcf/\xcaI\x01\x00\x1a\x0b\x04]'
+            self.checkequal(data, 'hello world', 'encode', 'zlib')
+            self.checkequal('hello world', data, 'decode', 'zlib')
 
-            self.checkraises(TypeError, 'xyz', 'decode', 42)
-            self.checkraises(TypeError, 'xyz', 'encode', 42)
+        self.checkraises(TypeError, 'xyz', 'decode', 42)
+        self.checkraises(TypeError, 'xyz', 'encode', 42)
 
 
 class MixinStrUnicodeTest:

Modified: python/branches/py3k-struni/Lib/test/test_binascii.py
==============================================================================
--- python/branches/py3k-struni/Lib/test/test_binascii.py	(original)
+++ python/branches/py3k-struni/Lib/test/test_binascii.py	Fri Jun  8 16:30:53 2007
@@ -121,9 +121,7 @@
         self.assertRaises(binascii.Error, binascii.a2b_hex, t[:-1])
         self.assertRaises(binascii.Error, binascii.a2b_hex, t[:-1] + b'q')
 
-        # Verify the treatment of Unicode strings
-        if test_support.have_unicode:
-            self.assertEqual(binascii.hexlify('a'), b'61')
+        self.assertEqual(binascii.hexlify('a'), b'61')
 
     def test_qp(self):
         # A test for SF bug 534347 (segfaults without the proper fix)

Modified: python/branches/py3k-struni/Lib/test/test_support.py
==============================================================================
--- python/branches/py3k-struni/Lib/test/test_support.py	(original)
+++ python/branches/py3k-struni/Lib/test/test_support.py	Fri Jun  8 16:30:53 2007
@@ -146,42 +146,35 @@
     TESTFN = 'testfile'
 else:
     TESTFN = '@test'
-    # Unicode name only used if TEST_FN_ENCODING exists for the platform.
-    if have_unicode:
-        # Assuming sys.getfilesystemencoding()!=sys.getdefaultencoding()
-        # TESTFN_UNICODE is a filename that can be encoded using the
-        # file system encoding, but *not* with the default (ascii) encoding
-        if isinstance('', str):
-            # python -U
-            # XXX perhaps unicode() should accept Unicode strings?
-            TESTFN_UNICODE = "@test-\xe0\xf2"
-        else:
-            # 2 latin characters.
-            TESTFN_UNICODE = str("@test-\xe0\xf2", "latin-1")
-        TESTFN_ENCODING = sys.getfilesystemencoding()
-        # TESTFN_UNICODE_UNENCODEABLE is a filename that should *not* be
-        # able to be encoded by *either* the default or filesystem encoding.
-        # This test really only makes sense on Windows NT platforms
-        # which have special Unicode support in posixmodule.
-        if (not hasattr(sys, "getwindowsversion") or
-                sys.getwindowsversion()[3] < 2): #  0=win32s or 1=9x/ME
-            TESTFN_UNICODE_UNENCODEABLE = None
+
+    # Assuming sys.getfilesystemencoding()!=sys.getdefaultencoding()
+    # TESTFN_UNICODE is a filename that can be encoded using the
+    # file system encoding, but *not* with the default (ascii) encoding
+    TESTFN_UNICODE = "@test-\xe0\xf2"
+    TESTFN_ENCODING = sys.getfilesystemencoding()
+    # TESTFN_UNICODE_UNENCODEABLE is a filename that should *not* be
+    # able to be encoded by *either* the default or filesystem encoding.
+    # This test really only makes sense on Windows NT platforms
+    # which have special Unicode support in posixmodule.
+    if (not hasattr(sys, "getwindowsversion") or
+            sys.getwindowsversion()[3] < 2): #  0=win32s or 1=9x/ME
+        TESTFN_UNICODE_UNENCODEABLE = None
+    else:
+        # Japanese characters (I think - from bug 846133)
+        TESTFN_UNICODE_UNENCODEABLE = "@test-\u5171\u6709\u3055\u308c\u308b"
+        try:
+            # XXX - Note - should be using TESTFN_ENCODING here - but for
+            # Windows, "mbcs" currently always operates as if in
+            # errors=ignore' mode - hence we get '?' characters rather than
+            # the exception.  'Latin1' operates as we expect - ie, fails.
+            # See [ 850997 ] mbcs encoding ignores errors
+            TESTFN_UNICODE_UNENCODEABLE.encode("Latin1")
+        except UnicodeEncodeError:
+            pass
         else:
-            # Japanese characters (I think - from bug 846133)
-            TESTFN_UNICODE_UNENCODEABLE = eval('u"@test-\u5171\u6709\u3055\u308c\u308b"')
-            try:
-                # XXX - Note - should be using TESTFN_ENCODING here - but for
-                # Windows, "mbcs" currently always operates as if in
-                # errors=ignore' mode - hence we get '?' characters rather than
-                # the exception.  'Latin1' operates as we expect - ie, fails.
-                # See [ 850997 ] mbcs encoding ignores errors
-                TESTFN_UNICODE_UNENCODEABLE.encode("Latin1")
-            except UnicodeEncodeError:
-                pass
-            else:
-                print('WARNING: The filename %r CAN be encoded by the filesystem.  ' \
-                'Unicode filename tests may not be effective' \
-                % TESTFN_UNICODE_UNENCODEABLE)
+            print('WARNING: The filename %r CAN be encoded by the filesystem.  ' \
+            'Unicode filename tests may not be effective' \
+            % TESTFN_UNICODE_UNENCODEABLE)
 
 # Make sure we can write to TESTFN, try in /tmp if we can't
 fp = None

Modified: python/branches/py3k-struni/Lib/test/test_textwrap.py
==============================================================================
--- python/branches/py3k-struni/Lib/test/test_textwrap.py	(original)
+++ python/branches/py3k-struni/Lib/test/test_textwrap.py	Fri Jun  8 16:30:53 2007
@@ -336,19 +336,6 @@
                          "with     ", "much white", "space."],
                         drop_whitespace=False)
 
-    if test_support.have_unicode:
-        def test_unicode(self):
-            # *Very* simple test of wrapping Unicode strings.  I'm sure
-            # there's more to it than this, but let's at least make
-            # sure textwrap doesn't crash on Unicode input!
-            text = "Hello there, how are you today?"
-            self.check_wrap(text, 50, ["Hello there, how are you today?"])
-            self.check_wrap(text, 20, ["Hello there, how are", "you today?"])
-            olines = self.wrapper.wrap(text)
-            assert isinstance(olines, list) and isinstance(olines[0], str)
-            otext = self.wrapper.fill(text)
-            assert isinstance(otext, str)
-
     def test_split(self):
         # Ensure that the standard _split() method works as advertised
         # in the comments

Modified: python/branches/py3k-struni/Lib/test/test_types.py
==============================================================================
--- python/branches/py3k-struni/Lib/test/test_types.py	(original)
+++ python/branches/py3k-struni/Lib/test/test_types.py	Fri Jun  8 16:30:53 2007
@@ -1,6 +1,6 @@
 # Python test set -- part 6, built-in types
 
-from test.test_support import run_unittest, have_unicode
+from test.test_support import run_unittest
 import unittest
 import sys
 
@@ -199,19 +199,6 @@
         self.assertEqual(a[100:-100:-1], a[::-1])
         self.assertEqual(a[-100:100:2], '02468')
 
-        if have_unicode:
-            a = str(b'0123456789', 'ascii')
-            self.assertEqual(a[::], a)
-            self.assertEqual(a[::2], str(b'02468', 'ascii'))
-            self.assertEqual(a[1::2], str(b'13579', 'ascii'))
-            self.assertEqual(a[::-1], str(b'9876543210', 'ascii'))
-            self.assertEqual(a[::-2], str(b'97531', 'ascii'))
-            self.assertEqual(a[3::-2], str(b'31', 'ascii'))
-            self.assertEqual(a[-100:100:], a)
-            self.assertEqual(a[100:-100:-1], a[::-1])
-            self.assertEqual(a[-100:100:2], str(b'02468', 'ascii'))
-
-
     def test_type_function(self):
         self.assertRaises(TypeError, type, 1, 2)
         self.assertRaises(TypeError, type, 1, 2, 3, 4)

Modified: python/branches/py3k-struni/Lib/test/test_xmlrpc.py
==============================================================================
--- python/branches/py3k-struni/Lib/test/test_xmlrpc.py	(original)
+++ python/branches/py3k-struni/Lib/test/test_xmlrpc.py	Fri Jun  8 16:30:53 2007
@@ -4,13 +4,6 @@
 import xmlrpclib
 from test import test_support
 
-try:
-    str
-except NameError:
-    have_unicode = False
-else:
-    have_unicode = True
-
 alist = [{'astring': 'foo at bar.baz.spam',
           'afloat': 7283.43,
           'anint': 2**20,
@@ -147,15 +140,11 @@
                 del sys.setdefaultencoding
 
         items = list(d.items())
-        if have_unicode:
-            self.assertEquals(s, "abc \x95")
-            self.assert_(isinstance(s, str))
-            self.assertEquals(items, [("def \x96", "ghi \x97")])
-            self.assert_(isinstance(items[0][0], str))
-            self.assert_(isinstance(items[0][1], str))
-        else:
-            self.assertEquals(s, "abc \xc2\x95")
-            self.assertEquals(items, [("def \xc2\x96", "ghi \xc2\x97")])
+        self.assertEquals(s, "abc \x95")
+        self.assert_(isinstance(s, str))
+        self.assertEquals(items, [("def \x96", "ghi \x97")])
+        self.assert_(isinstance(items[0][0], str))
+        self.assert_(isinstance(items[0][1], str))
 
 def test_main():
     test_support.run_unittest(XMLRPCTestCase)


More information about the Python-3000-checkins mailing list