Skip to content

Commit

Permalink
Add tests for converting to dict
Browse files Browse the repository at this point in the history
  • Loading branch information
kiendang committed Oct 24, 2023
1 parent 86c6077 commit be2ee1a
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/syft/tests/syft/types/dicttuple_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ def test_keys(dict_tuple) -> None:


@pytest.mark.parametrize("dict_tuple", SIMPLE_TEST_CASES)
def test_get_mapping(dict_tuple: DictTuple) -> None:
def test_convert_to_dict(dict_tuple: DictTuple) -> None:
assert dict(dict_tuple) == {"x": 1, "y": 2}


@pytest.mark.parametrize("dict_tuple", SIMPLE_TEST_CASES)
def test_convert_items_to_dicttest_get_mapping(dict_tuple: DictTuple) -> None:
assert dict(dict_tuple.items()) == {"x": 1, "y": 2}


Expand Down Expand Up @@ -118,7 +123,7 @@ def kv(self) -> Iterable[tuple[_KT, _VT]]:
return zip(self.keys, self.values)

@cached_property
def mapping(self) -> Mapping[_KT, _VT]:
def mapping(self) -> dict[_KT, _VT]:
return dict(self.kv())

def constructor_args(self, mapping: bool = True) -> list[Callable[[], tuple]]:
Expand Down Expand Up @@ -203,14 +208,17 @@ def test_convert_to_other_iterable_types(
def test_keys(self, dict_tuple: DictTuple, case: Case) -> None:
assert list(dict_tuple.keys()) == list(case.keys)

def test_get_mapping(self, dict_tuple: DictTuple, case: Case) -> None:
assert dict(dict_tuple.items()) == dict(case.mapping)

def test_dicttuple_is_not_a_mapping(
self, dict_tuple: DictTuple, case: Case
) -> None:
assert not isinstance(dict_tuple, Mapping)

def test_convert_to_dict(self, dict_tuple: DictTuple, case: Case) -> None:
assert dict(dict_tuple) == case.mapping

def test_convert_items_to_dict(self, dict_tuple: DictTuple, case: Case) -> None:
assert dict(dict_tuple.items()) == case.mapping


@pytest.mark.parametrize(
"args", Case(values=["z", "b"], keys=[1, 2]).constructor_args()
Expand Down

0 comments on commit be2ee1a

Please sign in to comment.