示例#1
0
def test_bytes():
    bs = T.Bytes([1, 2, 3])
    assert bs.bin() == ['00000001', '00000010', '00000011']
    assert bs.hex() == ['01', '02', '03']
    bs = T.Bytes([32, 97])
    assert bs.bin() == ['00100000', '01100001']
    assert bs.hex() == ['20', '61']
示例#2
0
def test_append_ints():
    bs = T.Bytes()
    assert bs.bs == []
    res = bs.append([1, 2])
    assert res is bs
    assert bs.bs == [1, 2]
    bs.append([3, 4]).append([5, 6])
    assert bs.bs == [1, 2, 3, 4, 5, 6]
示例#3
0
def test_append_bytes():
    bs = T.Bytes()
    assert bs.bs == []
    res = bs.append([' ', 'Z'])
    assert res is bs
    assert bs.bs == [ord(' '), ord('Z')]
示例#4
0
def test_bytes_init_intsmalllist():
    assert T.Bytes([1, 2]).bs == [1, 2]
示例#5
0
def test_bytes_init_intlargelist():
    # TODO: this doesn't really make sense, so shouldn't be allowed
    assert T.Bytes([257, 261]).bs == [1, 1, 1, 5]
示例#6
0
def test_bytes_init_intlarge():
    assert T.Bytes(2**8 + 2**7).bs == [1, 2**7]
示例#7
0
def test_bytes_init_intsmall():
    assert T.Bytes(42).bs == [42]
示例#8
0
def test_bytes_init_bytelist():
    assert T.Bytes([' ', 'z']).bs == map(ord, ' z')
示例#9
0
def test_bytes_init_byte():
    assert T.Bytes('Z').bs == [ord('Z')]
示例#10
0
def test_bytes_init():
    assert T.Bytes().bs == []