Issue #7654: enable additional bytes/bytearray tests. Patch by Florent Xicluna.

This commit is contained in:
Antoine Pitrou 2010-01-12 22:02:10 +00:00
parent b227f47b2b
commit efa45f35b5
1 changed files with 10 additions and 15 deletions

View File

@ -78,7 +78,7 @@ class BaseBytesTest(unittest.TestCase):
self.assertRaises(TypeError, self.type2test, 0.0) self.assertRaises(TypeError, self.type2test, 0.0)
class C: class C:
pass pass
# allowed in 2.6 # allowed in 2.x
#self.assertRaises(TypeError, self.type2test, ["0"]) #self.assertRaises(TypeError, self.type2test, ["0"])
self.assertRaises(TypeError, self.type2test, [0.0]) self.assertRaises(TypeError, self.type2test, [0.0])
self.assertRaises(TypeError, self.type2test, [None]) 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") self.assertEqual(self.type2test(b".").join([b"ab", b"cd"]), b"ab.cd")
# XXX more... # 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): def test_count(self):
b = self.type2test(b'mississippi') b = self.type2test(b'mississippi')
self.assertEqual(b.count(b'i'), 4) self.assertEqual(b.count(b'i'), 4)
@ -361,6 +354,10 @@ class BaseBytesTest(unittest.TestCase):
def test_split_string_error(self): def test_split_string_error(self):
self.assertRaises(TypeError, self.type2test(b'a b').split, u' ') 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): def test_rsplit(self):
b = self.type2test(b'mississippi') b = self.type2test(b'mississippi')
self.assertEqual(b.rsplit(b'i'), [b'm', b'ss', b'ss', b'pp', b'']) 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): def test_rsplit_unicodewhitespace(self):
b = self.type2test(b"\x09\x0A\x0B\x0C\x0D\x1C\x1D\x1E\x1F") 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']) self.assertEqual(b.rsplit(), [b'\x1c\x1d\x1e\x1f'])
def test_partition(self): def test_partition(self):
b = self.type2test(b'mississippi') b = self.type2test(b'mississippi')
self.assertEqual(b.partition(b'ss'), (b'mi', b'ss', b'issippi')) 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): def test_rpartition(self):
b = self.type2test(b'mississippi') b = self.type2test(b'mississippi')
self.assertEqual(b.rpartition(b'ss'), (b'missi', b'ss', b'ippi')) 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'i'), (b'mississipp', b'i', b''))
self.assertEqual(b.rpartition(b'w'), (b'', b'', b'mississippi'))
def test_pickling(self): def test_pickling(self):
for proto in range(pickle.HIGHEST_PROTOCOL + 1): 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.lstrip(), b'abc \t\n\r\f\v')
self.assertEqual(b.rstrip(), b' \t\n\r\f\vabc') self.assertEqual(b.rstrip(), b' \t\n\r\f\vabc')
def XXXtest_strip_bytearray(self): def test_strip_bytearray(self):
# XXX memoryview not available
self.assertEqual(self.type2test(b'abc').strip(memoryview(b'ac')), b'b') 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').lstrip(memoryview(b'ac')), b'bc')
self.assertEqual(self.type2test(b'abc').rstrip(memoryview(b'ac')), b'ab') 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(-2, ord('i'))
b.insert(1000, ord('i')) b.insert(1000, ord('i'))
self.assertEqual(b, b'mississippi') self.assertEqual(b, b'mississippi')
# allowed in 2.6 # allowed in 2.x
#self.assertRaises(TypeError, lambda: b.insert(0, b'1')) #self.assertRaises(TypeError, lambda: b.insert(0, b'1'))
b = bytearray() b = bytearray()
b.insert(0, Indexable(ord('A'))) b.insert(0, Indexable(ord('A')))
@ -755,8 +751,7 @@ class ByteArrayTest(BaseBytesTest):
self.assertEqual(b, b"") self.assertEqual(b, b"")
self.assertEqual(c, b"") self.assertEqual(c, b"")
# XXX memoryview not available def test_resize_forbidden(self):
def XXXtest_resize_forbidden(self):
# #4509: can't resize a bytearray when there are buffer exports, even # #4509: can't resize a bytearray when there are buffer exports, even
# if it wouldn't reallocate the underlying buffer. # if it wouldn't reallocate the underlying buffer.
# Furthermore, no destructive changes to the buffer may be applied # Furthermore, no destructive changes to the buffer may be applied