Skip to content

Commit 604e74c

Browse files
serhiy-storchakavstinner
authored andcommitted
bpo-20552: Use specific asserts in bytes tests (#790)
1 parent b8a7daf commit 604e74c

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

Lib/test/test_bytes.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ def test_iconcat(self):
11701170
b += b"def"
11711171
self.assertEqual(b, b"abcdef")
11721172
self.assertEqual(b, b1)
1173-
self.assertTrue(b is b1)
1173+
self.assertIs(b, b1)
11741174
b += b"xyz"
11751175
self.assertEqual(b, b"abcdefxyz")
11761176
try:
@@ -1186,20 +1186,20 @@ def test_irepeat(self):
11861186
b *= 3
11871187
self.assertEqual(b, b"abcabcabc")
11881188
self.assertEqual(b, b1)
1189-
self.assertTrue(b is b1)
1189+
self.assertIs(b, b1)
11901190

11911191
def test_irepeat_1char(self):
11921192
b = bytearray(b"x")
11931193
b1 = b
11941194
b *= 100
11951195
self.assertEqual(b, b"x"*100)
11961196
self.assertEqual(b, b1)
1197-
self.assertTrue(b is b1)
1197+
self.assertIs(b, b1)
11981198

11991199
def test_alloc(self):
12001200
b = bytearray()
12011201
alloc = b.__alloc__()
1202-
self.assertTrue(alloc >= 0)
1202+
self.assertGreaterEqual(alloc, 0)
12031203
seq = [alloc]
12041204
for i in range(100):
12051205
b += b"x"
@@ -1319,17 +1319,17 @@ def test_copied(self):
13191319
# Issue 4348. Make sure that operations that don't mutate the array
13201320
# copy the bytes.
13211321
b = bytearray(b'abc')
1322-
self.assertFalse(b is b.replace(b'abc', b'cde', 0))
1322+
self.assertIsNot(b, b.replace(b'abc', b'cde', 0))
13231323

13241324
t = bytearray([i for i in range(256)])
13251325
x = bytearray(b'')
1326-
self.assertFalse(x is x.translate(t))
1326+
self.assertIsNot(x, x.translate(t))
13271327

13281328
def test_partition_bytearray_doesnt_share_nullstring(self):
13291329
a, b, c = bytearray(b"x").partition(b"y")
13301330
self.assertEqual(b, b"")
13311331
self.assertEqual(c, b"")
1332-
self.assertTrue(b is not c)
1332+
self.assertIsNot(b, c)
13331333
b += b"!"
13341334
self.assertEqual(c, b"")
13351335
a, b, c = bytearray(b"x").partition(b"y")
@@ -1339,7 +1339,7 @@ def test_partition_bytearray_doesnt_share_nullstring(self):
13391339
b, c, a = bytearray(b"x").rpartition(b"y")
13401340
self.assertEqual(b, b"")
13411341
self.assertEqual(c, b"")
1342-
self.assertTrue(b is not c)
1342+
self.assertIsNot(b, c)
13431343
b += b"!"
13441344
self.assertEqual(c, b"")
13451345
c, b, a = bytearray(b"x").rpartition(b"y")
@@ -1529,7 +1529,7 @@ def test_rsplit_bytearray(self):
15291529
def test_return_self(self):
15301530
# bytearray.replace must always return a new bytearray
15311531
b = bytearray()
1532-
self.assertFalse(b.replace(b'', b'') is b)
1532+
self.assertIsNot(b.replace(b'', b''), b)
15331533

15341534
@unittest.skipUnless(sys.flags.bytes_warning,
15351535
"BytesWarning is needed for this test: use -bb option")
@@ -1588,14 +1588,14 @@ def test_returns_new_copy(self):
15881588
method = getattr(val, methname)
15891589
newval = method(3)
15901590
self.assertEqual(val, newval)
1591-
self.assertTrue(val is not newval,
1591+
self.assertIsNot(val, newval,
15921592
methname+' returned self on a mutable object')
15931593
for expr in ('val.split()[0]', 'val.rsplit()[0]',
15941594
'val.partition(b".")[0]', 'val.rpartition(b".")[2]',
15951595
'val.splitlines()[0]', 'val.replace(b"", b"")'):
15961596
newval = eval(expr)
15971597
self.assertEqual(val, newval)
1598-
self.assertTrue(val is not newval,
1598+
self.assertIsNot(val, newval,
15991599
expr+' returned val on a mutable object')
16001600
sep = self.marshal(b'')
16011601
newval = sep.join([val])
@@ -1634,7 +1634,7 @@ def test_basic(self):
16341634
self.assertTrue(_a <= _b)
16351635
self.assertTrue(_b >= _a)
16361636
self.assertTrue(_b > _a)
1637-
self.assertTrue(_a is not a)
1637+
self.assertIsNot(_a, a)
16381638

16391639
# test concat of subclass instances
16401640
self.assertEqual(a + b, _a + _b)
@@ -1650,12 +1650,12 @@ def test_join(self):
16501650
# Make sure that it is of the appropriate type.
16511651
s1 = self.type2test(b"abcd")
16521652
s2 = self.basetype().join([s1])
1653-
self.assertTrue(s1 is not s2)
1654-
self.assertTrue(type(s2) is self.basetype, type(s2))
1653+
self.assertIsNot(s1, s2)
1654+
self.assertIs(type(s2), self.basetype, type(s2))
16551655

16561656
# Test reverse, calling join on subclass
16571657
s3 = s1.join([b"abcd"])
1658-
self.assertTrue(type(s3) is self.basetype)
1658+
self.assertIs(type(s3), self.basetype)
16591659

16601660
def test_pickle(self):
16611661
a = self.type2test(b"abcd")

0 commit comments

Comments
 (0)