Example #1
0
    def test_bytestr_uncode_encode(self):
        hello = 'Привет'
        self.assertEqual(bytestr_encode(hello, encoding='utf-8'), 
            int_to_byte(len(hello.encode('utf-8'))) + hello.encode('utf-8'))

        long_hello = hello * 100
        self.assertEqual(bytestr_encode(long_hello, encoding='utf-8'), 
            uint_encode(len(long_hello.encode('utf-8')), n=7) + long_hello.encode('utf-8'))
Example #2
0
    def test_bytestr_uncode_encode(self):
        hello = 'Привет'
        self.assertEqual(
            bytestr_encode(hello, encoding='utf-8'),
            int_to_byte(len(hello.encode('utf-8'))) + hello.encode('utf-8'))

        long_hello = hello * 100
        self.assertEqual(
            bytestr_encode(long_hello, encoding='utf-8'),
            uint_encode(len(long_hello.encode('utf-8')), n=7) +
            long_hello.encode('utf-8'))
Example #3
0
    def test_byte_int_convertions(self):
        self.assertTrue(int_to_byte(0) == b'\x00')
        self.assertTrue(int_to_byte(16) == b'\x10')
        self.assertTrue(int_to_byte(33) == b'\x21')

        self.assertEqual(byte_to_int(int_to_byte(0)), 0)
        self.assertEqual(byte_to_int(int_to_byte(16)), 16)
        self.assertEqual(byte_to_int(int_to_byte(33)), 33)

        self.assertEqual(int_to_bytes(0, n=3), b'\x00\x00\x00')
        self.assertEqual(int_to_bytes(256, n=3), b'\x00\x01\x00')
        self.assertEqual(int_to_bytes(256, n=1), b'\x00')
        self.assertEqual(int_to_bytes(95000, n=3), b'\x01\x73\x18')