Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(6)

Unified Diff: Lib/test/test_bytes.py

Issue 20552: Use specific asserts in bytes tests
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/test/test_bytes.py Fri Feb 07 17:53:13 2014 +0100
+++ b/Lib/test/test_bytes.py Fri Feb 07 22:21:03 2014 +0200
@@ -957,7 +957,7 @@
b += b"def"
self.assertEqual(b, b"abcdef")
self.assertEqual(b, b1)
- self.assertTrue(b is b1)
+ self.assertIs(b, b1)
b += b"xyz"
self.assertEqual(b, b"abcdefxyz")
try:
@@ -973,7 +973,7 @@
b *= 3
self.assertEqual(b, b"abcabcabc")
self.assertEqual(b, b1)
- self.assertTrue(b is b1)
+ self.assertIs(b, b1)
def test_irepeat_1char(self):
b = bytearray(b"x")
@@ -981,17 +981,17 @@
b *= 100
self.assertEqual(b, b"x"*100)
self.assertEqual(b, b1)
- self.assertTrue(b is b1)
+ self.assertIs(b, b1)
def test_alloc(self):
b = bytearray()
alloc = b.__alloc__()
- self.assertTrue(alloc >= 0)
+ self.assertGreaterEqual(alloc, 0)
seq = [alloc]
for i in range(100):
b += b"x"
alloc = b.__alloc__()
- self.assertTrue(alloc >= len(b))
+ self.assertGreaterEqual(alloc, len(b))
if alloc not in seq:
seq.append(alloc)
@@ -1082,17 +1082,17 @@
# Issue 4348. Make sure that operations that don't mutate the array
# copy the bytes.
b = bytearray(b'abc')
- self.assertFalse(b is b.replace(b'abc', b'cde', 0))
+ self.assertIsNot(b, b.replace(b'abc', b'cde', 0))
t = bytearray([i for i in range(256)])
x = bytearray(b'')
- self.assertFalse(x is x.translate(t))
+ self.assertIsNot(x, x.translate(t))
def test_partition_bytearray_doesnt_share_nullstring(self):
a, b, c = bytearray(b"x").partition(b"y")
self.assertEqual(b, b"")
self.assertEqual(c, b"")
- self.assertTrue(b is not c)
+ self.assertIsNot(b, c)
b += b"!"
self.assertEqual(c, b"")
a, b, c = bytearray(b"x").partition(b"y")
@@ -1102,7 +1102,7 @@
b, c, a = bytearray(b"x").rpartition(b"y")
self.assertEqual(b, b"")
self.assertEqual(c, b"")
- self.assertTrue(b is not c)
+ self.assertIsNot(b, c)
b += b"!"
self.assertEqual(c, b"")
c, b, a = bytearray(b"x").rpartition(b"y")
@@ -1249,7 +1249,7 @@
def test_return_self(self):
# bytearray.replace must always return a new bytearray
b = bytearray()
- self.assertFalse(b.replace(b'', b'') is b)
+ self.assertIsNot(b.replace(b'', b''), b)
def test_compare(self):
if sys.flags.bytes_warning:
@@ -1294,14 +1294,14 @@
method = getattr(val, methname)
newval = method(3)
self.assertEqual(val, newval)
- self.assertTrue(val is not newval,
+ self.assertIsNot(val, newval,
methname+' returned self on a mutable object')
for expr in ('val.split()[0]', 'val.rsplit()[0]',
'val.partition(b".")[0]', 'val.rpartition(b".")[2]',
'val.splitlines()[0]', 'val.replace(b"", b"")'):
newval = eval(expr)
self.assertEqual(val, newval)
- self.assertTrue(val is not newval,
+ self.assertIsNot(val, newval,
expr+' returned val on a mutable object')
sep = self.marshal(b'')
newval = sep.join([val])
@@ -1353,7 +1353,7 @@
self.assertTrue(_a <= _b)
self.assertTrue(_b >= _a)
self.assertTrue(_b > _a)
- self.assertTrue(_a is not a)
+ self.assertIsNot(_a, a)
# test concat of subclass instances
self.assertEqual(a + b, _a + _b)
@@ -1369,12 +1369,12 @@
# Make sure that it is of the appropriate type.
s1 = self.subclass2test(b"abcd")
s2 = self.type2test().join([s1])
- self.assertTrue(s1 is not s2)
- self.assertTrue(type(s2) is self.type2test, type(s2))
+ self.assertIsNot(s1, s2)
+ self.assertIs(type(s2), self.type2test)
# Test reverse, calling join on subclass
s3 = s1.join([b"abcd"])
- self.assertTrue(type(s3) is self.type2test)
+ self.assertIs(type(s3), self.type2test)
def test_pickle(self):
a = self.subclass2test(b"abcd")
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+