summaryrefslogtreecommitdiff
path: root/Lib/test/test_bytes.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-10-29 02:11:54 +0300
committerGitHub <noreply@github.com>2017-10-29 02:11:54 +0300
commita2314283ff87c65e1745a42c2f2b716b1a209128 (patch)
treeb1b1287aeea750c8694673939ec72b469c19cc59 /Lib/test/test_bytes.py
parent5a4bbcd479ce86f68bbe12bc8c16e3447f32e13a (diff)
downloadcpython-git-a2314283ff87c65e1745a42c2f2b716b1a209128.tar.gz
bpo-20047: Make bytearray methods partition() and rpartition() rejecting (#4158)
separators that are not bytes-like objects.
Diffstat (limited to 'Lib/test/test_bytes.py')
-rw-r--r--Lib/test/test_bytes.py35
1 files changed, 29 insertions, 6 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index 18091c1cfd..1408fb4fb8 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -548,8 +548,16 @@ class BaseBytesTest:
self.assertEqual(b.replace(b'i', b'a'), b'massassappa')
self.assertEqual(b.replace(b'ss', b'x'), b'mixixippi')
+ def test_replace_int_error(self):
+ self.assertRaises(TypeError, self.type2test(b'a b').replace, 32, b'')
+
def test_split_string_error(self):
self.assertRaises(TypeError, self.type2test(b'a b').split, ' ')
+ self.assertRaises(TypeError, self.type2test(b'a b').rsplit, ' ')
+
+ def test_split_int_error(self):
+ self.assertRaises(TypeError, self.type2test(b'a b').split, 32)
+ self.assertRaises(TypeError, self.type2test(b'a b').rsplit, 32)
def test_split_unicodewhitespace(self):
for b in (b'a\x1Cb', b'a\x1Db', b'a\x1Eb', b'a\x1Fb'):
@@ -558,9 +566,6 @@ class BaseBytesTest:
b = self.type2test(b"\x09\x0A\x0B\x0C\x0D\x1C\x1D\x1E\x1F")
self.assertEqual(b.split(), [b'\x1c\x1d\x1e\x1f'])
- def test_rsplit_string_error(self):
- self.assertRaises(TypeError, self.type2test(b'a b').rsplit, ' ')
-
def test_rsplit_unicodewhitespace(self):
b = self.type2test(b"\x09\x0A\x0B\x0C\x0D\x1C\x1D\x1E\x1F")
self.assertEqual(b.rsplit(), [b'\x1c\x1d\x1e\x1f'])
@@ -576,6 +581,14 @@ class BaseBytesTest:
self.assertEqual(b.rpartition(b'i'), (b'mississipp', b'i', b''))
self.assertEqual(b.rpartition(b'w'), (b'', b'', b'mississippi'))
+ def test_partition_string_error(self):
+ self.assertRaises(TypeError, self.type2test(b'a b').partition, ' ')
+ self.assertRaises(TypeError, self.type2test(b'a b').rpartition, ' ')
+
+ def test_partition_int_error(self):
+ self.assertRaises(TypeError, self.type2test(b'a b').partition, 32)
+ self.assertRaises(TypeError, self.type2test(b'a b').rpartition, 32)
+
def test_pickling(self):
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
for b in b"", b"a", b"abc", b"\xffab\x80", b"\0\0\377\0\0":
@@ -608,9 +621,14 @@ class BaseBytesTest:
self.assertEqual(self.type2test(b'abc').rstrip(memoryview(b'ac')), b'ab')
def test_strip_string_error(self):
- self.assertRaises(TypeError, self.type2test(b'abc').strip, 'b')
- self.assertRaises(TypeError, self.type2test(b'abc').lstrip, 'b')
- self.assertRaises(TypeError, self.type2test(b'abc').rstrip, 'b')
+ self.assertRaises(TypeError, self.type2test(b'abc').strip, 'ac')
+ self.assertRaises(TypeError, self.type2test(b'abc').lstrip, 'ac')
+ self.assertRaises(TypeError, self.type2test(b'abc').rstrip, 'ac')
+
+ def test_strip_int_error(self):
+ self.assertRaises(TypeError, self.type2test(b' abc ').strip, 32)
+ self.assertRaises(TypeError, self.type2test(b' abc ').lstrip, 32)
+ self.assertRaises(TypeError, self.type2test(b' abc ').rstrip, 32)
def test_center(self):
# Fill character can be either bytes or bytearray (issue 12380)
@@ -633,6 +651,11 @@ class BaseBytesTest:
self.assertEqual(b.rjust(7, fill_type(b'-')),
self.type2test(b'----abc'))
+ def test_xjust_int_error(self):
+ self.assertRaises(TypeError, self.type2test(b'abc').center, 7, 32)
+ self.assertRaises(TypeError, self.type2test(b'abc').ljust, 7, 32)
+ self.assertRaises(TypeError, self.type2test(b'abc').rjust, 7, 32)
+
def test_ord(self):
b = self.type2test(b'\0A\x7f\x80\xff')
self.assertEqual([ord(b[i:i+1]) for i in range(len(b))],