Back to index

python3.2  3.2.2
Public Member Functions
test.test_bytes.AssortedBytesTest Class Reference

List of all members.

Public Member Functions

def test_repr_str
def test_compare_bytes_to_bytearray
def test_doc
def test_from_bytearray
def test_to_str
def test_literal
def test_translate
def test_split_bytearray
def test_rsplit_bytearray
def test_return_self
def test_compare

Detailed Description

Definition at line 926 of file test_bytes.py.


Member Function Documentation

Definition at line 1034 of file test_bytes.py.

01034 
01035     def test_compare(self):
01036         if sys.flags.bytes_warning:
01037             def bytes_warning():
01038                 return test.support.check_warnings(('', BytesWarning))
01039             with bytes_warning():
01040                 b'' == ''
01041             with bytes_warning():
01042                 b'' != ''
01043             with bytes_warning():
01044                 bytearray(b'') == ''
01045             with bytes_warning():
01046                 bytearray(b'') != ''
01047         else:
01048             self.skipTest("BytesWarning is needed for this test: use -bb option")

Here is the call graph for this function:

Definition at line 942 of file test_bytes.py.

00942 
00943     def test_compare_bytes_to_bytearray(self):
00944         self.assertEqual(b"abc" == bytes(b"abc"), True)
00945         self.assertEqual(b"ab" != bytes(b"abc"), True)
00946         self.assertEqual(b"ab" <= bytes(b"abc"), True)
00947         self.assertEqual(b"ab" < bytes(b"abc"), True)
00948         self.assertEqual(b"abc" >= bytes(b"ab"), True)
00949         self.assertEqual(b"abc" > bytes(b"ab"), True)
00950 
00951         self.assertEqual(b"abc" != bytes(b"abc"), False)
00952         self.assertEqual(b"ab" == bytes(b"abc"), False)
00953         self.assertEqual(b"ab" > bytes(b"abc"), False)
00954         self.assertEqual(b"ab" >= bytes(b"abc"), False)
00955         self.assertEqual(b"abc" < bytes(b"ab"), False)
00956         self.assertEqual(b"abc" <= bytes(b"ab"), False)
00957 
00958         self.assertEqual(bytes(b"abc") == b"abc", True)
00959         self.assertEqual(bytes(b"ab") != b"abc", True)
00960         self.assertEqual(bytes(b"ab") <= b"abc", True)
00961         self.assertEqual(bytes(b"ab") < b"abc", True)
00962         self.assertEqual(bytes(b"abc") >= b"ab", True)
00963         self.assertEqual(bytes(b"abc") > b"ab", True)
00964 
00965         self.assertEqual(bytes(b"abc") != b"abc", False)
00966         self.assertEqual(bytes(b"ab") == b"abc", False)
00967         self.assertEqual(bytes(b"ab") > b"abc", False)
00968         self.assertEqual(bytes(b"ab") >= b"abc", False)
00969         self.assertEqual(bytes(b"abc") < b"ab", False)
00970         self.assertEqual(bytes(b"abc") <= b"ab", False)

Here is the call graph for this function:

Definition at line 971 of file test_bytes.py.

00971 
00972     def test_doc(self):
00973         self.assertIsNotNone(bytearray.__doc__)
00974         self.assertTrue(bytearray.__doc__.startswith("bytearray("), bytearray.__doc__)
00975         self.assertIsNotNone(bytes.__doc__)
00976         self.assertTrue(bytes.__doc__.startswith("bytes("), bytes.__doc__)

Here is the call graph for this function:

Definition at line 977 of file test_bytes.py.

00977 
00978     def test_from_bytearray(self):
00979         sample = bytes(b"Hello world\n\x80\x81\xfe\xff")
00980         buf = memoryview(sample)
00981         b = bytearray(buf)
00982         self.assertEqual(b, bytearray(sample))

Here is the call graph for this function:

Definition at line 992 of file test_bytes.py.

00992 
00993     def test_literal(self):
00994         tests =  [
00995             (b"Wonderful spam", "Wonderful spam"),
00996             (br"Wonderful spam too", "Wonderful spam too"),
00997             (b"\xaa\x00\000\200", "\xaa\x00\000\200"),
00998             (br"\xaa\x00\000\200", r"\xaa\x00\000\200"),
00999         ]
01000         for b, s in tests:
01001             self.assertEqual(b, bytearray(s, 'latin-1'))
01002         for c in range(128, 256):
01003             self.assertRaises(SyntaxError, eval,
01004                               'b"%s"' % chr(c))

Here is the call graph for this function:

Definition at line 932 of file test_bytes.py.

00932 
00933     def test_repr_str(self):
00934         for f in str, repr:
00935             self.assertEqual(f(bytearray()), "bytearray(b'')")
00936             self.assertEqual(f(bytearray([0])), "bytearray(b'\\x00')")
00937             self.assertEqual(f(bytearray([0, 1, 254, 255])),
00938                              "bytearray(b'\\x00\\x01\\xfe\\xff')")
00939             self.assertEqual(f(b"abc"), "b'abc'")
00940             self.assertEqual(f(b"'"), '''b"'"''') # '''
00941             self.assertEqual(f(b"'\""), r"""b'\'"'""") # '

Here is the call graph for this function:

Definition at line 1029 of file test_bytes.py.

01029 
01030     def test_return_self(self):
01031         # bytearray.replace must always return a new bytearray
01032         b = bytearray()
01033         self.assertFalse(b.replace(b'', b'') is b)

Here is the call graph for this function:

Definition at line 1026 of file test_bytes.py.

01026 
01027     def test_rsplit_bytearray(self):
01028         self.assertEqual(b'a b'.rsplit(memoryview(b' ')), [b'a', b'b'])

Here is the call graph for this function:

Definition at line 1023 of file test_bytes.py.

01023 
01024     def test_split_bytearray(self):
01025         self.assertEqual(b'a b'.split(memoryview(b' ')), [b'a', b'b'])

Here is the call graph for this function:

Definition at line 984 of file test_bytes.py.

00984 
00985     def test_to_str(self):
00986         self.assertEqual(str(b''), "b''")
00987         self.assertEqual(str(b'x'), "b'x'")
00988         self.assertEqual(str(b'\x80'), "b'\\x80'")
00989         self.assertEqual(str(bytearray(b'')), "bytearray(b'')")
00990         self.assertEqual(str(bytearray(b'x')), "bytearray(b'x')")
00991         self.assertEqual(str(bytearray(b'\x80')), "bytearray(b'\\x80')")

Here is the call graph for this function:

Definition at line 1005 of file test_bytes.py.

01005 
01006     def test_translate(self):
01007         b = b'hello'
01008         ba = bytearray(b)
01009         rosetta = bytearray(range(0, 256))
01010         rosetta[ord('o')] = ord('e')
01011         c = b.translate(rosetta, b'l')
01012         self.assertEqual(b, b'hello')
01013         self.assertEqual(c, b'hee')
01014         c = ba.translate(rosetta, b'l')
01015         self.assertEqual(ba, b'hello')
01016         self.assertEqual(c, b'hee')
01017         c = b.translate(None, b'e')
01018         self.assertEqual(c, b'hllo')
01019         c = ba.translate(None, b'e')
01020         self.assertEqual(c, b'hllo')
01021         self.assertRaises(TypeError, b.translate, None, None)
01022         self.assertRaises(TypeError, ba.translate, None, None)

Here is the call graph for this function:


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