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

Skip to content

Commit 9b77553

Browse files
committed
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.
1 parent 0157ebe commit 9b77553

7 files changed

Lines changed: 62 additions & 112 deletions

File tree

Lib/test/pickletester.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
import pickletools
88
import copy_reg
99

10-
from test.test_support import TestFailed, have_unicode, TESTFN, \
11-
run_with_locale
10+
from test.test_support import TestFailed, TESTFN, run_with_locale
1211

1312
# Tests that try a number of pickle protocols should have a
1413
# for proto in protocols:
@@ -482,15 +481,13 @@ def test_insecure_strings(self):
482481
buf = b"S" + bytes(s) + b"\012p0\012."
483482
self.assertRaises(ValueError, self.loads, buf)
484483

485-
if have_unicode:
486-
def test_unicode(self):
487-
endcases = [str(''), str('<\\u>'), str('<\\\u1234>'),
488-
str('<\n>'), str('<\\>')]
489-
for proto in protocols:
490-
for u in endcases:
491-
p = self.dumps(u, proto)
492-
u2 = self.loads(p)
493-
self.assertEqual(u2, u)
484+
def test_unicode(self):
485+
endcases = ['', '<\\u>', '<\\\u1234>', '<\n>', '<\\>']
486+
for proto in protocols:
487+
for u in endcases:
488+
p = self.dumps(u, proto)
489+
u2 = self.loads(p)
490+
self.assertEqual(u2, u)
494491

495492
def test_ints(self):
496493
import sys

Lib/test/string_tests.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,27 +1100,26 @@ class MixinStrUserStringTest:
11001100
# Additional tests that only work with
11011101
# 8bit compatible object, i.e. str and UserString
11021102

1103-
if test_support.have_unicode:
1104-
def test_encoding_decoding(self):
1105-
codecs = [('rot13', b'uryyb jbeyq'),
1106-
('base64', b'aGVsbG8gd29ybGQ=\n'),
1107-
('hex', b'68656c6c6f20776f726c64'),
1108-
('uu', b'begin 666 <data>\n+:&5L;&\\@=V]R;&0 \n \nend\n')]
1109-
for encoding, data in codecs:
1110-
self.checkequal(data, 'hello world', 'encode', encoding)
1111-
self.checkequal('hello world', data, 'decode', encoding)
1112-
# zlib is optional, so we make the test optional too...
1113-
try:
1114-
import zlib
1115-
except ImportError:
1116-
pass
1117-
else:
1118-
data = b'x\x9c\xcbH\xcd\xc9\xc9W(\xcf/\xcaI\x01\x00\x1a\x0b\x04]'
1119-
self.checkequal(data, 'hello world', 'encode', 'zlib')
1120-
self.checkequal('hello world', data, 'decode', 'zlib')
1103+
def test_encoding_decoding(self):
1104+
codecs = [('rot13', b'uryyb jbeyq'),
1105+
('base64', b'aGVsbG8gd29ybGQ=\n'),
1106+
('hex', b'68656c6c6f20776f726c64'),
1107+
('uu', b'begin 666 <data>\n+:&5L;&\\@=V]R;&0 \n \nend\n')]
1108+
for encoding, data in codecs:
1109+
self.checkequal(data, 'hello world', 'encode', encoding)
1110+
self.checkequal('hello world', data, 'decode', encoding)
1111+
# zlib is optional, so we make the test optional too...
1112+
try:
1113+
import zlib
1114+
except ImportError:
1115+
pass
1116+
else:
1117+
data = b'x\x9c\xcbH\xcd\xc9\xc9W(\xcf/\xcaI\x01\x00\x1a\x0b\x04]'
1118+
self.checkequal(data, 'hello world', 'encode', 'zlib')
1119+
self.checkequal('hello world', data, 'decode', 'zlib')
11211120

1122-
self.checkraises(TypeError, 'xyz', 'decode', 42)
1123-
self.checkraises(TypeError, 'xyz', 'encode', 42)
1121+
self.checkraises(TypeError, 'xyz', 'decode', 42)
1122+
self.checkraises(TypeError, 'xyz', 'encode', 42)
11241123

11251124

11261125
class MixinStrUnicodeTest:

Lib/test/test_binascii.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ def test_hex(self):
121121
self.assertRaises(binascii.Error, binascii.a2b_hex, t[:-1])
122122
self.assertRaises(binascii.Error, binascii.a2b_hex, t[:-1] + b'q')
123123

124-
# Verify the treatment of Unicode strings
125-
if test_support.have_unicode:
126-
self.assertEqual(binascii.hexlify('a'), b'61')
124+
self.assertEqual(binascii.hexlify('a'), b'61')
127125

128126
def test_qp(self):
129127
# A test for SF bug 534347 (segfaults without the proper fix)

Lib/test/test_support.py

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -146,42 +146,35 @@ def fcmp(x, y): # fuzzy comparison function
146146
TESTFN = 'testfile'
147147
else:
148148
TESTFN = '@test'
149-
# Unicode name only used if TEST_FN_ENCODING exists for the platform.
150-
if have_unicode:
151-
# Assuming sys.getfilesystemencoding()!=sys.getdefaultencoding()
152-
# TESTFN_UNICODE is a filename that can be encoded using the
153-
# file system encoding, but *not* with the default (ascii) encoding
154-
if isinstance('', str):
155-
# python -U
156-
# XXX perhaps unicode() should accept Unicode strings?
157-
TESTFN_UNICODE = "@test-\xe0\xf2"
158-
else:
159-
# 2 latin characters.
160-
TESTFN_UNICODE = str("@test-\xe0\xf2", "latin-1")
161-
TESTFN_ENCODING = sys.getfilesystemencoding()
162-
# TESTFN_UNICODE_UNENCODEABLE is a filename that should *not* be
163-
# able to be encoded by *either* the default or filesystem encoding.
164-
# This test really only makes sense on Windows NT platforms
165-
# which have special Unicode support in posixmodule.
166-
if (not hasattr(sys, "getwindowsversion") or
167-
sys.getwindowsversion()[3] < 2): # 0=win32s or 1=9x/ME
168-
TESTFN_UNICODE_UNENCODEABLE = None
149+
150+
# Assuming sys.getfilesystemencoding()!=sys.getdefaultencoding()
151+
# TESTFN_UNICODE is a filename that can be encoded using the
152+
# file system encoding, but *not* with the default (ascii) encoding
153+
TESTFN_UNICODE = "@test-\xe0\xf2"
154+
TESTFN_ENCODING = sys.getfilesystemencoding()
155+
# TESTFN_UNICODE_UNENCODEABLE is a filename that should *not* be
156+
# able to be encoded by *either* the default or filesystem encoding.
157+
# This test really only makes sense on Windows NT platforms
158+
# which have special Unicode support in posixmodule.
159+
if (not hasattr(sys, "getwindowsversion") or
160+
sys.getwindowsversion()[3] < 2): # 0=win32s or 1=9x/ME
161+
TESTFN_UNICODE_UNENCODEABLE = None
162+
else:
163+
# Japanese characters (I think - from bug 846133)
164+
TESTFN_UNICODE_UNENCODEABLE = "@test-\u5171\u6709\u3055\u308c\u308b"
165+
try:
166+
# XXX - Note - should be using TESTFN_ENCODING here - but for
167+
# Windows, "mbcs" currently always operates as if in
168+
# errors=ignore' mode - hence we get '?' characters rather than
169+
# the exception. 'Latin1' operates as we expect - ie, fails.
170+
# See [ 850997 ] mbcs encoding ignores errors
171+
TESTFN_UNICODE_UNENCODEABLE.encode("Latin1")
172+
except UnicodeEncodeError:
173+
pass
169174
else:
170-
# Japanese characters (I think - from bug 846133)
171-
TESTFN_UNICODE_UNENCODEABLE = eval('u"@test-\u5171\u6709\u3055\u308c\u308b"')
172-
try:
173-
# XXX - Note - should be using TESTFN_ENCODING here - but for
174-
# Windows, "mbcs" currently always operates as if in
175-
# errors=ignore' mode - hence we get '?' characters rather than
176-
# the exception. 'Latin1' operates as we expect - ie, fails.
177-
# See [ 850997 ] mbcs encoding ignores errors
178-
TESTFN_UNICODE_UNENCODEABLE.encode("Latin1")
179-
except UnicodeEncodeError:
180-
pass
181-
else:
182-
print('WARNING: The filename %r CAN be encoded by the filesystem. ' \
183-
'Unicode filename tests may not be effective' \
184-
% TESTFN_UNICODE_UNENCODEABLE)
175+
print('WARNING: The filename %r CAN be encoded by the filesystem. ' \
176+
'Unicode filename tests may not be effective' \
177+
% TESTFN_UNICODE_UNENCODEABLE)
185178

186179
# Make sure we can write to TESTFN, try in /tmp if we can't
187180
fp = None

Lib/test/test_textwrap.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -336,19 +336,6 @@ def test_no_drop_whitespace(self):
336336
"with ", "much white", "space."],
337337
drop_whitespace=False)
338338

339-
if test_support.have_unicode:
340-
def test_unicode(self):
341-
# *Very* simple test of wrapping Unicode strings. I'm sure
342-
# there's more to it than this, but let's at least make
343-
# sure textwrap doesn't crash on Unicode input!
344-
text = "Hello there, how are you today?"
345-
self.check_wrap(text, 50, ["Hello there, how are you today?"])
346-
self.check_wrap(text, 20, ["Hello there, how are", "you today?"])
347-
olines = self.wrapper.wrap(text)
348-
assert isinstance(olines, list) and isinstance(olines[0], str)
349-
otext = self.wrapper.fill(text)
350-
assert isinstance(otext, str)
351-
352339
def test_split(self):
353340
# Ensure that the standard _split() method works as advertised
354341
# in the comments

Lib/test/test_types.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Python test set -- part 6, built-in types
22

3-
from test.test_support import run_unittest, have_unicode
3+
from test.test_support import run_unittest
44
import unittest
55
import sys
66

@@ -199,19 +199,6 @@ def test_strings(self):
199199
self.assertEqual(a[100:-100:-1], a[::-1])
200200
self.assertEqual(a[-100:100:2], '02468')
201201

202-
if have_unicode:
203-
a = str(b'0123456789', 'ascii')
204-
self.assertEqual(a[::], a)
205-
self.assertEqual(a[::2], str(b'02468', 'ascii'))
206-
self.assertEqual(a[1::2], str(b'13579', 'ascii'))
207-
self.assertEqual(a[::-1], str(b'9876543210', 'ascii'))
208-
self.assertEqual(a[::-2], str(b'97531', 'ascii'))
209-
self.assertEqual(a[3::-2], str(b'31', 'ascii'))
210-
self.assertEqual(a[-100:100:], a)
211-
self.assertEqual(a[100:-100:-1], a[::-1])
212-
self.assertEqual(a[-100:100:2], str(b'02468', 'ascii'))
213-
214-
215202
def test_type_function(self):
216203
self.assertRaises(TypeError, type, 1, 2)
217204
self.assertRaises(TypeError, type, 1, 2, 3, 4)

Lib/test/test_xmlrpc.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@
44
import xmlrpclib
55
from test import test_support
66

7-
try:
8-
str
9-
except NameError:
10-
have_unicode = False
11-
else:
12-
have_unicode = True
13-
147
alist = [{'astring': '[email protected]',
158
'afloat': 7283.43,
169
'anint': 2**20,
@@ -147,15 +140,11 @@ def test_default_encoding_issues(self):
147140
del sys.setdefaultencoding
148141

149142
items = list(d.items())
150-
if have_unicode:
151-
self.assertEquals(s, "abc \x95")
152-
self.assert_(isinstance(s, str))
153-
self.assertEquals(items, [("def \x96", "ghi \x97")])
154-
self.assert_(isinstance(items[0][0], str))
155-
self.assert_(isinstance(items[0][1], str))
156-
else:
157-
self.assertEquals(s, "abc \xc2\x95")
158-
self.assertEquals(items, [("def \xc2\x96", "ghi \xc2\x97")])
143+
self.assertEquals(s, "abc \x95")
144+
self.assert_(isinstance(s, str))
145+
self.assertEquals(items, [("def \x96", "ghi \x97")])
146+
self.assert_(isinstance(items[0][0], str))
147+
self.assert_(isinstance(items[0][1], str))
159148

160149
def test_main():
161150
test_support.run_unittest(XMLRPCTestCase)

0 commit comments

Comments
 (0)