def test_single_and_double_with_struct(value, only_double): # Float and double must match the behavior of the built-in struct module if not only_double: assert t.Single(value).serialize() == struct.pack("<f", value) v1, r1 = t.Single.deserialize(struct.pack("<f", value)) assert compare_with_nan(v1, t.Single(value)) assert r1 == b"" assert t.Double(value).serialize() == struct.pack("<d", value) v2, r2 = t.Double.deserialize(struct.pack("<d", value)) assert compare_with_nan(v2, t.Double(value)) assert r2 == b""
def test_single(): value = 1.25 extra = b"ab12!" v = t.Single(value) ser = v.serialize() assert t.Single.deserialize(ser) == (value, b"") assert t.Single.deserialize(ser + extra) == (value, extra) with pytest.raises(ValueError): t.Double.deserialize(ser[1:])
def test_single(): v = t.Single(1.25) ser = v.serialize() assert t.Single.deserialize(ser) == (1.25, b'')