Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4e41a4b

Browse files
committed
Disable a few other tests, that can't work if Python is compiled without
Unicode support.
1 parent 649f8e7 commit 4e41a4b

4 files changed

Lines changed: 30 additions & 18 deletions

File tree

Lib/test/test_builtin.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -582,14 +582,16 @@ def test_getattr(self):
582582
self.assertRaises(TypeError, getattr, sys, 1)
583583
self.assertRaises(TypeError, getattr, sys, 1, "foo")
584584
self.assertRaises(TypeError, getattr)
585-
self.assertRaises(UnicodeError, getattr, sys, unichr(sys.maxunicode))
585+
if have_unicode:
586+
self.assertRaises(UnicodeError, getattr, sys, unichr(sys.maxunicode))
586587

587588
def test_hasattr(self):
588589
import sys
589590
self.assert_(hasattr(sys, 'stdout'))
590591
self.assertRaises(TypeError, hasattr, sys, 1)
591592
self.assertRaises(TypeError, hasattr)
592-
self.assertRaises(UnicodeError, hasattr, sys, unichr(sys.maxunicode))
593+
if have_unicode:
594+
self.assertRaises(UnicodeError, hasattr, sys, unichr(sys.maxunicode))
593595

594596
def test_hash(self):
595597
hash(None)
@@ -1101,7 +1103,8 @@ def test_ord(self):
11011103
if have_unicode:
11021104
self.assertEqual(ord(unichr(sys.maxunicode)), sys.maxunicode)
11031105
self.assertRaises(TypeError, ord, 42)
1104-
self.assertRaises(TypeError, ord, unicode("12"))
1106+
if have_unicode:
1107+
self.assertRaises(TypeError, ord, unicode("12"))
11051108

11061109
def test_pow(self):
11071110
self.assertEqual(pow(0,0), 1)
@@ -1494,11 +1497,17 @@ def test_basic(self):
14941497

14951498
def test_inputtypes(self):
14961499
s = 'abracadabra'
1497-
for T in [unicode, list, tuple]:
1500+
types = [list, tuple]
1501+
if have_unicode:
1502+
types.insert(0, unicode)
1503+
for T in types:
14981504
self.assertEqual(sorted(s), sorted(T(s)))
14991505

15001506
s = ''.join(dict.fromkeys(s).keys()) # unique letters only
1501-
for T in [unicode, set, frozenset, list, tuple, dict.fromkeys]:
1507+
types = [set, frozenset, list, tuple, dict.fromkeys]
1508+
if have_unicode:
1509+
types.insert(0, unicode)
1510+
for T in types:
15021511
self.assertEqual(sorted(s), sorted(T(s)))
15031512

15041513
def test_baddecorator(self):

Lib/test/test_isinstance.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ def test_subclass_tuple(self):
243243
self.assertEqual(True, issubclass(NewSuper, (NewChild, (NewSuper,))))
244244

245245
self.assertEqual(True, issubclass(int, (long, (float, int))))
246-
self.assertEqual(True, issubclass(str, (unicode, (Child, NewChild, basestring))))
246+
if test_support.have_unicode:
247+
self.assertEqual(True, issubclass(str, (unicode, (Child, NewChild, basestring))))
247248

248249
def test_subclass_recursion_limit(self):
249250
# make sure that issubclass raises RuntimeError before the C stack is

Lib/test/test_sys.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ def test_attributes(self):
247247
self.assert_(isinstance(sys.executable, basestring))
248248
self.assert_(isinstance(sys.hexversion, int))
249249
self.assert_(isinstance(sys.maxint, int))
250-
self.assert_(isinstance(sys.maxunicode, int))
250+
if test.test_support.have_unicode:
251+
self.assert_(isinstance(sys.maxunicode, int))
251252
self.assert_(isinstance(sys.platform, basestring))
252253
self.assert_(isinstance(sys.prefix, basestring))
253254
self.assert_(isinstance(sys.version, basestring))

Lib/test/test_textwrap.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -328,17 +328,18 @@ def test_initial_whitespace(self):
328328
self.check_wrap(text, 30,
329329
[" This is a sentence with", "leading whitespace."])
330330

331-
def test_unicode(self):
332-
# *Very* simple test of wrapping Unicode strings. I'm sure
333-
# there's more to it than this, but let's at least make
334-
# sure textwrap doesn't crash on Unicode input!
335-
text = u"Hello there, how are you today?"
336-
self.check_wrap(text, 50, [u"Hello there, how are you today?"])
337-
self.check_wrap(text, 20, [u"Hello there, how are", "you today?"])
338-
olines = self.wrapper.wrap(text)
339-
assert isinstance(olines, list) and isinstance(olines[0], unicode)
340-
otext = self.wrapper.fill(text)
341-
assert isinstance(otext, unicode)
331+
if test_support.have_unicode:
332+
def test_unicode(self):
333+
# *Very* simple test of wrapping Unicode strings. I'm sure
334+
# there's more to it than this, but let's at least make
335+
# sure textwrap doesn't crash on Unicode input!
336+
text = u"Hello there, how are you today?"
337+
self.check_wrap(text, 50, [u"Hello there, how are you today?"])
338+
self.check_wrap(text, 20, [u"Hello there, how are", "you today?"])
339+
olines = self.wrapper.wrap(text)
340+
assert isinstance(olines, list) and isinstance(olines[0], unicode)
341+
otext = self.wrapper.fill(text)
342+
assert isinstance(otext, unicode)
342343

343344
def test_split(self):
344345
# Ensure that the standard _split() method works as advertised

0 commit comments

Comments
 (0)