def test_without_types():
    obj = from_bytes(
        PointWithoutTypes,
        b"\x01\x00\x02\x00\x00\x00\x05\xff\xff\xff\xff\xff\xff\xff\xff\x01\xff\xff\x00\x00\x00\x05\xff\xff\xff\xff\xff\xff\xff\xff",
    )
    assert obj == PointWithoutTypes(1, 2, 5, 18446744073709551615, 1, -1, 5,
                                    -1)
Exemple #2
0
def test_variable_array():
    obj = from_bytes(PolyLine, b"\x05\x01\x01\x02\x02\x03\x03\x04\x04\x05\x05")
    assert type(obj) == PolyLine
    assert type(obj.num_points) == Uint8 and obj.num_points == 5
    assert type(obj.points) == list and len(obj.points) == 5
    assert obj.points == [
        Point(1, 1),
        Point(2, 2),
        Point(3, 3),
        Point(4, 4),
        Point(5, 5),
    ]
Exemple #3
0
def test_bytes():
    obj = from_bytes(OctetPacket, b"\x01\x02\x05")
    assert type(obj) == OctetPacket
    assert type(obj.x) == Uint8 and obj.x == 1
    assert obj.y == bytes((2, 5))
def test_nested_class():
    obj = from_bytes(BoundingBox, b"\x01\x02\x05\x04")
    assert type(obj) == BoundingBox
    assert type(obj.corner_a) == Point and obj.corner_a == Point(1, 2)
    assert type(obj.corner_b) == Point and obj.corner_b == Point(5, 4)
Exemple #5
0
def test_fixed_array():
    obj = from_bytes(PolyLine, b"\x03\x01\x01\x02\x02\x03\x03")
    assert type(obj) == PolyLine
    assert type(obj.points) == list and len(obj.points) == 3
    assert obj.points == [Point(1, 1), Point(2, 2), Point(3, 3)]
def test_enum():
    obj = from_bytes(Cheeseshop, b"\x22")
    assert (type(obj.last_requested_out_of_stock_item) == Cheese
            and obj.last_requested_out_of_stock_item == Cheese.GORGONZOLA)
Exemple #7
0
def test_basic():
    obj = from_bytes(Point, b"\x01\x02")
    assert obj == Point(1, 2)
    assert type(obj.x) == Uint8
    assert type(obj.y) == Uint8
Exemple #8
0
def test_toolittle64():
    with raises(ValueError):
        obj = from_bytes(BigPoint, b"\x03" * 10)
Exemple #9
0
def test_toomuch64():
    with raises(ValueError):
        obj = from_bytes(BigPoint, b"\xff" * 20)
Exemple #10
0
def test_toolittle():
    with raises(ValueError):
        obj = from_bytes(Point, b"\x03")
Exemple #11
0
def test_toomuch():
    with raises(ValueError):
        obj = from_bytes(Point, b"\x05\x01\x01")