def test_extra_array_elements(): data = [ 14, 255, 135, 1, 1, 2, 255, 136, 0, 1, 4, 1, 2, 0, 0, 5, 255, 136, 0, 7, 34 ] with pytest.raises(AssertionError) as excinfo: pygob.load(bytes(data)) excinfo.match('expected 1 elements, found 7')
def test_user_struct(): data = [ 34, 255, 129, 3, 1, 1, 4, 85, 115, 101, 114, 1, 255, 130, 0, 1, 2, 1, 2, 73, 100, 1, 4, 0, 1, 4, 78, 97, 109, 101, 1, 12, 0, 0, 0, 14, 255, 130, 1, 2, 1, 7, 101, 121, 111, 116, 97, 110, 103, 0 ] User = collections.namedtuple('User', ['Id', 'Name']) assert pygob.load(bytes(data)) == User(1, b'eyotang')
def test_point_struct(): data = [ 31, 255, 147, 3, 1, 1, 5, 80, 111, 105, 110, 116, 1, 255, 148, 0, 1, 2, 1, 1, 88, 1, 4, 0, 1, 1, 89, 1, 4, 0, 0, 0, 7, 255, 148, 1, 34, 1, 84, 0 ] Point = collections.namedtuple('Point', ['X', 'Y']) assert pygob.load(bytes(data)) == Point(17, 42)
def test_int_matrix(): data = [ 15, 255, 141, 1, 1, 2, 255, 142, 0, 1, 255, 140, 1, 6, 0, 0, 14, 255, 139, 1, 1, 2, 255, 140, 0, 1, 4, 1, 6, 0, 0, 16, 255, 142, 0, 3, 3, 0, 2, 4, 3, 6, 8, 10, 3, 12, 14, 16 ] expected = ((0, 1, 2), (3, 4, 5), (6, 7, 8)) assert pygob.load(bytes(data)) == expected
def test_a_recursive_struct(): data = [ 49, 255, 129, 3, 1, 1, 4, 78, 111, 100, 101, 1, 255, 130, 0, 1, 3, 1, 5, 86, 97, 108, 117, 101, 1, 4, 0, 1, 4, 76, 101, 102, 116, 1, 255, 130, 0, 1, 5, 82, 105, 103, 104, 116, 1, 255, 130, 0, 0, 0, 9, 255, 130, 1, 2, 1, 1, 4, 0, 0 ] Node = collections.namedtuple('Node', ['Value', 'Left', 'Right']) assert pygob.load(bytes(data)) == Node(1, Node(2, None, None), None)
def test_person_struct(): data = [ 50, 255, 149, 3, 1, 1, 6, 80, 101, 114, 115, 111, 110, 1, 255, 150, 0, 1, 3, 1, 4, 78, 97, 109, 101, 1, 12, 0, 1, 3, 65, 103, 101, 1, 4, 0, 1, 7, 65, 100, 100, 114, 101, 115, 115, 1, 255, 152, 0, 0, 0, 48, 255, 151, 3, 1, 1, 7, 65, 100, 100, 114, 101, 115, 115, 1, 255, 152, 0, 1, 2, 1, 6, 83, 116, 114, 101, 101, 116, 1, 12, 0, 1, 11, 72, 111, 117, 115, 101, 78, 117, 109, 98, 101, 114, 1, 4, 0, 0, 0, 25, 255, 150, 1, 5, 65, 108, 105, 99, 101, 1, 70, 1, 1, 7, 77, 97, 105, 110, 32, 83, 116, 1, 34, 0, 0 ] Person = collections.namedtuple('Person', ['Name', 'Age', 'Address']) Address = collections.namedtuple('Address', ['Street', 'HouseNumber']) assert pygob.load(bytes(data)) == Person(b'Alice', 35, Address(b'Main St', 17))
def test_complex(data, expected): assert pygob.load(bytes(data)) == expected
def test_string(data, expected): result = pygob.load(bytes(data)) assert type(result) == bytes assert result == expected
def test_byte_slice(data, expected): result = pygob.load(bytes(data)) assert type(result) == bytearray assert result == expected
def test_float_nan(): data = [11, 8, 0, 248, 1, 0, 0, 0, 0, 0, 248, 127] result = pygob.load(bytes(data)) assert math.isnan(result)
def test_float(data, expected): assert pygob.load(bytes(data)) == expected
def test_int_bool_map(data, expected): assert pygob.load(bytes(data)) == expected
def test_bool_array(data, expected): assert pygob.load(bytes(data)) == expected