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.
This commit is contained in:
Walter Dörwald 2007-06-08 14:30:53 +00:00
parent 0157ebe999
commit 9b775535f8
7 changed files with 62 additions and 112 deletions

View File

@ -7,8 +7,7 @@ except ImportError:
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 @@ class AbstractPickleTests(unittest.TestCase):
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

View File

@ -1100,27 +1100,26 @@ class MixinStrUserStringTest:
# 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:

View File

@ -121,9 +121,7 @@ class BinASCIITest(unittest.TestCase):
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)

View File

@ -146,42 +146,35 @@ elif os.name == 'riscos':
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"
# 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:
# 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
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

View File

@ -336,19 +336,6 @@ What a mess!
"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

View File

@ -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 @@ class TypesTests(unittest.TestCase):
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)

View File

@ -4,13 +4,6 @@ import unittest
import xmlrpclib
from test import test_support
try:
str
except NameError:
have_unicode = False
else:
have_unicode = True
alist = [{'astring': 'foo@bar.baz.spam',
'afloat': 7283.43,
'anint': 2**20,
@ -147,15 +140,11 @@ class XMLRPCTestCase(unittest.TestCase):
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)