コード例 #1
0
def test_dict_creation() -> None:
    d1 = {String("t1"): 1, String("t2"): 2}
    dict1 = Dict(d1)
    assert type(getattr(dict1, "id", None)) is UID

    d2 = dict({"t1": 1, "t2": 2})
    dict2 = Dict(d2)
    dict2._id = UID()
    assert type(getattr(dict2, "id", None)) is UID

    d3 = UserDict({"t1": 1, "t2": 2})
    dict3 = Dict(**d3)
    assert type(getattr(dict3, "id", None)) is UID

    assert dict1.keys() == dict2.keys()
    assert dict1.keys() == dict3.keys()

    # ValuesView uses object.__eq__
    # https://stackoverflow.com/questions/34312674/why-are-the-values-of-an-ordereddict-not-equal
    assert dict1.values() != dict2.values()
    assert dict1.values() != dict3.values()

    assert dict1.items() == dict2.items()
    assert dict1.items() == dict3.items()

    it = list(iter(dict2.values()))
    assert len(it) == 2
    assert type(it) is list
コード例 #2
0
def send_get_string_local(data: str, duet: sy.VirtualMachine) -> None:
    syft_string = String(data)

    ptr = syft_string.send(duet, pointable=True)
    remote_data = ptr.get()

    assert data == remote_data
コード例 #3
0
def test_string_serde() -> None:
    syft_string = String("Hello OpenMined")

    serialized = syft_string._object2proto()

    assert isinstance(serialized, String_PB)

    deserialized = String._proto2object(proto=serialized)

    assert isinstance(deserialized, String)
    assert deserialized.id == syft_string.id
コード例 #4
0
def test_string_send() -> None:
    alice = syft.VirtualMachine(name="alice")
    alice_client = alice.get_client()

    syft_string = String("Hello OpenMined!")
    ptr = syft_string.send(alice_client)

    # Check pointer type
    assert ptr.__class__.__name__ == "StringPointer"

    # Check that we can get back the object
    res = ptr.get()
    assert res == syft_string
コード例 #5
0
def test_list_send(client: sy.VirtualMachineClient) -> None:
    syft_list = Dict({
        String("t1"): String("test"),
        String("t2"): String("test")
    })
    ptr = syft_list.send(client)
    # Check pointer type
    assert ptr.__class__.__name__ == "DictPointer"

    # Check that we can get back the object
    res = ptr.get()
    for res_el, original_el in zip(res, syft_list):
        assert res_el == original_el
コード例 #6
0
def test_dict_creation() -> None:
    d1 = {String("t1"): 1, String("t2"): 2}
    dict1 = Dict(d1)
    assert type(getattr(dict1, "id", None)) is UID

    d2 = dict({"t1": 1, "t2": 2})
    dict2 = Dict(d2)
    dict2._id = UID()
    assert type(getattr(dict2, "id", None)) is UID

    d3 = UserDict({"t1": 1, "t2": 2})
    dict3 = Dict(**d3)
    assert type(getattr(dict3, "id", None)) is UID

    assert dict1.keys() == dict2.keys()
    assert dict1.keys() == dict3.keys()
コード例 #7
0
ファイル: dict_test.py プロジェクト: znreza/PySyft
    def test_dictitems_contains_use_after_free(self):
        class X:
            def __eq__(self, other):
                d.clear()
                return NotImplemented

        d = Dict({0: String("test")})  # TODO: we should be able to support set
        (0, X()) in d.items()
コード例 #8
0
ファイル: slice_test.py プロジェクト: yashlamba/PySyft
def test_slice_types() -> None:
    py_string = "Python"
    py_list = ["P", "y", "t", "h", "o", "n"]
    py_tuple = ("P", "y", "t", "h", "o", "n")

    sy_string = String(py_string)
    sy_tuple = Tuple(py_tuple)
    sy_list = List(py_list)

    py_slice1 = slice(1)
    sy_slice1 = Slice(1)

    assert py_slice1.start == sy_slice1.start
    assert py_slice1.stop == sy_slice1.stop
    assert py_slice1.step == sy_slice1.step

    assert py_slice1 == sy_slice1

    py_slice2 = slice(1, 2)
    sy_slice2 = Slice(1, 2)

    assert py_slice2 == sy_slice2

    assert py_slice2.start == sy_slice2.start
    assert py_slice2.stop == sy_slice2.stop
    assert py_slice2.step == sy_slice2.step

    py_slice3 = slice(1, 2, -1)
    sy_slice3 = Slice(1, 2, -1)

    assert py_slice3 == sy_slice3

    assert py_slice3.start == sy_slice3.start
    assert py_slice3.stop == sy_slice3.stop
    assert py_slice3.step == sy_slice3.step

    assert sy_string[sy_slice1] == py_string[py_slice1]
    assert sy_string[sy_slice2] == py_string[py_slice2]
    assert sy_string[sy_slice3] == py_string[py_slice3]

    assert sy_tuple[sy_slice1] == py_tuple[py_slice1]
    assert sy_tuple[sy_slice2] == py_tuple[py_slice2]
    assert sy_tuple[sy_slice3] == py_tuple[py_slice3]

    assert sy_list[sy_slice1] == py_list[py_slice1]
    assert sy_list[sy_slice2] == py_list[py_slice2]
    assert sy_list[sy_slice3] == py_list[py_slice3]

    assert sy_list[py_slice3] == py_list[py_slice3]
コード例 #9
0
ファイル: bool_test.py プロジェクト: yashlamba/PySyft
def test_sane_len():
    # this test just tests our assumptions about __len__
    # this will start failing if __len__ changes assertions
    for badval in [String("illegal"), Int(-1), Int(1 << 32)]:

        class A:
            def __len__(self):
                return badval

        try:
            Bool(A())
        except (Exception) as e_bool:
            try:
                len(A())
            except (Exception) as e_len:
                assert str(e_bool) == str(e_len)
コード例 #10
0
def test_id_concat_syft_type() -> None:
    val = String(" 2020")

    result = STRING_SYFT + val

    assert result.id
    assert result.id != STRING_SYFT.id
    assert val.id != result.id
    assert result == STRING_PYTHON + val

    result = val + STRING_SYFT

    assert result.id
    assert result.id != STRING_SYFT.id
    assert val.id != result.id
    assert val + STRING_PYTHON == result
コード例 #11
0
def send_get_string_multiprocess(data: String, port: int) -> None:
    run_endpoints(do_send, ds_get, String(data), port)
コード例 #12
0
ファイル: bool_test.py プロジェクト: yashlamba/PySyft
def test_string():
    assert String("xyz").endswith("z") == SyTrue
    assert String("xyz").endswith("x") == SyFalse
    assert String("xyz0123").isalnum() == SyTrue
    assert String("@#$%").isalnum() == SyFalse
    assert String("xyz").isalpha() == SyTrue
    assert String("@#$%").isalpha() == SyFalse
    assert String("0123").isdigit() == SyTrue
    assert String("xyz").isdigit() == SyFalse
    assert String("xyz").islower() == SyTrue
    assert String("XYZ").islower() == SyFalse
    assert String("0123").isdecimal() == SyTrue
    assert String("xyz").isdecimal() == SyFalse
    assert String("0123").isnumeric() == SyTrue
    assert String("xyz").isnumeric() == SyFalse
    assert String(" ").isspace() == SyTrue
    assert String("\xa0").isspace() == SyTrue
    assert String("\u3000").isspace() == SyTrue
    assert String("XYZ").isspace() == SyFalse
    assert String("X").istitle() == SyTrue
    assert String("x").istitle() == SyFalse
    assert String("XYZ").isupper() == SyTrue
    assert String("xyz").isupper() == SyFalse
    assert String("xyz").startswith("x") == SyTrue
    assert String("xyz").startswith("z") == SyFalse
コード例 #13
0
ファイル: bool_test.py プロジェクト: yashlamba/PySyft
def test_repr() -> None:
    assert repr(SyFalse) == String("False")
    assert repr(SyTrue) == String("True")
    assert eval(repr(SyFalse)) == SyFalse
    assert eval(repr(SyTrue)) == SyTrue
コード例 #14
0
ファイル: bool_test.py プロジェクト: yashlamba/PySyft
def test_format() -> None:
    assert String("%d") % SyFalse == "0"
    assert String("%d") % SyTrue == "1"
    assert String("%x") % SyFalse == "0"
    assert String("%x") % SyTrue == "1"
コード例 #15
0
def string_serde(data: str) -> None:
    syft_string = String(data)

    serialized = syft_string._object2proto()
    String._proto2object(proto=serialized)
コード例 #16
0
ファイル: bool_test.py プロジェクト: yashlamba/PySyft
def test_str() -> None:
    assert str(SyFalse) == String("False")
    assert str(SyTrue) == String("True")
コード例 #17
0
# syft absolute
from syft.lib.python.string import String

STRING_PYTHON = "Hello OpenMined"
STRING_SYFT = String(STRING_PYTHON)


def test_id_concat_python_type() -> None:
    val = " 2020"

    result = STRING_SYFT + val

    assert result.id
    assert result.id != STRING_SYFT.id
    assert result == STRING_PYTHON + val

    result = val + STRING_SYFT

    assert result.id
    assert result.id != STRING_SYFT.id
    assert val + STRING_PYTHON == result


def test_id_concat_syft_type() -> None:
    val = String(" 2020")

    result = STRING_SYFT + val

    assert result.id
    assert result.id != STRING_SYFT.id
    assert val.id != result.id