コード例 #1
0
 def test_setitem_using_slice_with_empty_sequence(self):
     # This will call BytesList.__setslice__ on Python 2
     bytes_list = BytesList()
     bytes_list.extend([b"zero", b"one", b"two", b"three"])
     bytes_list[1:3] = []
     self.assertEqual(bytes_list, [b"zero", b"three"])
コード例 #2
0
 def test_setitem_using_stepped_slice(self):
     # This will call BytesList.__setitem__ on both Python 2 and Python 3
     bytes_list = BytesList()
     bytes_list.extend([b"zero", b"one", b"two", b"three"])
     bytes_list[0:3:2] = [b"four", b"five"]
     self.assertEqual(bytes_list, [b"four", b"one", b"five", b"three"])
コード例 #3
0
 def test_setitem_using_slice_with_non_string(self):
     # This will call BytesList.__setslice__ on Python 2
     bytes_list = BytesList()
     bytes_list.extend([b"zero", b"one", b"two", b"three"])
     with self.assertRaises(TypeError):
         bytes_list[1:3] = [u"four", NON_STRING_VALUE]
コード例 #4
0
 def test_append(self):
     bytes_list = BytesList()
     bytes_list.append(b"some string")
     self.assertEqual(bytes_list, [b"some string"])
コード例 #5
0
 def test_insert_with_byte_string(self):
     bytes_list = BytesList()
     with self.assertRaises(TypeError):
         bytes_list.insert(0, u"some string")
コード例 #6
0
 def test_setitem_using_integer(self):
     bytes_list = BytesList()
     bytes_list.append(b"some string")
     bytes_list[0] = b"another string"
     self.assertEqual(bytes_list[0], b"another string")
コード例 #7
0
 def test_insert(self):
     bytes_list = BytesList()
     bytes_list.insert(0, b"some string")
     self.assertEqual(bytes_list, [b"some string"])
コード例 #8
0
 def test_insert_with_non_string(self):
     bytes_list = BytesList()
     with self.assertRaises(TypeError):
         bytes_list.insert(0, NON_STRING_VALUE)
コード例 #9
0
 def test_extend_with_unicode_string(self):
     bytes_list = BytesList()
     with self.assertRaises(TypeError):
         bytes_list.extend([u"some string"])
コード例 #10
0
 def test_extend_with_empty_sequence(self):
     bytes_list = BytesList()
     bytes_list.extend([])
     self.assertEqual(bytes_list, [])
コード例 #11
0
 def test_extend_with_non_string(self):
     bytes_list = BytesList()
     with self.assertRaises(TypeError):
         bytes_list.extend([b"some string", NON_STRING_VALUE])
コード例 #12
0
 def test_extend(self):
     bytes_list = BytesList()
     bytes_list.extend([b"some string", b"another string"])
     self.assertEqual(bytes_list, [b"some string", b"another string"])
コード例 #13
0
 def test_delitem_with_slice(self):
     bytes_list = BytesList()
     bytes_list.extend([b"zero", b"one", b"two", b"three"])
     del bytes_list[1:3]
     self.assertEqual(bytes_list, [b"zero", b"three"])
コード例 #14
0
 def test_append_with_non_string(self):
     bytes_list = BytesList()
     with self.assertRaises(TypeError):
         bytes_list.append(NON_STRING_VALUE)
コード例 #15
0
 def test_setitem_using_stepped_slice_with_non_string(self):
     # This will call BytesList.__setitem__ on both Python 2 and Python 3
     bytes_list = BytesList()
     bytes_list.extend([b"zero", b"one", b"two", b"three"])
     with self.assertRaises(TypeError):
         bytes_list[0:3:2] = [b"four", NON_STRING_VALUE]