Commit 9b775535 authored by Walter Dörwald's avatar Walter Dörwald

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.
parent 0157ebe9
...@@ -7,8 +7,7 @@ except ImportError: ...@@ -7,8 +7,7 @@ except ImportError:
import pickletools import pickletools
import copy_reg import copy_reg
from test.test_support import TestFailed, have_unicode, TESTFN, \ from test.test_support import TestFailed, TESTFN, run_with_locale
run_with_locale
# Tests that try a number of pickle protocols should have a # Tests that try a number of pickle protocols should have a
# for proto in protocols: # for proto in protocols:
...@@ -482,15 +481,13 @@ class AbstractPickleTests(unittest.TestCase): ...@@ -482,15 +481,13 @@ class AbstractPickleTests(unittest.TestCase):
buf = b"S" + bytes(s) + b"\012p0\012." buf = b"S" + bytes(s) + b"\012p0\012."
self.assertRaises(ValueError, self.loads, buf) self.assertRaises(ValueError, self.loads, buf)
if have_unicode: def test_unicode(self):
def test_unicode(self): endcases = ['', '<\\u>', '<\\\u1234>', '<\n>', '<\\>']
endcases = [str(''), str('<\\u>'), str('<\\\u1234>'), for proto in protocols:
str('<\n>'), str('<\\>')] for u in endcases:
for proto in protocols: p = self.dumps(u, proto)
for u in endcases: u2 = self.loads(p)
p = self.dumps(u, proto) self.assertEqual(u2, u)
u2 = self.loads(p)
self.assertEqual(u2, u)
def test_ints(self): def test_ints(self):
import sys import sys
......
...@@ -1100,27 +1100,26 @@ class MixinStrUserStringTest: ...@@ -1100,27 +1100,26 @@ class MixinStrUserStringTest:
# Additional tests that only work with # Additional tests that only work with
# 8bit compatible object, i.e. str and UserString # 8bit compatible object, i.e. str and UserString
if test_support.have_unicode: def test_encoding_decoding(self):
def test_encoding_decoding(self): codecs = [('rot13', b'uryyb jbeyq'),
codecs = [('rot13', b'uryyb jbeyq'), ('base64', b'aGVsbG8gd29ybGQ=\n'),
('base64', b'aGVsbG8gd29ybGQ=\n'), ('hex', b'68656c6c6f20776f726c64'),
('hex', b'68656c6c6f20776f726c64'), ('uu', b'begin 666 <data>\n+:&5L;&\\@=V]R;&0 \n \nend\n')]
('uu', b'begin 666 <data>\n+:&5L;&\\@=V]R;&0 \n \nend\n')] for encoding, data in codecs:
for encoding, data in codecs: self.checkequal(data, 'hello world', 'encode', encoding)
self.checkequal(data, 'hello world', 'encode', encoding) self.checkequal('hello world', data, 'decode', encoding)
self.checkequal('hello world', data, 'decode', encoding) # zlib is optional, so we make the test optional too...
# zlib is optional, so we make the test optional too... try:
try: import zlib
import zlib except ImportError:
except ImportError: pass
pass else:
else: data = b'x\x9c\xcbH\xcd\xc9\xc9W(\xcf/\xcaI\x01\x00\x1a\x0b\x04]'
data = b'x\x9c\xcbH\xcd\xc9\xc9W(\xcf/\xcaI\x01\x00\x1a\x0b\x04]' self.checkequal(data, 'hello world', 'encode', 'zlib')
self.checkequal(data, 'hello world', 'encode', 'zlib') self.checkequal('hello world', data, 'decode', 'zlib')
self.checkequal('hello world', data, 'decode', 'zlib')
self.checkraises(TypeError, 'xyz', 'decode', 42) self.checkraises(TypeError, 'xyz', 'decode', 42)
self.checkraises(TypeError, 'xyz', 'encode', 42) self.checkraises(TypeError, 'xyz', 'encode', 42)
class MixinStrUnicodeTest: class MixinStrUnicodeTest:
......
...@@ -121,9 +121,7 @@ class BinASCIITest(unittest.TestCase): ...@@ -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])
self.assertRaises(binascii.Error, binascii.a2b_hex, t[:-1] + b'q') self.assertRaises(binascii.Error, binascii.a2b_hex, t[:-1] + b'q')
# Verify the treatment of Unicode strings self.assertEqual(binascii.hexlify('a'), b'61')
if test_support.have_unicode:
self.assertEqual(binascii.hexlify('a'), b'61')
def test_qp(self): def test_qp(self):
# A test for SF bug 534347 (segfaults without the proper fix) # A test for SF bug 534347 (segfaults without the proper fix)
......
...@@ -146,42 +146,35 @@ elif os.name == 'riscos': ...@@ -146,42 +146,35 @@ elif os.name == 'riscos':
TESTFN = 'testfile' TESTFN = 'testfile'
else: else:
TESTFN = '@test' TESTFN = '@test'
# Unicode name only used if TEST_FN_ENCODING exists for the platform.
if have_unicode: # Assuming sys.getfilesystemencoding()!=sys.getdefaultencoding()
# Assuming sys.getfilesystemencoding()!=sys.getdefaultencoding() # TESTFN_UNICODE is a filename that can be encoded using the
# TESTFN_UNICODE is a filename that can be encoded using the # file system encoding, but *not* with the default (ascii) encoding
# file system encoding, but *not* with the default (ascii) encoding TESTFN_UNICODE = "@test-\xe0\xf2"
if isinstance('', str): TESTFN_ENCODING = sys.getfilesystemencoding()
# python -U # TESTFN_UNICODE_UNENCODEABLE is a filename that should *not* be
# XXX perhaps unicode() should accept Unicode strings? # able to be encoded by *either* the default or filesystem encoding.
TESTFN_UNICODE = "@test-\xe0\xf2" # This test really only makes sense on Windows NT platforms
else: # which have special Unicode support in posixmodule.
# 2 latin characters. if (not hasattr(sys, "getwindowsversion") or
TESTFN_UNICODE = str("@test-\xe0\xf2", "latin-1") sys.getwindowsversion()[3] < 2): # 0=win32s or 1=9x/ME
TESTFN_ENCODING = sys.getfilesystemencoding() TESTFN_UNICODE_UNENCODEABLE = None
# TESTFN_UNICODE_UNENCODEABLE is a filename that should *not* be else:
# able to be encoded by *either* the default or filesystem encoding. # Japanese characters (I think - from bug 846133)
# This test really only makes sense on Windows NT platforms TESTFN_UNICODE_UNENCODEABLE = "@test-\u5171\u6709\u3055\u308c\u308b"
# which have special Unicode support in posixmodule. try:
if (not hasattr(sys, "getwindowsversion") or # XXX - Note - should be using TESTFN_ENCODING here - but for
sys.getwindowsversion()[3] < 2): # 0=win32s or 1=9x/ME # Windows, "mbcs" currently always operates as if in
TESTFN_UNICODE_UNENCODEABLE = None # 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: else:
# Japanese characters (I think - from bug 846133) print('WARNING: The filename %r CAN be encoded by the filesystem. ' \
TESTFN_UNICODE_UNENCODEABLE = eval('u"@test-\u5171\u6709\u3055\u308c\u308b"') 'Unicode filename tests may not be effective' \
try: % TESTFN_UNICODE_UNENCODEABLE)
# 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)
# Make sure we can write to TESTFN, try in /tmp if we can't # Make sure we can write to TESTFN, try in /tmp if we can't
fp = None fp = None
......
...@@ -336,19 +336,6 @@ What a mess! ...@@ -336,19 +336,6 @@ What a mess!
"with ", "much white", "space."], "with ", "much white", "space."],
drop_whitespace=False) 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): def test_split(self):
# Ensure that the standard _split() method works as advertised # Ensure that the standard _split() method works as advertised
# in the comments # in the comments
......
# Python test set -- part 6, built-in types # 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 unittest
import sys import sys
...@@ -199,19 +199,6 @@ class TypesTests(unittest.TestCase): ...@@ -199,19 +199,6 @@ class TypesTests(unittest.TestCase):
self.assertEqual(a[100:-100:-1], a[::-1]) self.assertEqual(a[100:-100:-1], a[::-1])
self.assertEqual(a[-100:100:2], '02468') 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): def test_type_function(self):
self.assertRaises(TypeError, type, 1, 2) self.assertRaises(TypeError, type, 1, 2)
self.assertRaises(TypeError, type, 1, 2, 3, 4) self.assertRaises(TypeError, type, 1, 2, 3, 4)
......
...@@ -4,13 +4,6 @@ import unittest ...@@ -4,13 +4,6 @@ import unittest
import xmlrpclib import xmlrpclib
from test import test_support from test import test_support
try:
str
except NameError:
have_unicode = False
else:
have_unicode = True
alist = [{'astring': 'foo@bar.baz.spam', alist = [{'astring': 'foo@bar.baz.spam',
'afloat': 7283.43, 'afloat': 7283.43,
'anint': 2**20, 'anint': 2**20,
...@@ -147,15 +140,11 @@ class XMLRPCTestCase(unittest.TestCase): ...@@ -147,15 +140,11 @@ class XMLRPCTestCase(unittest.TestCase):
del sys.setdefaultencoding del sys.setdefaultencoding
items = list(d.items()) items = list(d.items())
if have_unicode: self.assertEquals(s, "abc \x95")
self.assertEquals(s, "abc \x95") self.assert_(isinstance(s, str))
self.assert_(isinstance(s, str)) self.assertEquals(items, [("def \x96", "ghi \x97")])
self.assertEquals(items, [("def \x96", "ghi \x97")]) self.assert_(isinstance(items[0][0], str))
self.assert_(isinstance(items[0][0], str)) self.assert_(isinstance(items[0][1], str))
self.assert_(isinstance(items[0][1], str))
else:
self.assertEquals(s, "abc \xc2\x95")
self.assertEquals(items, [("def \xc2\x96", "ghi \xc2\x97")])
def test_main(): def test_main():
test_support.run_unittest(XMLRPCTestCase) test_support.run_unittest(XMLRPCTestCase)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment