Пример #1
0
def test_dict_simplify():
    """This tests our ability to simplify dict objects.

    This test is pretty simple since dicts just serialize to
    themselves, with a tuple wrapper with the correct ID
    for dicts so that the detailer knows how to interpret it."""

    input = {"hello": "world"}
    detail_dict_code = serde.proto_type_info(dict).code
    detail_str_code = serde.proto_type_info(str).code
    target = (detail_dict_code, (((detail_str_code, (b"hello",)), (detail_str_code, (b"world",))),))
    assert serde._simplify(input) == target
Пример #2
0
def test_list_simplify():
    """This tests our ability to simplify list types.

    This test is pretty simple since lists just serialize to
    themselves, with a tuple wrapper with the correct ID (2)
    for lists so that the detailer knows how to interpret it."""

    input = ["hello", "world"]
    list_detail_code = serde.proto_type_info(list).code
    str_detail_code = serde.proto_type_info(str).code
    target = (list_detail_code, ((str_detail_code, (b"hello",)), (str_detail_code, (b"world",))))
    assert serde._simplify(input) == target
Пример #3
0
def test_tuple_simplify(workers):
    """This tests our ability to simplify tuple types.

    This test is pretty simple since tuples just serialize to
    themselves, with a tuple wrapper with the correct ID (1)
    for tuples so that the detailer knows how to interpret it."""

    me = workers["me"]
    input = ("hello", "world")
    tuple_detail_code = serde.proto_type_info(tuple).code
    str_detail_code = serde.proto_type_info(str).code
    target = (tuple_detail_code, ((str_detail_code, (b"hello",)), (str_detail_code, (b"world",))))
    assert serde._simplify(me, input) == target
Пример #4
0
def test_set_simplify():
    """This tests our ability to simplify set objects.

    This test is pretty simple since sets just serialize to
    lists, with a tuple wrapper with the correct ID (3)
    for sets so that the detailer knows how to interpret it."""

    input = set(["hello", "world"])
    set_detail_code = serde.proto_type_info(set).code
    str_detail_code = serde.proto_type_info(str).code
    target = (set_detail_code, ((str_detail_code, (b"hello",)), (str_detail_code, (b"world",))))
    assert serde._simplify(input)[0] == target[0]
    assert set(serde._simplify(input)[1]) == set(target[1])
Пример #5
0
def test_string_simplify():
    """This tests our ability to simplify string objects.

    This test is pretty simple since strings just serialize to
    themselves, with no tuple/id necessary."""

    input = "hello"
    target = (serde.proto_type_info(str).code, (b"hello",))
    assert serde._simplify(input) == target
Пример #6
0
def test_range_simplify():
    """This tests our ability to simplify range objects.

    This test is pretty simple since range objs just serialize to
    themselves, with a tuple wrapper with the correct ID (5)
    for dicts so that the detailer knows how to interpret it."""

    input = range(1, 3, 4)
    target = (serde.proto_type_info(range).code, (1, 3, 4))
    assert serde._simplify(input) == target