Skip to content

Commit

Permalink
Typo
Browse files Browse the repository at this point in the history
  • Loading branch information
kiendang committed Oct 24, 2023
1 parent a8e58d0 commit 6fded12
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/syft/src/syft/types/dicttuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def __init__(
if any(isinstance(k, SupportsIndex) for k in self.__mapping.keys()):
raise ValueError(
"values of `__keys` should not have type `int`, "
"or implements `__index__()`"
"or implement `__index__()`"
)

@overload
Expand Down
37 changes: 31 additions & 6 deletions packages/syft/tests/syft/types/dicttuple_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from collections.abc import Collection
from collections.abc import Iterable
from collections.abc import Mapping
from functools import cached_property
from itertools import chain
from itertools import combinations
from typing import Any
Expand Down Expand Up @@ -89,7 +90,6 @@ class Case(Generic[_KT, _VT]):
key_fn: Optional[Callable[[_VT], _KT]]
value_generator: Callable[[], Generator[_VT, Any, None]]
key_generator: Callable[[], Generator[_KT, Any, None]]
mapping: Mapping[_KT, _VT]

def __init__(
self,
Expand All @@ -114,19 +114,27 @@ def key_generator() -> Generator[_KT, Any, None]:
self.value_generator = value_generator
self.key_generator = key_generator

self.mapping = dict(zip(self.keys, self.values))

def kv(self) -> Iterable[tuple[_KT, _VT]]:
return zip(self.keys, self.values)

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

def constructor_args(self, mapping: bool = True) -> list[Callable[[], tuple]]:
return [
lambda: (self.values, self.keys),
lambda: (self.value_generator(), self.key_generator()),
lambda: (self.values, self.key_generator()),
lambda: (self.value_generator(), self.keys),
lambda: (self.mapping,),
lambda: (self.kv(),),
*(
[
lambda: (self.mapping,),
lambda: (self.kv(),),
]
if mapping
else []
),
*(
[
lambda: (self.values, self.key_fn),
Expand Down Expand Up @@ -207,3 +215,20 @@ def test_dicttuple_is_not_a_mapping(
def test_keys_should_not_be_int(args: Callable[[], tuple]) -> None:
with pytest.raises(ValueError, match="int"):
DictTuple(*args())


LENGTH_MISMACTH_TEST_CASES = [
Case(values=[1, 2, 3], keys=["x", "y"]),
Case(values=[1, 2], keys=["x", "y", "z"]),
]


@pytest.mark.parametrize(
"args",
chain.from_iterable(
c.constructor_args(mapping=False) for c in LENGTH_MISMACTH_TEST_CASES
),
)
def test_keys_and_values_should_have_same_length(args: Callable[[], tuple]) -> None:
with pytest.raises(ValueError, match="length"):
DictTuple(*args())

0 comments on commit 6fded12

Please sign in to comment.