◐ Shell
reader mode source ↗
Skip to content
Merged
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
30 changes: 15 additions & 15 deletions Lib/test/test_bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ def test_iconcat(self):
b += b"def"
self.assertEqual(b, b"abcdef")
self.assertEqual(b, b1)
self.assertTrue(b is b1)
b += b"xyz"
self.assertEqual(b, b"abcdefxyz")
try:
Expand All @@ -1186,20 +1186,20 @@ def test_irepeat(self):
b *= 3
self.assertEqual(b, b"abcabcabc")
self.assertEqual(b, b1)
self.assertTrue(b is b1)

def test_irepeat_1char(self):
b = bytearray(b"x")
b1 = b
b *= 100
self.assertEqual(b, b"x"*100)
self.assertEqual(b, b1)
self.assertTrue(b is b1)

def test_alloc(self):
b = bytearray()
alloc = b.__alloc__()
self.assertTrue(alloc >= 0)
seq = [alloc]
for i in range(100):
b += b"x"
Expand Down Expand Up @@ -1319,17 +1319,17 @@ def test_copied(self):
# 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))

t = bytearray([i for i in range(256)])
x = bytearray(b'')
self.assertFalse(x is 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)
b += b"!"
self.assertEqual(c, b"")
a, b, c = bytearray(b"x").partition(b"y")
Expand All @@ -1339,7 +1339,7 @@ def test_partition_bytearray_doesnt_share_nullstring(self):
b, c, a = bytearray(b"x").rpartition(b"y")
self.assertEqual(b, b"")
self.assertEqual(c, b"")
self.assertTrue(b is not c)
b += b"!"
self.assertEqual(c, b"")
c, b, a = bytearray(b"x").rpartition(b"y")
Expand Down Expand Up @@ -1529,7 +1529,7 @@ def test_rsplit_bytearray(self):
def test_return_self(self):
# bytearray.replace must always return a new bytearray
b = bytearray()
self.assertFalse(b.replace(b'', b'') is b)

@unittest.skipUnless(sys.flags.bytes_warning,
"BytesWarning is needed for this test: use -bb option")
Expand Down Expand Up @@ -1588,14 +1588,14 @@ def test_returns_new_copy(self):
method = getattr(val, methname)
newval = method(3)
self.assertEqual(val, newval)
self.assertTrue(val is not 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,
expr+' returned val on a mutable object')
sep = self.marshal(b'')
newval = sep.join([val])
Expand Down Expand Up @@ -1634,7 +1634,7 @@ def test_basic(self):
self.assertTrue(_a <= _b)
self.assertTrue(_b >= _a)
self.assertTrue(_b > _a)
self.assertTrue(_a is not a)

# test concat of subclass instances
self.assertEqual(a + b, _a + _b)
Expand All @@ -1650,12 +1650,12 @@ def test_join(self):
# Make sure that it is of the appropriate type.
s1 = self.type2test(b"abcd")
s2 = self.basetype().join([s1])
self.assertTrue(s1 is not s2)
self.assertTrue(type(s2) is self.basetype, type(s2))

# Test reverse, calling join on subclass
s3 = s1.join([b"abcd"])
self.assertTrue(type(s3) is self.basetype)

def test_pickle(self):
a = self.type2test(b"abcd")
Expand Down
Toggle all file notes Toggle all file annotations