コード例 #1
0
ファイル: test_msgpack_serde.py プロジェクト: thltsui/PySyft
def test_list_simplify(workers):
    """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."""

    me = workers["me"]
    input = ["hello", "world"]
    list_detail_code = msgpack.proto_type_info(list).code
    str_detail_code = msgpack.proto_type_info(str).code
    target = (list_detail_code, ((str_detail_code, (b"hello",)), (str_detail_code, (b"world",))))
    assert msgpack.serde._simplify(me, input) == target
コード例 #2
0
ファイル: test_msgpack_serde.py プロジェクト: thltsui/PySyft
def test_dict_simplify(workers):
    """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."""

    me = workers["me"]
    input = {"hello": "world"}
    detail_dict_code = msgpack.proto_type_info(dict).code
    detail_str_code = msgpack.proto_type_info(str).code
    target = (detail_dict_code, (((detail_str_code, (b"hello",)), (detail_str_code, (b"world",))),))
    assert msgpack.serde._simplify(me, input) == target
コード例 #3
0
ファイル: test_msgpack_serde.py プロジェクト: thltsui/PySyft
def test_set_simplify(workers):
    """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."""

    me = workers["me"]
    input = set(["hello", "world"])
    set_detail_code = msgpack.proto_type_info(set).code
    str_detail_code = msgpack.proto_type_info(str).code
    target = (set_detail_code, ((str_detail_code, (b"hello",)), (str_detail_code, (b"world",))))
    assert msgpack.serde._simplify(me, input)[0] == target[0]
    assert set(msgpack.serde._simplify(me, input)[1]) == set(target[1])
コード例 #4
0
ファイル: serde.py プロジェクト: zyedmaheen/PySyft
def _detail_field(typeCode, val):
    """
    This functions converts the field value 2**64 which was
    serialised as str to avoid msgpack overflow back to int
    after deserialisation.
    """
    if typeCode == msgpack.proto_type_info(str).code and val == str_field:
        return int(val)
    else:
        return val
コード例 #5
0
def test_string_simplify(workers):
    """This tests our ability to simplify string objects.

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

    me = workers["me"]
    input = "hello"
    target = (msgpack.proto_type_info(str).code, (b"hello", ))
    assert msgpack.serde._simplify(me, input) == target
コード例 #6
0
def test_range_simplify(workers):
    """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."""

    me = workers["me"]
    input = range(1, 3, 4)
    target = (msgpack.proto_type_info(range).code, (1, 3, 4))
    assert msgpack.serde._simplify(me, input) == target