Back to index

python3.2  3.2.2
Public Member Functions | Static Public Attributes
test.test_bytes.BytesTest Class Reference
Inheritance diagram for test.test_bytes.BytesTest:
Inheritance graph
[legend]
Collaboration diagram for test.test_bytes.BytesTest:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_buffer_is_readonly
def test_custom
def test_from_format
def test_basics
def test_copy
def test_empty_sequence
def test_from_list
def test_from_index
def test_from_ssize
def test_constructor_type_errors
def test_constructor_value_errors
def test_compare
def test_compare_to_str
def test_reversed
def test_getslice
def test_extended_getslice
def test_encoding
def test_decode
def test_from_int
def test_concat
def test_repeat
def test_repeat_1char
def test_contains
def test_fromhex
def test_join
def test_count
def test_startswith
def test_endswith
def test_find
def test_rfind
def test_index
def test_rindex
def test_replace
def test_split
def test_split_whitespace
def test_split_string_error
def test_split_unicodewhitespace
def test_rsplit
def test_rsplit_whitespace
def test_rsplit_string_error
def test_rsplit_unicodewhitespace
def test_partition
def test_rpartition
def test_pickling
def test_strip
def test_lstrip
def test_rstrip
def test_strip_whitespace
def test_strip_bytearray
def test_strip_string_error
def test_ord
def test_maketrans
def test_none_arguments
def test_find_etc_raise_correct_error_messages

Static Public Attributes

 type2test = bytes

Detailed Description

Definition at line 552 of file test_bytes.py.


Member Function Documentation

def test.test_bytes.BaseBytesTest.test_basics (   self) [inherited]

Definition at line 43 of file test_bytes.py.

00043 
00044     def test_basics(self):
00045         b = self.type2test()
00046         self.assertEqual(type(b), self.type2test)
00047         self.assertEqual(b.__class__, self.type2test)

Here is the call graph for this function:

Definition at line 555 of file test_bytes.py.

00555 
00556     def test_buffer_is_readonly(self):
00557         fd = os.dup(sys.stdin.fileno())
00558         with open(fd, "rb", buffering=0) as f:
00559             self.assertRaises(TypeError, f.readinto, b"")

Here is the call graph for this function:

def test.test_bytes.BaseBytesTest.test_compare (   self) [inherited]

Definition at line 114 of file test_bytes.py.

00114 
00115     def test_compare(self):
00116         b1 = self.type2test([1, 2, 3])
00117         b2 = self.type2test([1, 2, 3])
00118         b3 = self.type2test([1, 3])
00119 
00120         self.assertEqual(b1, b2)
00121         self.assertTrue(b2 != b3)
00122         self.assertTrue(b1 <= b2)
00123         self.assertTrue(b1 <= b3)
00124         self.assertTrue(b1 <  b3)
00125         self.assertTrue(b1 >= b2)
00126         self.assertTrue(b3 >= b2)
00127         self.assertTrue(b3 >  b2)
00128 
00129         self.assertFalse(b1 != b2)
00130         self.assertFalse(b2 == b3)
00131         self.assertFalse(b1 >  b2)
00132         self.assertFalse(b1 >  b3)
00133         self.assertFalse(b1 >= b3)
00134         self.assertFalse(b1 <  b2)
00135         self.assertFalse(b3 <  b2)
00136         self.assertFalse(b3 <= b2)

Here is the call graph for this function:

Definition at line 138 of file test_bytes.py.

00138 
00139     def test_compare_to_str(self):
00140         # Byte comparisons with unicode should always fail!
00141         # Test this for all expected byte orders and Unicode character
00142         # sizes.
00143         self.assertEqual(self.type2test(b"\0a\0b\0c") == "abc", False)
00144         self.assertEqual(self.type2test(b"\0\0\0a\0\0\0b\0\0\0c") == "abc",
00145                             False)
00146         self.assertEqual(self.type2test(b"a\0b\0c\0") == "abc", False)
00147         self.assertEqual(self.type2test(b"a\0\0\0b\0\0\0c\0\0\0") == "abc",
00148                             False)
00149         self.assertEqual(self.type2test() == str(), False)
00150         self.assertEqual(self.type2test() != str(), True)

Here is the call graph for this function:

def test.test_bytes.BaseBytesTest.test_concat (   self) [inherited]

Definition at line 218 of file test_bytes.py.

00218 
00219     def test_concat(self):
00220         b1 = self.type2test(b"abc")
00221         b2 = self.type2test(b"def")
00222         self.assertEqual(b1 + b2, b"abcdef")
00223         self.assertEqual(b1 + bytes(b"def"), b"abcdef")
00224         self.assertEqual(bytes(b"def") + b1, b"defabc")
00225         self.assertRaises(TypeError, lambda: b1 + "def")
00226         self.assertRaises(TypeError, lambda: "abc" + b2)

Here is the call graph for this function:

Definition at line 93 of file test_bytes.py.

00093 
00094     def test_constructor_type_errors(self):
00095         self.assertRaises(TypeError, self.type2test, 0.0)
00096         class C:
00097             pass
00098         self.assertRaises(TypeError, self.type2test, ["0"])
00099         self.assertRaises(TypeError, self.type2test, [0.0])
00100         self.assertRaises(TypeError, self.type2test, [None])
00101         self.assertRaises(TypeError, self.type2test, [C()])

Here is the call graph for this function:

Definition at line 102 of file test_bytes.py.

00102 
00103     def test_constructor_value_errors(self):
00104         self.assertRaises(ValueError, self.type2test, [-1])
00105         self.assertRaises(ValueError, self.type2test, [-sys.maxsize])
00106         self.assertRaises(ValueError, self.type2test, [-sys.maxsize-1])
00107         self.assertRaises(ValueError, self.type2test, [-sys.maxsize-2])
00108         self.assertRaises(ValueError, self.type2test, [-10**100])
00109         self.assertRaises(ValueError, self.type2test, [256])
00110         self.assertRaises(ValueError, self.type2test, [257])
00111         self.assertRaises(ValueError, self.type2test, [sys.maxsize])
00112         self.assertRaises(ValueError, self.type2test, [sys.maxsize+1])
00113         self.assertRaises(ValueError, self.type2test, [10**100])

Here is the call graph for this function:

def test.test_bytes.BaseBytesTest.test_contains (   self) [inherited]

Definition at line 243 of file test_bytes.py.

00243 
00244     def test_contains(self):
00245         b = self.type2test(b"abc")
00246         self.assertIn(ord('a'), b)
00247         self.assertIn(int(ord('a')), b)
00248         self.assertNotIn(200, b)
00249         self.assertRaises(ValueError, lambda: 300 in b)
00250         self.assertRaises(ValueError, lambda: -1 in b)
00251         self.assertRaises(TypeError, lambda: None in b)
00252         self.assertRaises(TypeError, lambda: float(ord('a')) in b)
00253         self.assertRaises(TypeError, lambda: "a" in b)
00254         for f in bytes, bytearray:
00255             self.assertIn(f(b""), b)
00256             self.assertIn(f(b"a"), b)
00257             self.assertIn(f(b"b"), b)
00258             self.assertIn(f(b"c"), b)
00259             self.assertIn(f(b"ab"), b)
00260             self.assertIn(f(b"bc"), b)
00261             self.assertIn(f(b"abc"), b)
00262             self.assertNotIn(f(b"ac"), b)
00263             self.assertNotIn(f(b"d"), b)
00264             self.assertNotIn(f(b"dab"), b)
00265             self.assertNotIn(f(b"abd"), b)

Here is the call graph for this function:

def test.test_bytes.BaseBytesTest.test_copy (   self) [inherited]

Definition at line 48 of file test_bytes.py.

00048 
00049     def test_copy(self):
00050         a = self.type2test(b"abcd")
00051         for copy_method in (copy.copy, copy.deepcopy):
00052             b = copy_method(a)
00053             self.assertEqual(a, b)
00054             self.assertEqual(type(a), type(b))

Here is the call graph for this function:

def test.test_bytes.BaseBytesTest.test_count (   self) [inherited]

Definition at line 292 of file test_bytes.py.

00292 
00293     def test_count(self):
00294         b = self.type2test(b'mississippi')
00295         self.assertEqual(b.count(b'i'), 4)
00296         self.assertEqual(b.count(b'ss'), 2)
00297         self.assertEqual(b.count(b'w'), 0)

Here is the call graph for this function:

Definition at line 560 of file test_bytes.py.

00560 
00561     def test_custom(self):
00562         class A:
00563             def __bytes__(self):
00564                 return b'abc'
00565         self.assertEqual(bytes(A()), b'abc')
00566         class A: pass
00567         self.assertRaises(TypeError, bytes, A())
00568         class A:
00569             def __bytes__(self):
00570                 return None
00571         self.assertRaises(TypeError, bytes, A())

Here is the call graph for this function:

def test.test_bytes.BaseBytesTest.test_decode (   self) [inherited]

Definition at line 198 of file test_bytes.py.

00198 
00199     def test_decode(self):
00200         sample = "Hello world\n\u1234\u5678\u9abc\def0\def0"
00201         for enc in ("utf8", "utf16"):
00202             b = self.type2test(sample, enc)
00203             self.assertEqual(b.decode(enc), sample)
00204         sample = "Hello world\n\x80\x81\xfe\xff"
00205         b = self.type2test(sample, "latin1")
00206         self.assertRaises(UnicodeDecodeError, b.decode, "utf8")
00207         self.assertEqual(b.decode("utf8", "ignore"), "Hello world\n")
00208         self.assertEqual(b.decode(errors="ignore", encoding="utf8"),
00209                          "Hello world\n")

Here is the call graph for this function:

Definition at line 55 of file test_bytes.py.

00055 
00056     def test_empty_sequence(self):
00057         b = self.type2test()
00058         self.assertEqual(len(b), 0)
00059         self.assertRaises(IndexError, lambda: b[0])
00060         self.assertRaises(IndexError, lambda: b[1])
00061         self.assertRaises(IndexError, lambda: b[sys.maxsize])
00062         self.assertRaises(IndexError, lambda: b[sys.maxsize+1])
00063         self.assertRaises(IndexError, lambda: b[10**100])
00064         self.assertRaises(IndexError, lambda: b[-1])
00065         self.assertRaises(IndexError, lambda: b[-2])
00066         self.assertRaises(IndexError, lambda: b[-sys.maxsize])
00067         self.assertRaises(IndexError, lambda: b[-sys.maxsize-1])
00068         self.assertRaises(IndexError, lambda: b[-sys.maxsize-2])
00069         self.assertRaises(IndexError, lambda: b[-10**100])

Here is the call graph for this function:

def test.test_bytes.BaseBytesTest.test_encoding (   self) [inherited]

Definition at line 189 of file test_bytes.py.

00189 
00190     def test_encoding(self):
00191         sample = "Hello world\n\u1234\u5678\u9abc"
00192         for enc in ("utf8", "utf16"):
00193             b = self.type2test(sample, enc)
00194             self.assertEqual(b, self.type2test(sample.encode(enc)))
00195         self.assertRaises(UnicodeEncodeError, self.type2test, sample, "latin1")
00196         b = self.type2test(sample, "latin1", "ignore")
00197         self.assertEqual(b, self.type2test(sample[:-3], "utf-8"))

Here is the call graph for this function:

def test.test_bytes.BaseBytesTest.test_endswith (   self) [inherited]

Definition at line 312 of file test_bytes.py.

00312 
00313     def test_endswith(self):
00314         b = self.type2test(b'hello')
00315         self.assertFalse(bytearray().endswith(b"anything"))
00316         self.assertTrue(b.endswith(b"hello"))
00317         self.assertTrue(b.endswith(b"llo"))
00318         self.assertTrue(b.endswith(b"o"))
00319         self.assertFalse(b.endswith(b"whello"))
00320         self.assertFalse(b.endswith(b"no"))
00321         with self.assertRaises(TypeError) as cm:
00322             b.endswith([b'o'])
00323         exc = str(cm.exception)
00324         self.assertIn('bytes', exc)
00325         self.assertIn('tuple', exc)

Here is the call graph for this function:

Definition at line 178 of file test_bytes.py.

00178 
00179     def test_extended_getslice(self):
00180         # Test extended slicing by comparing with list slicing.
00181         L = list(range(255))
00182         b = self.type2test(L)
00183         indices = (0, None, 1, 3, 19, 100, -1, -2, -31, -100)
00184         for start in indices:
00185             for stop in indices:
00186                 # Skip step 0 (invalid)
00187                 for step in indices[1:]:
00188                     self.assertEqual(b[start:stop:step], self.type2test(L[start:stop:step]))

Here is the call graph for this function:

def test.test_bytes.BaseBytesTest.test_find (   self) [inherited]

Definition at line 326 of file test_bytes.py.

00326 
00327     def test_find(self):
00328         b = self.type2test(b'mississippi')
00329         self.assertEqual(b.find(b'ss'), 2)
00330         self.assertEqual(b.find(b'ss', 3), 5)
00331         self.assertEqual(b.find(b'ss', 1, 7), 2)
00332         self.assertEqual(b.find(b'ss', 1, 3), -1)
00333         self.assertEqual(b.find(b'w'), -1)
00334         self.assertEqual(b.find(b'mississippian'), -1)

Here is the call graph for this function:

Definition at line 532 of file test_bytes.py.

00532 
00533     def test_find_etc_raise_correct_error_messages(self):
00534         # issue 11828
00535         b = self.type2test(b'hello')
00536         x = self.type2test(b'x')
00537         self.assertRaisesRegex(TypeError, r'\bfind\b', b.find,
00538                                 x, None, None, None)
00539         self.assertRaisesRegex(TypeError, r'\brfind\b', b.rfind,
00540                                 x, None, None, None)
00541         self.assertRaisesRegex(TypeError, r'\bindex\b', b.index,
00542                                 x, None, None, None)
00543         self.assertRaisesRegex(TypeError, r'\brindex\b', b.rindex,
00544                                 x, None, None, None)
00545         self.assertRaisesRegex(TypeError, r'\bcount\b', b.count,
00546                                 x, None, None, None)
00547         self.assertRaisesRegex(TypeError, r'\bstartswith\b', b.startswith,
00548                                 x, None, None, None)
00549         self.assertRaisesRegex(TypeError, r'\bendswith\b', b.endswith,
00550                                 x, None, None, None)
00551 

Here is the call graph for this function:

Definition at line 573 of file test_bytes.py.

00573 
00574     def test_from_format(self):
00575         test.support.import_module('ctypes')
00576         from ctypes import pythonapi, py_object, c_int, c_char_p
00577         PyBytes_FromFormat = pythonapi.PyBytes_FromFormat
00578         PyBytes_FromFormat.restype = py_object
00579 
00580         self.assertEqual(PyBytes_FromFormat(b'format'),
00581                          b'format')
00582 
00583         self.assertEqual(PyBytes_FromFormat(b'%'), b'%')
00584         self.assertEqual(PyBytes_FromFormat(b'%%'), b'%')
00585         self.assertEqual(PyBytes_FromFormat(b'%%s'), b'%s')
00586         self.assertEqual(PyBytes_FromFormat(b'[%%]'), b'[%]')
00587         self.assertEqual(PyBytes_FromFormat(b'%%%c', c_int(ord('_'))), b'%_')
00588 
00589         self.assertEqual(PyBytes_FromFormat(b'c:%c', c_int(255)),
00590                          b'c:\xff')
00591         self.assertEqual(PyBytes_FromFormat(b's:%s', c_char_p(b'cstr')),
00592                          b's:cstr')
00593 

Here is the call graph for this function:

Definition at line 76 of file test_bytes.py.

00076 
00077     def test_from_index(self):
00078         b = self.type2test([Indexable(), Indexable(1), Indexable(254),
00079                             Indexable(255)])
00080         self.assertEqual(list(b), [0, 1, 254, 255])
00081         self.assertRaises(ValueError, self.type2test, [Indexable(-1)])
00082         self.assertRaises(ValueError, self.type2test, [Indexable(256)])

Here is the call graph for this function:

def test.test_bytes.BaseBytesTest.test_from_int (   self) [inherited]

Definition at line 210 of file test_bytes.py.

00210 
00211     def test_from_int(self):
00212         b = self.type2test(0)
00213         self.assertEqual(b, self.type2test())
00214         b = self.type2test(10)
00215         self.assertEqual(b, self.type2test([0]*10))
00216         b = self.type2test(10000)
00217         self.assertEqual(b, self.type2test([0]*10000))

Here is the call graph for this function:

Definition at line 70 of file test_bytes.py.

00070 
00071     def test_from_list(self):
00072         ints = list(range(256))
00073         b = self.type2test(i for i in ints)
00074         self.assertEqual(len(b), 256)
00075         self.assertEqual(list(b), ints)

Here is the call graph for this function:

Definition at line 83 of file test_bytes.py.

00083 
00084     def test_from_ssize(self):
00085         self.assertEqual(self.type2test(0), b'')
00086         self.assertEqual(self.type2test(1), b'\x00')
00087         self.assertEqual(self.type2test(5), b'\x00\x00\x00\x00\x00')
00088         self.assertRaises(ValueError, self.type2test, -1)
00089 
00090         self.assertEqual(self.type2test('0', 'ascii'), b'0')
00091         self.assertEqual(self.type2test(b'0'), b'0')
00092         self.assertRaises(OverflowError, self.type2test, sys.maxsize + 1)

Here is the call graph for this function:

def test.test_bytes.BaseBytesTest.test_fromhex (   self) [inherited]

Definition at line 266 of file test_bytes.py.

00266 
00267     def test_fromhex(self):
00268         self.assertRaises(TypeError, self.type2test.fromhex)
00269         self.assertRaises(TypeError, self.type2test.fromhex, 1)
00270         self.assertEqual(self.type2test.fromhex(''), self.type2test())
00271         b = bytearray([0x1a, 0x2b, 0x30])
00272         self.assertEqual(self.type2test.fromhex('1a2B30'), b)
00273         self.assertEqual(self.type2test.fromhex('  1A 2B  30   '), b)
00274         self.assertEqual(self.type2test.fromhex('0000'), b'\0\0')
00275         self.assertRaises(TypeError, self.type2test.fromhex, b'1B')
00276         self.assertRaises(ValueError, self.type2test.fromhex, 'a')
00277         self.assertRaises(ValueError, self.type2test.fromhex, 'rt')
00278         self.assertRaises(ValueError, self.type2test.fromhex, '1a b cd')
00279         self.assertRaises(ValueError, self.type2test.fromhex, '\x00')
00280         self.assertRaises(ValueError, self.type2test.fromhex, '12   \x00   34')

Here is the call graph for this function:

def test.test_bytes.BaseBytesTest.test_getslice (   self) [inherited]

Definition at line 158 of file test_bytes.py.

00158 
00159     def test_getslice(self):
00160         def by(s):
00161             return self.type2test(map(ord, s))
00162         b = by("Hello, world")
00163 
00164         self.assertEqual(b[:5], by("Hello"))
00165         self.assertEqual(b[1:5], by("ello"))
00166         self.assertEqual(b[5:7], by(", "))
00167         self.assertEqual(b[7:], by("world"))
00168         self.assertEqual(b[7:12], by("world"))
00169         self.assertEqual(b[7:100], by("world"))
00170 
00171         self.assertEqual(b[:-7], by("Hello"))
00172         self.assertEqual(b[-11:-7], by("ello"))
00173         self.assertEqual(b[-7:-5], by(", "))
00174         self.assertEqual(b[-5:], by("world"))
00175         self.assertEqual(b[-5:12], by("world"))
00176         self.assertEqual(b[-5:100], by("world"))
00177         self.assertEqual(b[-100:5], by("Hello"))

Here is the call graph for this function:

def test.test_bytes.BaseBytesTest.test_index (   self) [inherited]

Definition at line 343 of file test_bytes.py.

00343 
00344     def test_index(self):
00345         b = self.type2test(b'world')
00346         self.assertEqual(b.index(b'w'), 0)
00347         self.assertEqual(b.index(b'orl'), 1)
00348         self.assertRaises(ValueError, b.index, b'worm')
00349         self.assertRaises(ValueError, b.index, b'ldo')

Here is the call graph for this function:

def test.test_bytes.BaseBytesTest.test_join (   self) [inherited]

Definition at line 281 of file test_bytes.py.

00281 
00282     def test_join(self):
00283         self.assertEqual(self.type2test(b"").join([]), b"")
00284         self.assertEqual(self.type2test(b"").join([b""]), b"")
00285         for lst in [[b"abc"], [b"a", b"bc"], [b"ab", b"c"], [b"a", b"b", b"c"]]:
00286             lst = list(map(self.type2test, lst))
00287             self.assertEqual(self.type2test(b"").join(lst), b"abc")
00288             self.assertEqual(self.type2test(b"").join(tuple(lst)), b"abc")
00289             self.assertEqual(self.type2test(b"").join(iter(lst)), b"abc")
00290         self.assertEqual(self.type2test(b".").join([b"ab", b"cd"]), b"ab.cd")
00291         # XXX more...

Here is the call graph for this function:

def test.test_bytes.BaseBytesTest.test_lstrip (   self) [inherited]

Definition at line 444 of file test_bytes.py.

00444 
00445     def test_lstrip(self):
00446         b = self.type2test(b'mississippi')
00447         self.assertEqual(b.lstrip(b'i'), b'mississippi')
00448         self.assertEqual(b.lstrip(b'm'), b'ississippi')
00449         self.assertEqual(b.lstrip(b'pi'), b'mississippi')
00450         self.assertEqual(b.lstrip(b'im'), b'ssissippi')
00451         self.assertEqual(b.lstrip(b'pim'), b'ssissippi')

Here is the call graph for this function:

Definition at line 481 of file test_bytes.py.

00481 
00482     def test_maketrans(self):
00483         transtable = b'\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037 !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`xyzdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377'
00484         self.assertEqual(self.type2test.maketrans(b'abc', b'xyz'), transtable)
00485         transtable = b'\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037 !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374xyz'
00486         self.assertEqual(self.type2test.maketrans(b'\375\376\377', b'xyz'), transtable)
00487         self.assertRaises(ValueError, self.type2test.maketrans, b'abc', b'xyzq')
00488         self.assertRaises(TypeError, self.type2test.maketrans, 'abc', 'def')

Here is the call graph for this function:

Definition at line 489 of file test_bytes.py.

00489 
00490     def test_none_arguments(self):
00491         # issue 11828
00492         b = self.type2test(b'hello')
00493         l = self.type2test(b'l')
00494         h = self.type2test(b'h')
00495         x = self.type2test(b'x')
00496         o = self.type2test(b'o')
00497 
00498         self.assertEqual(2, b.find(l, None))
00499         self.assertEqual(3, b.find(l, -2, None))
00500         self.assertEqual(2, b.find(l, None, -2))
00501         self.assertEqual(0, b.find(h, None, None))
00502 
00503         self.assertEqual(3, b.rfind(l, None))
00504         self.assertEqual(3, b.rfind(l, -2, None))
00505         self.assertEqual(2, b.rfind(l, None, -2))
00506         self.assertEqual(0, b.rfind(h, None, None))
00507 
00508         self.assertEqual(2, b.index(l, None))
00509         self.assertEqual(3, b.index(l, -2, None))
00510         self.assertEqual(2, b.index(l, None, -2))
00511         self.assertEqual(0, b.index(h, None, None))
00512 
00513         self.assertEqual(3, b.rindex(l, None))
00514         self.assertEqual(3, b.rindex(l, -2, None))
00515         self.assertEqual(2, b.rindex(l, None, -2))
00516         self.assertEqual(0, b.rindex(h, None, None))
00517 
00518         self.assertEqual(2, b.count(l, None))
00519         self.assertEqual(1, b.count(l, -2, None))
00520         self.assertEqual(1, b.count(l, None, -2))
00521         self.assertEqual(0, b.count(x, None, None))
00522 
00523         self.assertEqual(True, b.endswith(o, None))
00524         self.assertEqual(True, b.endswith(o, -2, None))
00525         self.assertEqual(True, b.endswith(l, None, -2))
00526         self.assertEqual(False, b.endswith(x, None, None))
00527 
00528         self.assertEqual(True, b.startswith(h, None))
00529         self.assertEqual(True, b.startswith(l, -2, None))
00530         self.assertEqual(True, b.startswith(h, None, -2))
00531         self.assertEqual(False, b.startswith(x, None, None))

Here is the call graph for this function:

def test.test_bytes.BaseBytesTest.test_ord (   self) [inherited]

Definition at line 476 of file test_bytes.py.

00476 
00477     def test_ord(self):
00478         b = self.type2test(b'\0A\x7f\x80\xff')
00479         self.assertEqual([ord(b[i:i+1]) for i in range(len(b))],
00480                          [0, 65, 127, 128, 255])

Here is the call graph for this function:

Definition at line 416 of file test_bytes.py.

00416 
00417     def test_partition(self):
00418         b = self.type2test(b'mississippi')
00419         self.assertEqual(b.partition(b'ss'), (b'mi', b'ss', b'issippi'))
00420         self.assertEqual(b.partition(b'w'), (b'mississippi', b'', b''))

Here is the call graph for this function:

def test.test_bytes.BaseBytesTest.test_pickling (   self) [inherited]

Definition at line 427 of file test_bytes.py.

00427 
00428     def test_pickling(self):
00429         for proto in range(pickle.HIGHEST_PROTOCOL + 1):
00430             for b in b"", b"a", b"abc", b"\xffab\x80", b"\0\0\377\0\0":
00431                 b = self.type2test(b)
00432                 ps = pickle.dumps(b, proto)
00433                 q = pickle.loads(ps)
00434                 self.assertEqual(b, q)

Here is the call graph for this function:

def test.test_bytes.BaseBytesTest.test_repeat (   self) [inherited]

Definition at line 227 of file test_bytes.py.

00227 
00228     def test_repeat(self):
00229         for b in b"abc", self.type2test(b"abc"):
00230             self.assertEqual(b * 3, b"abcabcabc")
00231             self.assertEqual(b * 0, b"")
00232             self.assertEqual(b * -1, b"")
00233             self.assertRaises(TypeError, lambda: b * 3.14)
00234             self.assertRaises(TypeError, lambda: 3.14 * b)
00235             # XXX Shouldn't bytes and bytearray agree on what to raise?
00236             with self.assertRaises((OverflowError, MemoryError)):
00237                 c = b * sys.maxsize
00238             with self.assertRaises((OverflowError, MemoryError)):
00239                 b *= sys.maxsize

Here is the call graph for this function:

Definition at line 240 of file test_bytes.py.

00240 
00241     def test_repeat_1char(self):
00242         self.assertEqual(self.type2test(b'x')*100, self.type2test([ord('x')]*100))

Here is the call graph for this function:

def test.test_bytes.BaseBytesTest.test_replace (   self) [inherited]

Definition at line 358 of file test_bytes.py.

00358 
00359     def test_replace(self):
00360         b = self.type2test(b'mississippi')
00361         self.assertEqual(b.replace(b'i', b'a'), b'massassappa')
00362         self.assertEqual(b.replace(b'ss', b'x'), b'mixixippi')

Here is the call graph for this function:

def test.test_bytes.BaseBytesTest.test_reversed (   self) [inherited]

Definition at line 151 of file test_bytes.py.

00151 
00152     def test_reversed(self):
00153         input = list(map(ord, "Hello"))
00154         b = self.type2test(input)
00155         output = list(reversed(b))
00156         input.reverse()
00157         self.assertEqual(output, input)

Here is the call graph for this function:

def test.test_bytes.BaseBytesTest.test_rfind (   self) [inherited]

Definition at line 335 of file test_bytes.py.

00335 
00336     def test_rfind(self):
00337         b = self.type2test(b'mississippi')
00338         self.assertEqual(b.rfind(b'ss'), 5)
00339         self.assertEqual(b.rfind(b'ss', 3), 5)
00340         self.assertEqual(b.rfind(b'ss', 0, 6), 2)
00341         self.assertEqual(b.rfind(b'w'), -1)
00342         self.assertEqual(b.rfind(b'mississippian'), -1)

Here is the call graph for this function:

def test.test_bytes.BaseBytesTest.test_rindex (   self) [inherited]

Definition at line 350 of file test_bytes.py.

00350 
00351     def test_rindex(self):
00352         # XXX could be more rigorous
00353         b = self.type2test(b'world')
00354         self.assertEqual(b.rindex(b'w'), 0)
00355         self.assertEqual(b.rindex(b'orl'), 1)
00356         self.assertRaises(ValueError, b.rindex, b'worm')
00357         self.assertRaises(ValueError, b.rindex, b'ldo')

Here is the call graph for this function:

Definition at line 421 of file test_bytes.py.

00421 
00422     def test_rpartition(self):
00423         b = self.type2test(b'mississippi')
00424         self.assertEqual(b.rpartition(b'ss'), (b'missi', b'ss', b'ippi'))
00425         self.assertEqual(b.rpartition(b'i'), (b'mississipp', b'i', b''))
00426         self.assertEqual(b.rpartition(b'w'), (b'', b'', b'mississippi'))

Here is the call graph for this function:

def test.test_bytes.BaseBytesTest.test_rsplit (   self) [inherited]

Definition at line 391 of file test_bytes.py.

00391 
00392     def test_rsplit(self):
00393         b = self.type2test(b'mississippi')
00394         self.assertEqual(b.rsplit(b'i'), [b'm', b'ss', b'ss', b'pp', b''])
00395         self.assertEqual(b.rsplit(b'ss'), [b'mi', b'i', b'ippi'])
00396         self.assertEqual(b.rsplit(b'w'), [b])

Here is the call graph for this function:

Definition at line 409 of file test_bytes.py.

00409 
00410     def test_rsplit_string_error(self):
00411         self.assertRaises(TypeError, self.type2test(b'a b').rsplit, ' ')

Here is the call graph for this function:

Definition at line 412 of file test_bytes.py.

00412 
00413     def test_rsplit_unicodewhitespace(self):
00414         b = self.type2test(b"\x09\x0A\x0B\x0C\x0D\x1C\x1D\x1E\x1F")
00415         self.assertEqual(b.rsplit(), [b'\x1c\x1d\x1e\x1f'])

Here is the call graph for this function:

Definition at line 397 of file test_bytes.py.

00397 
00398     def test_rsplit_whitespace(self):
00399         for b in (b'  arf  barf  ', b'arf\tbarf', b'arf\nbarf', b'arf\rbarf',
00400                   b'arf\fbarf', b'arf\vbarf'):
00401             b = self.type2test(b)
00402             self.assertEqual(b.rsplit(), [b'arf', b'barf'])
00403             self.assertEqual(b.rsplit(None), [b'arf', b'barf'])
00404             self.assertEqual(b.rsplit(None, 2), [b'arf', b'barf'])
00405         self.assertEqual(self.type2test(b'  a  bb  c  ').rsplit(None, 0), [b'  a  bb  c'])
00406         self.assertEqual(self.type2test(b'  a  bb  c  ').rsplit(None, 1), [b'  a  bb', b'c'])
00407         self.assertEqual(self.type2test(b'  a  bb  c  ').rsplit(None, 2), [b'  a', b'bb', b'c'])
00408         self.assertEqual(self.type2test(b'  a  bb  c  ').rsplit(None, 3), [b'a', b'bb', b'c'])

Here is the call graph for this function:

def test.test_bytes.BaseBytesTest.test_rstrip (   self) [inherited]

Definition at line 452 of file test_bytes.py.

00452 
00453     def test_rstrip(self):
00454         b = self.type2test(b'mississippi')
00455         self.assertEqual(b.rstrip(b'i'), b'mississipp')
00456         self.assertEqual(b.rstrip(b'm'), b'mississippi')
00457         self.assertEqual(b.rstrip(b'pi'), b'mississ')
00458         self.assertEqual(b.rstrip(b'im'), b'mississipp')
00459         self.assertEqual(b.rstrip(b'pim'), b'mississ')

Here is the call graph for this function:

def test.test_bytes.BaseBytesTest.test_split (   self) [inherited]

Definition at line 363 of file test_bytes.py.

00363 
00364     def test_split(self):
00365         b = self.type2test(b'mississippi')
00366         self.assertEqual(b.split(b'i'), [b'm', b'ss', b'ss', b'pp', b''])
00367         self.assertEqual(b.split(b'ss'), [b'mi', b'i', b'ippi'])
00368         self.assertEqual(b.split(b'w'), [b])

Here is the call graph for this function:

Definition at line 384 of file test_bytes.py.

00384 
00385     def test_split_string_error(self):
00386         self.assertRaises(TypeError, self.type2test(b'a b').split, ' ')

Here is the call graph for this function:

Definition at line 387 of file test_bytes.py.

00387 
00388     def test_split_unicodewhitespace(self):
00389         b = self.type2test(b"\x09\x0A\x0B\x0C\x0D\x1C\x1D\x1E\x1F")
00390         self.assertEqual(b.split(), [b'\x1c\x1d\x1e\x1f'])

Here is the call graph for this function:

Definition at line 369 of file test_bytes.py.

00369 
00370     def test_split_whitespace(self):
00371         for b in (b'  arf  barf  ', b'arf\tbarf', b'arf\nbarf', b'arf\rbarf',
00372                   b'arf\fbarf', b'arf\vbarf'):
00373             b = self.type2test(b)
00374             self.assertEqual(b.split(), [b'arf', b'barf'])
00375             self.assertEqual(b.split(None), [b'arf', b'barf'])
00376             self.assertEqual(b.split(None, 2), [b'arf', b'barf'])
00377         for b in (b'a\x1Cb', b'a\x1Db', b'a\x1Eb', b'a\x1Fb'):
00378             b = self.type2test(b)
00379             self.assertEqual(b.split(), [b])
00380         self.assertEqual(self.type2test(b'  a  bb  c  ').split(None, 0), [b'a  bb  c  '])
00381         self.assertEqual(self.type2test(b'  a  bb  c  ').split(None, 1), [b'a', b'bb  c  '])
00382         self.assertEqual(self.type2test(b'  a  bb  c  ').split(None, 2), [b'a', b'bb', b'c  '])
00383         self.assertEqual(self.type2test(b'  a  bb  c  ').split(None, 3), [b'a', b'bb', b'c'])

Here is the call graph for this function:

Definition at line 298 of file test_bytes.py.

00298 
00299     def test_startswith(self):
00300         b = self.type2test(b'hello')
00301         self.assertFalse(self.type2test().startswith(b"anything"))
00302         self.assertTrue(b.startswith(b"hello"))
00303         self.assertTrue(b.startswith(b"hel"))
00304         self.assertTrue(b.startswith(b"h"))
00305         self.assertFalse(b.startswith(b"hellow"))
00306         self.assertFalse(b.startswith(b"ha"))
00307         with self.assertRaises(TypeError) as cm:
00308             b.startswith([b'h'])
00309         exc = str(cm.exception)
00310         self.assertIn('bytes', exc)
00311         self.assertIn('tuple', exc)

Here is the call graph for this function:

def test.test_bytes.BaseBytesTest.test_strip (   self) [inherited]

Definition at line 435 of file test_bytes.py.

00435 
00436     def test_strip(self):
00437         b = self.type2test(b'mississippi')
00438         self.assertEqual(b.strip(b'i'), b'mississipp')
00439         self.assertEqual(b.strip(b'm'), b'ississippi')
00440         self.assertEqual(b.strip(b'pi'), b'mississ')
00441         self.assertEqual(b.strip(b'im'), b'ssissipp')
00442         self.assertEqual(b.strip(b'pim'), b'ssiss')
00443         self.assertEqual(b.strip(b), b'')

Here is the call graph for this function:

Definition at line 466 of file test_bytes.py.

00466 
00467     def test_strip_bytearray(self):
00468         self.assertEqual(self.type2test(b'abc').strip(memoryview(b'ac')), b'b')
00469         self.assertEqual(self.type2test(b'abc').lstrip(memoryview(b'ac')), b'bc')
00470         self.assertEqual(self.type2test(b'abc').rstrip(memoryview(b'ac')), b'ab')

Here is the call graph for this function:

Definition at line 471 of file test_bytes.py.

00471 
00472     def test_strip_string_error(self):
00473         self.assertRaises(TypeError, self.type2test(b'abc').strip, 'b')
00474         self.assertRaises(TypeError, self.type2test(b'abc').lstrip, 'b')
00475         self.assertRaises(TypeError, self.type2test(b'abc').rstrip, 'b')

Here is the call graph for this function:

Definition at line 460 of file test_bytes.py.

00460 
00461     def test_strip_whitespace(self):
00462         b = self.type2test(b' \t\n\r\f\vabc \t\n\r\f\v')
00463         self.assertEqual(b.strip(), b'abc')
00464         self.assertEqual(b.lstrip(), b'abc \t\n\r\f\v')
00465         self.assertEqual(b.rstrip(), b' \t\n\r\f\vabc')

Here is the call graph for this function:


Member Data Documentation

Definition at line 553 of file test_bytes.py.


The documentation for this class was generated from the following file: