summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-10-29 10:24:45 (GMT)
committerGitHub <noreply@github.com>2017-10-29 10:24:45 (GMT)
commit9ea5a3a45b35d01b602e7e4da4f72b2db407e5c6 (patch)
tree11ee75c2a6cb1780e7aac0137058379498ca376e /Lib/test
parent0f1973d06e2116deafb19bbb9443b138187803c7 (diff)
downloadcpython-9ea5a3a45b35d01b602e7e4da4f72b2db407e5c6.zip
cpython-9ea5a3a45b35d01b602e7e4da4f72b2db407e5c6.tar.gz
cpython-9ea5a3a45b35d01b602e7e4da4f72b2db407e5c6.tar.bz2
[3.6] bpo-20047: Make bytearray methods partition() and rpartition() rejecting (GH-4158) (#4162)
separators that are not bytes-like objects.. (cherry picked from commit a2314283ff87c65e1745a42c2f2b716b1a209128)
Diffstat (limited to 'Lib/test')
-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 cd82fa6..6fcc26a 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -540,8 +540,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'):
@@ -550,9 +558,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'])
@@ -568,6 +573,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":
@@ -600,9 +613,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)
@@ -625,6 +643,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))],