[Python-3000-checkins] r55511 - python/branches/py3k-struni/Lib/test/test_array.py python/branches/py3k-struni/Lib/test/test_builtin.py python/branches/py3k-struni/Lib/test/test_complex.py python/branches/py3k-struni/Lib/test/test_contains.py python/branches/py3k-struni/Lib/test/test_isinstance.py python/branches/py3k-struni/Lib/test/test_iter.py python/branches/py3k-struni/Lib/test/test_unary.py

walter.doerwald python-3000-checkins at python.org
Tue May 22 18:53:03 CEST 2007


Author: walter.doerwald
Date: Tue May 22 18:52:54 2007
New Revision: 55511

Modified:
   python/branches/py3k-struni/Lib/test/test_array.py
   python/branches/py3k-struni/Lib/test/test_builtin.py
   python/branches/py3k-struni/Lib/test/test_complex.py
   python/branches/py3k-struni/Lib/test/test_contains.py
   python/branches/py3k-struni/Lib/test/test_isinstance.py
   python/branches/py3k-struni/Lib/test/test_iter.py
   python/branches/py3k-struni/Lib/test/test_unary.py
Log:
Remove have_unicode checks and merge those tests into the
normal code (or drop them if they only repeat previous
tests).


Modified: python/branches/py3k-struni/Lib/test/test_array.py
==============================================================================
--- python/branches/py3k-struni/Lib/test/test_array.py	(original)
+++ python/branches/py3k-struni/Lib/test/test_array.py	Tue May 22 18:52:54 2007
@@ -752,35 +752,34 @@
 
 tests.append(CharacterTest)
 
-if test_support.have_unicode:
-    class UnicodeTest(StringTest):
-        typecode = 'u'
-        example = '\x01\u263a\x00\ufeff'
-        smallerexample = '\x01\u263a\x00\ufefe'
-        biggerexample = '\x01\u263a\x01\ufeff'
-        outside = str('\x33')
-        minitemsize = 2
-
-        def test_unicode(self):
-            self.assertRaises(TypeError, array.array, 'b', 'foo')
-
-            a = array.array('u', '\xa0\xc2\u1234')
-            a.fromunicode(' ')
-            a.fromunicode('')
-            a.fromunicode('')
-            a.fromunicode('\x11abc\xff\u1234')
-            s = a.tounicode()
-            self.assertEqual(s, '\xa0\xc2\u1234 \x11abc\xff\u1234')
-
-            s = '\x00="\'a\\b\x80\xff\u0000\u0001\u1234'
-            a = array.array('u', s)
-            self.assertEqual(
-                repr(a),
-                "array('u', '\\x00=\"\\'a\\\\b\\x80\\xff\\x00\\x01\\u1234')")
+class UnicodeTest(StringTest):
+    typecode = 'u'
+    example = '\x01\u263a\x00\ufeff'
+    smallerexample = '\x01\u263a\x00\ufefe'
+    biggerexample = '\x01\u263a\x01\ufeff'
+    outside = str('\x33')
+    minitemsize = 2
+
+    def test_unicode(self):
+        self.assertRaises(TypeError, array.array, 'b', 'foo')
+
+        a = array.array('u', '\xa0\xc2\u1234')
+        a.fromunicode(' ')
+        a.fromunicode('')
+        a.fromunicode('')
+        a.fromunicode('\x11abc\xff\u1234')
+        s = a.tounicode()
+        self.assertEqual(s, '\xa0\xc2\u1234 \x11abc\xff\u1234')
+
+        s = '\x00="\'a\\b\x80\xff\u0000\u0001\u1234'
+        a = array.array('u', s)
+        self.assertEqual(
+            repr(a),
+            "array('u', '\\x00=\"\\'a\\\\b\\x80\\xff\\x00\\x01\\u1234')")
 
-            self.assertRaises(TypeError, a.fromunicode)
+        self.assertRaises(TypeError, a.fromunicode)
 
-    tests.append(UnicodeTest)
+tests.append(UnicodeTest)
 
 class NumberTest(BaseTest):
 

Modified: python/branches/py3k-struni/Lib/test/test_builtin.py
==============================================================================
--- python/branches/py3k-struni/Lib/test/test_builtin.py	(original)
+++ python/branches/py3k-struni/Lib/test/test_builtin.py	Tue May 22 18:52:54 2007
@@ -1,8 +1,8 @@
 # Python test set -- built-in functions
 
 import test.test_support, unittest
-from test.test_support import fcmp, have_unicode, TESTFN, unlink, \
-                              run_unittest, run_with_locale
+from test.test_support import fcmp, TESTFN, unlink,  run_unittest, \
+                              run_with_locale
 from operator import neg
 
 import sys, warnings, cStringIO, random, UserDict
@@ -70,26 +70,8 @@
         ('  1\02  ', ValueError),
         ('', ValueError),
         (' ', ValueError),
-        ('  \t\t  ', ValueError)
-]
-if have_unicode:
-    L += [
-        (str('0'), 0),
-        (str('1'), 1),
-        (str('9'), 9),
-        (str('10'), 10),
-        (str('99'), 99),
-        (str('100'), 100),
-        (str('314'), 314),
-        (str(' 314'), 314),
+        ('  \t\t  ', ValueError),
         (str(b'\u0663\u0661\u0664 ','raw-unicode-escape'), 314),
-        (str('  \t\t  314  \t\t  '), 314),
-        (str('  1x'), ValueError),
-        (str('  1  '), 1),
-        (str('  1\02  '), ValueError),
-        (str(''), ValueError),
-        (str(' '), ValueError),
-        (str('  \t\t  '), ValueError),
         (chr(0x200), ValueError),
 ]
 
@@ -186,6 +168,11 @@
         self.assertEqual(chr(97), 'a')
         self.assertEqual(chr(0xff), '\xff')
         self.assertRaises(ValueError, chr, 1<<24)
+        self.assertEqual(
+            chr(sys.maxunicode),
+            str(('\\U%08x' % (sys.maxunicode)).encode("ascii"), 'unicode-escape')
+        )
+        self.assertRaises(ValueError, chr, sys.maxunicode+1)
         self.assertRaises(TypeError, chr)
 
     def XXX_test_cmp(self):
@@ -219,11 +206,9 @@
         self.assertRaises(TypeError, compile, chr(0), 'f', 'exec')
         self.assertRaises(TypeError, compile, 'pass', '?', 'exec',
                           mode='eval', source='0', filename='tmp')
-        if have_unicode:
-            compile('print("\xe5")\n', '', 'exec')
-            self.assertRaises(TypeError, compile, chr(0), 'f', 'exec')
-            self.assertRaises(ValueError, compile, str('a = 1'), 'f', 'bad')
-
+        compile('print("\xe5")\n', '', 'exec')
+        self.assertRaises(TypeError, compile, chr(0), 'f', 'exec')
+        self.assertRaises(ValueError, compile, str('a = 1'), 'f', 'bad')
 
     def test_delattr(self):
         import sys
@@ -328,19 +313,11 @@
         self.assertEqual(eval('a', globals, locals), 1)
         self.assertEqual(eval('b', globals, locals), 200)
         self.assertEqual(eval('c', globals, locals), 300)
-        if have_unicode:
-            self.assertEqual(eval(str('1+1')), 2)
-            self.assertEqual(eval(str(' 1+1\n')), 2)
         globals = {'a': 1, 'b': 2}
         locals = {'b': 200, 'c': 300}
-        if have_unicode:
-            self.assertEqual(eval(str('a'), globals), 1)
-            self.assertEqual(eval(str('a'), globals, locals), 1)
-            self.assertEqual(eval(str('b'), globals, locals), 200)
-            self.assertEqual(eval(str('c'), globals, locals), 300)
-##             bom = b'\xef\xbb\xbf'
-##             self.assertEqual(eval(bom + b'a', globals, locals), 1)
-            self.assertEqual(eval('"\xe5"', globals), "\xe5")
+##         bom = b'\xef\xbb\xbf'
+##         self.assertEqual(eval(bom + b'a', globals, locals), 1)
+        self.assertEqual(eval('"\xe5"', globals), "\xe5")
         self.assertRaises(TypeError, eval)
         self.assertRaises(TypeError, eval, ())
 
@@ -512,7 +489,7 @@
         self.assertEqual(filter(lambda x: x>=3, (1, 2, 3, 4)), (3, 4))
         self.assertRaises(TypeError, filter, 42, (1, 2))
 
-        # test bltinmodule.c::filterstring()
+        # test bltinmodule.c::filterunicode()
         self.assertEqual(filter(None, "12"), "12")
         self.assertEqual(filter(lambda x: x>="3", "1234"), "34")
         self.assertRaises(TypeError, filter, 42, "12")
@@ -536,34 +513,8 @@
                 return chr(ord(str.__getitem__(self, index))+1)
         self.assertEqual(filter(lambda x: x>="3", shiftstr("1234")), "345")
 
-        if have_unicode:
-            # test bltinmodule.c::filterunicode()
-            self.assertEqual(filter(None, str("12")), str("12"))
-            self.assertEqual(filter(lambda x: x>="3", str("1234")), str("34"))
-            self.assertRaises(TypeError, filter, 42, str("12"))
-            self.assertRaises(ValueError, filter, lambda x: x >="3", badstr(str("1234")))
-
-            class badunicode(str):
-                def __getitem__(self, index):
-                    return 42
-            self.assertRaises(TypeError, filter, lambda x: x >=42, badunicode("1234"))
-
-            class weirdunicode(str):
-                def __getitem__(self, index):
-                    return weirdunicode(2*str.__getitem__(self, index))
-            self.assertEqual(
-                filter(lambda x: x>=str("33"), weirdunicode("1234")), str("3344"))
-
-            class shiftunicode(str):
-                def __getitem__(self, index):
-                    return chr(ord(str.__getitem__(self, index))+1)
-            self.assertEqual(
-                filter(lambda x: x>=str("3"), shiftunicode("1234")),
-                str("345")
-            )
-
     def test_filter_subclasses(self):
-        # test that filter() never returns tuple, str or unicode subclasses
+        # test that filter() never returns tuple or str subclasses
         # and that the result always goes through __getitem__
         funcs = (None, bool, lambda x: True)
         class tuple2(tuple):
@@ -576,14 +527,6 @@
             tuple2: {(): (), (1, 2, 3): (2, 4, 6)},
             str2:   {"": "", "123": "112233"}
         }
-        if have_unicode:
-            class unicode2(str):
-                def __getitem__(self, index):
-                    return 2*str.__getitem__(self, index)
-            inputs[unicode2] = {
-                str(): str(),
-                str("123"): str("112233")
-            }
 
         for (cls, inps) in inputs.items():
             for (inp, exp) in inps.items():
@@ -605,10 +548,8 @@
         self.assertEqual(float("  3.14  "), 3.14)
         self.assertRaises(ValueError, float, "  0x3.1  ")
         self.assertRaises(ValueError, float, "  -0x3.p-1  ")
-        if have_unicode:
-            self.assertEqual(float(str("  3.14  ")), 3.14)
-            self.assertEqual(float(str(b"  \u0663.\u0661\u0664  ",'raw-unicode-escape')), 3.14)
-            self.assertEqual(float("1"*10000), 1e10000) # Inf on both sides
+        self.assertEqual(float(str(b"  \u0663.\u0661\u0664  ",'raw-unicode-escape')), 3.14)
+        self.assertEqual(float("1"*10000), 1e10000) # Inf on both sides
 
     @run_with_locale('LC_NUMERIC', 'fr_FR', 'de_DE')
     def test_float_with_comma(self):
@@ -687,8 +628,7 @@
         self.assertEqual(hash(1), hash(1))
         self.assertEqual(hash(1), hash(1.0))
         hash('spam')
-        if have_unicode:
-            self.assertEqual(hash('spam'), hash(str('spam')))
+        self.assertEqual(hash('spam'), hash(str8('spam')))
         hash((0,1,2,3))
         def f(): pass
         self.assertRaises(TypeError, hash, [])
@@ -738,8 +678,6 @@
         self.assertEqual(int(-3.5), -3)
         # Different base:
         self.assertEqual(int("10",16), 16)
-        if have_unicode:
-            self.assertEqual(int(str("10"),16), 16)
         # Test conversion from strings and various anomalies
         for s, v in L:
             for sign in "", "+", "-":
@@ -784,9 +722,8 @@
         x = int('1' * 600)
         self.assert_(isinstance(x, int))
 
-        if have_unicode:
-            x = int(chr(0x661) * 600)
-            self.assert_(isinstance(x, int))
+        x = int(chr(0x661) * 600)
+        self.assert_(isinstance(x, int))
 
         self.assertRaises(TypeError, int, 1, 12)
 
@@ -908,8 +845,6 @@
         self.assertRaises(TypeError, iter)
         self.assertRaises(TypeError, iter, 42, 42)
         lists = [("1", "2"), ["1", "2"], "12"]
-        if have_unicode:
-            lists.append(str("12"))
         for l in lists:
             i = iter(l)
             self.assertEqual(next(i), '1')
@@ -1007,24 +942,14 @@
         self.assertEqual(int(3.5), 3)
         self.assertEqual(int(-3.5), -3)
         self.assertEqual(int("-3"), -3)
-        if have_unicode:
-            self.assertEqual(int(str("-3")), -3)
         # Different base:
         self.assertEqual(int("10",16), 16)
-        if have_unicode:
-            self.assertEqual(int(str("10"),16), 16)
         # Check conversions from string (same test set as for int(), and then some)
         LL = [
                 ('1' + '0'*20, 10**20),
                 ('1' + '0'*100, 10**100)
         ]
-        L2 = L[:]
-        if have_unicode:
-            L2 += [
-                (str('1') + str('0')*20, 10**20),
-                (str('1') + str('0')*100, 10**100),
-        ]
-        for s, v in L2 + LL:
+        for s, v in LL:
             for sign in "", "+", "-":
                 for prefix in "", " ", "\t", "  \t\t  ":
                     ss = prefix + sign + s
@@ -1391,11 +1316,8 @@
         self.assertEqual(ord(b'\x80'), 128)
         self.assertEqual(ord(b'\xff'), 255)
 
-        if have_unicode:
-            self.assertEqual(ord(chr(sys.maxunicode)), sys.maxunicode)
+        self.assertEqual(ord(chr(sys.maxunicode)), sys.maxunicode)
         self.assertRaises(TypeError, ord, 42)
-        if have_unicode:
-            self.assertRaises(TypeError, ord, str("12"))
 
     def test_pow(self):
         self.assertEqual(pow(0,0), 1)
@@ -1675,18 +1597,6 @@
         self.assertEqual(type(''),  type('123'))
         self.assertNotEqual(type(''), type(()))
 
-    def test_unichr(self):
-        if have_unicode:
-            self.assertEqual(chr(32), str(' '))
-            self.assertEqual(chr(65), str('A'))
-            self.assertEqual(chr(97), str('a'))
-            self.assertEqual(
-                chr(sys.maxunicode),
-                str(('\\U%08x' % (sys.maxunicode)).encode("ascii"), 'unicode-escape')
-            )
-            self.assertRaises(ValueError, chr, sys.maxunicode+1)
-            self.assertRaises(TypeError, chr)
-
     # We don't want self in vars(), so these are static methods
 
     @staticmethod
@@ -1774,16 +1684,12 @@
 
     def test_inputtypes(self):
         s = 'abracadabra'
-        types = [list, tuple]
-        if have_unicode:
-            types.insert(0, str)
+        types = [list, tuple, str]
         for T in types:
             self.assertEqual(sorted(s), sorted(T(s)))
 
-        s = ''.join(dict.fromkeys(s).keys())  # unique letters only
-        types = [set, frozenset, list, tuple, dict.fromkeys]
-        if have_unicode:
-            types.insert(0, str)
+        s = ''.join(set(s))  # unique letters only
+        types = [str, set, frozenset, list, tuple, dict.fromkeys]
         for T in types:
             self.assertEqual(sorted(s), sorted(T(s)))
 

Modified: python/branches/py3k-struni/Lib/test/test_complex.py
==============================================================================
--- python/branches/py3k-struni/Lib/test/test_complex.py	(original)
+++ python/branches/py3k-struni/Lib/test/test_complex.py	Tue May 22 18:52:54 2007
@@ -226,8 +226,6 @@
         self.assertRaises(TypeError, complex, 1, "1")
 
         self.assertEqual(complex("  3.14+J  "), 3.14+1j)
-        if test_support.have_unicode:
-            self.assertEqual(complex(str("  3.14+J  ")), 3.14+1j)
 
         # SF bug 543840:  complex(string) accepts strings with \0
         # Fixed in 2.3.
@@ -250,9 +248,8 @@
         self.assertRaises(ValueError, complex, "1+2j)")
         self.assertRaises(ValueError, complex, "1+(2j)")
         self.assertRaises(ValueError, complex, "(1+2j)123")
-        if test_support.have_unicode:
-            self.assertRaises(ValueError, complex, str("1"*500))
-            self.assertRaises(ValueError, complex, str("x"))
+        self.assertRaises(ValueError, complex, "1"*500)
+        self.assertRaises(ValueError, complex, "x")
 
         class EvilExc(Exception):
             pass

Modified: python/branches/py3k-struni/Lib/test/test_contains.py
==============================================================================
--- python/branches/py3k-struni/Lib/test/test_contains.py	(original)
+++ python/branches/py3k-struni/Lib/test/test_contains.py	Tue May 22 18:52:54 2007
@@ -1,4 +1,4 @@
-from test.test_support import TestFailed, have_unicode
+from test.test_support import TestFailed
 
 class base_set:
 
@@ -55,36 +55,6 @@
     pass
 
 
-if have_unicode:
-
-    # Test char in Unicode
-
-    check('c' in str('abc'), "'c' not in u'abc'")
-    check('d' not in str('abc'), "'d' in u'abc'")
-
-    check('' in str(''), "'' not in u''")
-    check(str('') in '', "u'' not in ''")
-    check(str('') in str(''), "u'' not in u''")
-    check('' in str('abc'), "'' not in u'abc'")
-    check(str('') in 'abc', "u'' not in 'abc'")
-    check(str('') in str('abc'), "u'' not in u'abc'")
-
-    try:
-        None in str('abc')
-        check(0, "None in u'abc' did not raise error")
-    except TypeError:
-        pass
-
-    # Test Unicode char in Unicode
-
-    check(str('c') in str('abc'), "u'c' not in u'abc'")
-    check(str('d') not in str('abc'), "u'd' in u'abc'")
-
-    # Test Unicode char in string
-
-    check(str('c') in 'abc', "u'c' not in 'abc'")
-    check(str('d') not in 'abc', "u'd' in 'abc'")
-
 # A collection of tests on builtin sequence types
 a = list(range(10))
 for i in a:

Modified: python/branches/py3k-struni/Lib/test/test_isinstance.py
==============================================================================
--- python/branches/py3k-struni/Lib/test/test_isinstance.py	(original)
+++ python/branches/py3k-struni/Lib/test/test_isinstance.py	Tue May 22 18:52:54 2007
@@ -242,8 +242,7 @@
         self.assertEqual(True, issubclass(NewSuper, (NewChild, (NewSuper,))))
 
         self.assertEqual(True, issubclass(int, (int, (float, int))))
-        if test_support.have_unicode:
-            self.assertEqual(True, issubclass(str, (str, (Child, NewChild, basestring))))
+        self.assertEqual(True, issubclass(str, (str, (Child, NewChild, basestring))))
 
     def test_subclass_recursion_limit(self):
         # make sure that issubclass raises RuntimeError before the C stack is

Modified: python/branches/py3k-struni/Lib/test/test_iter.py
==============================================================================
--- python/branches/py3k-struni/Lib/test/test_iter.py	(original)
+++ python/branches/py3k-struni/Lib/test/test_iter.py	Tue May 22 18:52:54 2007
@@ -1,7 +1,7 @@
 # Test iterators.
 
 import unittest
-from test.test_support import run_unittest, TESTFN, unlink, have_unicode
+from test.test_support import run_unittest, TESTFN, unlink
 
 # Test result of triple loop (too big to inline)
 TRIPLETS = [(0, 0, 0), (0, 0, 1), (0, 0, 2),
@@ -213,13 +213,6 @@
     def test_iter_string(self):
         self.check_for_loop(iter("abcde"), ["a", "b", "c", "d", "e"])
 
-    # Test a Unicode string
-    if have_unicode:
-        def test_iter_unicode(self):
-            self.check_for_loop(iter(str("abcde")),
-                                [str("a"), str("b"), str("c"),
-                                 str("d"), str("e")])
-
     # Test a directory
     def test_iter_dict(self):
         dict = {}
@@ -500,7 +493,6 @@
             for y in NoGuessLen5(), Guess3Len5(), Guess30Len5():
                 self.assertEqual(lzip(x, y), expected)
 
-    # This test case will be removed if we don't have Unicode
     def test_unicode_join_endcase(self):
 
         # This class inserts a Unicode object into its argument's natural
@@ -517,7 +509,7 @@
                 i = self.i
                 self.i = i+1
                 if i == 2:
-                    return str("fooled you!")
+                    return "fooled you!"
                 return next(self.it)
 
         f = open(TESTFN, "w")
@@ -541,8 +533,6 @@
                 unlink(TESTFN)
             except OSError:
                 pass
-    if not have_unicode:
-        def test_unicode_join_endcase(self): pass
 
     # Test iterators with 'x in y' and 'x not in y'.
     def test_in_and_not_in(self):

Modified: python/branches/py3k-struni/Lib/test/test_unary.py
==============================================================================
--- python/branches/py3k-struni/Lib/test/test_unary.py	(original)
+++ python/branches/py3k-struni/Lib/test/test_unary.py	Tue May 22 18:52:54 2007
@@ -1,7 +1,7 @@
 """Test compiler changes for unary ops (+, -, ~) introduced in Python 2.2"""
 
 import unittest
-from test.test_support import run_unittest, have_unicode
+from test.test_support import run_unittest
 
 class UnaryOpTestCase(unittest.TestCase):
 


More information about the Python-3000-checkins mailing list