mirror of https://github.com/python/cpython
Issue #7654: enable additional bytes/bytearray tests. Patch by Florent Xicluna.
This commit is contained in:
parent
b227f47b2b
commit
efa45f35b5
|
@ -78,7 +78,7 @@ class BaseBytesTest(unittest.TestCase):
|
|||
self.assertRaises(TypeError, self.type2test, 0.0)
|
||||
class C:
|
||||
pass
|
||||
# allowed in 2.6
|
||||
# allowed in 2.x
|
||||
#self.assertRaises(TypeError, self.type2test, ["0"])
|
||||
self.assertRaises(TypeError, self.type2test, [0.0])
|
||||
self.assertRaises(TypeError, self.type2test, [None])
|
||||
|
@ -269,13 +269,6 @@ class BaseBytesTest(unittest.TestCase):
|
|||
self.assertEqual(self.type2test(b".").join([b"ab", b"cd"]), b"ab.cd")
|
||||
# XXX more...
|
||||
|
||||
def test_index(self):
|
||||
b = self.type2test(b'parrot')
|
||||
self.assertEqual(b.index('p'), 0)
|
||||
self.assertEqual(b.index('rr'), 2)
|
||||
self.assertEqual(b.index('t'), 5)
|
||||
self.assertRaises(ValueError, lambda: b.index('w'))
|
||||
|
||||
def test_count(self):
|
||||
b = self.type2test(b'mississippi')
|
||||
self.assertEqual(b.count(b'i'), 4)
|
||||
|
@ -361,6 +354,10 @@ class BaseBytesTest(unittest.TestCase):
|
|||
def test_split_string_error(self):
|
||||
self.assertRaises(TypeError, self.type2test(b'a b').split, u' ')
|
||||
|
||||
def test_split_unicodewhitespace(self):
|
||||
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(self):
|
||||
b = self.type2test(b'mississippi')
|
||||
self.assertEqual(b.rsplit(b'i'), [b'm', b'ss', b'ss', b'pp', b''])
|
||||
|
@ -384,18 +381,18 @@ class BaseBytesTest(unittest.TestCase):
|
|||
|
||||
def test_rsplit_unicodewhitespace(self):
|
||||
b = self.type2test(b"\x09\x0A\x0B\x0C\x0D\x1C\x1D\x1E\x1F")
|
||||
self.assertEqual(b.split(), [b'\x1c\x1d\x1e\x1f'])
|
||||
self.assertEqual(b.rsplit(), [b'\x1c\x1d\x1e\x1f'])
|
||||
|
||||
def test_partition(self):
|
||||
b = self.type2test(b'mississippi')
|
||||
self.assertEqual(b.partition(b'ss'), (b'mi', b'ss', b'issippi'))
|
||||
self.assertEqual(b.rpartition(b'w'), (b'', b'', b'mississippi'))
|
||||
self.assertEqual(b.partition(b'w'), (b'mississippi', b'', b''))
|
||||
|
||||
def test_rpartition(self):
|
||||
b = self.type2test(b'mississippi')
|
||||
self.assertEqual(b.rpartition(b'ss'), (b'missi', b'ss', b'ippi'))
|
||||
self.assertEqual(b.rpartition(b'i'), (b'mississipp', b'i', b''))
|
||||
self.assertEqual(b.rpartition(b'w'), (b'', b'', b'mississippi'))
|
||||
|
||||
def test_pickling(self):
|
||||
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
||||
|
@ -436,8 +433,7 @@ class BaseBytesTest(unittest.TestCase):
|
|||
self.assertEqual(b.lstrip(), b'abc \t\n\r\f\v')
|
||||
self.assertEqual(b.rstrip(), b' \t\n\r\f\vabc')
|
||||
|
||||
def XXXtest_strip_bytearray(self):
|
||||
# XXX memoryview not available
|
||||
def test_strip_bytearray(self):
|
||||
self.assertEqual(self.type2test(b'abc').strip(memoryview(b'ac')), b'b')
|
||||
self.assertEqual(self.type2test(b'abc').lstrip(memoryview(b'ac')), b'bc')
|
||||
self.assertEqual(self.type2test(b'abc').rstrip(memoryview(b'ac')), b'ab')
|
||||
|
@ -718,7 +714,7 @@ class ByteArrayTest(BaseBytesTest):
|
|||
b.insert(-2, ord('i'))
|
||||
b.insert(1000, ord('i'))
|
||||
self.assertEqual(b, b'mississippi')
|
||||
# allowed in 2.6
|
||||
# allowed in 2.x
|
||||
#self.assertRaises(TypeError, lambda: b.insert(0, b'1'))
|
||||
b = bytearray()
|
||||
b.insert(0, Indexable(ord('A')))
|
||||
|
@ -755,8 +751,7 @@ class ByteArrayTest(BaseBytesTest):
|
|||
self.assertEqual(b, b"")
|
||||
self.assertEqual(c, b"")
|
||||
|
||||
# XXX memoryview not available
|
||||
def XXXtest_resize_forbidden(self):
|
||||
def test_resize_forbidden(self):
|
||||
# #4509: can't resize a bytearray when there are buffer exports, even
|
||||
# if it wouldn't reallocate the underlying buffer.
|
||||
# Furthermore, no destructive changes to the buffer may be applied
|
||||
|
|
Loading…
Reference in New Issue