Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 12 additions & 20 deletions Lib/test/multibytecodec_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,13 @@ def test_errorhandle(self):
if expected:
result = func(source, scheme)[0]
if func is self.decode:
self.assertTrue(type(result) is str, type(result))
self.assertEqual(result, expected,
'%a.decode(%r, %r)=%a != %a'
% (source, self.encoding, scheme, result,
expected))
msg = '%a.decode(%r, %r)' % (source, self.encoding, scheme)
self.assertIs(type(result), str, msg)
self.assertEqual(result, expected, msg)
else:
self.assertTrue(type(result) is bytes, type(result))
self.assertEqual(result, expected,
'%a.encode(%r, %r)=%a != %a'
% (source, self.encoding, scheme, result,
expected))
msg = '%a.encode(%r, %r)' % (source, self.encoding, scheme)
self.assertIs(type(result), bytes, msg)
self.assertEqual(result, expected, msg)
else:
self.assertRaises(UnicodeError, func, source, scheme)

Expand Down Expand Up @@ -360,18 +356,14 @@ def test_errorhandle(self):
if expected:
if isinstance(source, bytes):
result = func(self.encoding, scheme)
self.assertTrue(type(result) is str, type(result))
self.assertEqual(result, expected,
'%a.decode(%r, %r)=%a != %a'
% (source, self.encoding, scheme, result,
expected))
msg = '%a.decode(%r, %r)' % (source, self.encoding, scheme)
self.assertIs(type(result), str, msg)
self.assertEqual(result, expected, msg)
else:
result = func(self.encoding, scheme)
self.assertTrue(type(result) is bytes, type(result))
self.assertEqual(result, expected,
'%a.encode(%r, %r)=%a != %a'
% (source, self.encoding, scheme, result,
expected))
msg = '%a.encode(%r, %r)' % (source, self.encoding, scheme)
self.assertIs(type(result), bytes, msg)
self.assertEqual(result, expected, msg)
else:
self.assertRaises(UnicodeError, func, self.encoding, scheme)

Expand Down
8 changes: 4 additions & 4 deletions Lib/test/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def check_state_handling_decode(self, encoding, u, s):
# reset decoder to the default state without anything buffered
d.setstate((state[0][:0], 0))
# Feeding the previous input may not produce any output
self.assertTrue(not d.decode(state[0]))
self.assertFalse(d.decode(state[0]))
# The decoder must return to the same state
self.assertEqual(state, d.getstate())
# Create a new decoder and set it to the state
Expand Down Expand Up @@ -410,7 +410,7 @@ def test_only_one_bom(self):
f.write("spam")
d = s.getvalue()
# check whether there is exactly one BOM in it
self.assertTrue(d == self.spamle or d == self.spambe)
self.assertIn(d, (self.spamle, self.spambe))
# try to read it back
s = io.BytesIO(d)
f = reader(s)
Expand Down Expand Up @@ -594,7 +594,7 @@ def test_only_one_bom(self):
f.write("spam")
d = s.getvalue()
# check whether there is exactly one BOM in it
self.assertTrue(d == self.spamle or d == self.spambe)
self.assertIn(d, (self.spamle, self.spambe))
# try to read it back
s = io.BytesIO(d)
f = reader(s)
Expand Down Expand Up @@ -1977,7 +1977,7 @@ def test_basics(self):
for c in s:
writer.write(c)
chunk = q.read()
self.assertTrue(type(chunk) is bytes, type(chunk))
self.assertIs(type(chunk), bytes)
encodedresult += chunk
q = Queue(b"")
reader = codecs.getreader(encoding)(q)
Expand Down
35 changes: 24 additions & 11 deletions Lib/test/test_normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,26 @@ def test_main(self):
continue

# Perform tests
self.assertTrue(c2 == NFC(c1) == NFC(c2) == NFC(c3), line)
self.assertTrue(c4 == NFC(c4) == NFC(c5), line)
self.assertTrue(c3 == NFD(c1) == NFD(c2) == NFD(c3), line)
self.assertTrue(c5 == NFD(c4) == NFD(c5), line)
self.assertTrue(c4 == NFKC(c1) == NFKC(c2) == \
NFKC(c3) == NFKC(c4) == NFKC(c5),
line)
self.assertTrue(c5 == NFKD(c1) == NFKD(c2) == \
NFKD(c3) == NFKD(c4) == NFKD(c5),
line)
self.assertEqual(NFC(c1), c2, line)
self.assertEqual(NFC(c2), c2, line)
self.assertEqual(NFC(c3), c2, line)
self.assertEqual(NFC(c4), c4, line)
self.assertEqual(NFC(c5), c4, line)
self.assertEqual(NFD(c1), c3, line)
self.assertEqual(NFD(c2), c3, line)
self.assertEqual(NFD(c3), c3, line)
self.assertEqual(NFD(c4), c5, line)
self.assertEqual(NFD(c5), c5, line)
self.assertEqual(NFKC(c1), c4, line)
self.assertEqual(NFKC(c2), c4, line)
self.assertEqual(NFKC(c3), c4, line)
self.assertEqual(NFKC(c4), c4, line)
self.assertEqual(NFKC(c5), c4, line)
self.assertEqual(NFKD(c1), c5, line)
self.assertEqual(NFKD(c2), c5, line)
self.assertEqual(NFKD(c3), c5, line)
self.assertEqual(NFKD(c4), c5, line)
self.assertEqual(NFKD(c5), c5, line)

# Record part 1 data
if part == "@Part1":
Expand All @@ -89,7 +99,10 @@ def test_main(self):
X = chr(c)
if X in part1_data:
continue
self.assertTrue(X == NFC(X) == NFD(X) == NFKC(X) == NFKD(X), c)
self.assertEqual(NFC(X), X, c)
self.assertEqual(NFD(X), X, c)
self.assertEqual(NFKC(X), X, c)
self.assertEqual(NFKD(X), X, c)

def test_bug_834676(self):
# Check for bug 834676
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def checkequalnofix(self, result, object, methodname, *args):
method = getattr(object, methodname)
realresult = method(*args)
self.assertEqual(realresult, result)
self.assertTrue(type(realresult) is type(result))
self.assertIs(type(realresult), type(result))

# if the original is returned make sure that
# this doesn't happen with subclasses
Expand All @@ -70,7 +70,7 @@ def __repr__(self):
method = getattr(object, methodname)
realresult = method(*args)
self.assertEqual(realresult, result)
self.assertTrue(object is not realresult)
self.assertIsNot(object, realresult)

def test_literals(self):
self.assertEqual('\xff', '\u00ff')
Expand Down
12 changes: 6 additions & 6 deletions Lib/test/test_unicodedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def test_decimal_numeric_consistent(self):
if dec != -1:
self.assertEqual(dec, self.db.numeric(c))
count += 1
self.assertTrue(count >= 10) # should have tested at least the ASCII digits
self.assertGreaterEqual(count, 10) # should have tested at least the ASCII digits

def test_digit_numeric_consistent(self):
# Test that digit and numeric are consistent,
Expand All @@ -268,7 +268,7 @@ def test_digit_numeric_consistent(self):
if dec != -1:
self.assertEqual(dec, self.db.numeric(c))
count += 1
self.assertTrue(count >= 10) # should have tested at least the ASCII digits
self.assertGreaterEqual(count, 10) # should have tested at least the ASCII digits

def test_bug_1704793(self):
self.assertEqual(self.db.lookup("GOTHIC LETTER FAIHU"), '\U00010346')
Expand All @@ -277,12 +277,12 @@ def test_ucd_510(self):
import unicodedata
# In UCD 5.1.0, a mirrored property changed wrt. UCD 3.2.0
self.assertTrue(unicodedata.mirrored("\u0f3a"))
self.assertTrue(not unicodedata.ucd_3_2_0.mirrored("\u0f3a"))
self.assertFalse(unicodedata.ucd_3_2_0.mirrored("\u0f3a"))
# Also, we now have two ways of representing
# the upper-case mapping: as delta, or as absolute value
self.assertTrue("a".upper()=='A')
self.assertTrue("\u1d79".upper()=='\ua77d')
self.assertTrue(".".upper()=='.')
self.assertEqual("a".upper(), 'A')
self.assertEqual("\u1d79".upper(), '\ua77d')
self.assertEqual(".".upper(), '.')

def test_bug_5828(self):
self.assertEqual("\u1d79".lower(), "\u1d79")
Expand Down