Skip to content

Commit

Permalink
Appeases the majority of mypy. Prepping to use ParamSpec in ExpandedType
Browse files Browse the repository at this point in the history
  • Loading branch information
56kyle committed Aug 31, 2023
1 parent b44dde9 commit 757bebf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/pytest_static/parametric.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ def parametrize_types(
instance_sets: List[List[T]] = [
list(get_all_possible_type_instances(t)) for t in argtypes
]
instance_combinations: List[List[T]] = list(itertools.product(*instance_sets))
instance_combinations: List[Iterable[itertools.product[Tuple[Any, ...]]]] = list(
itertools.product(*instance_sets)
)

if ids is None:
ids = [", ".join(map(repr, ic)) for ic in instance_combinations]
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def expanded_type(


@pytest.fixture(scope="function")
def primary_type(request: FixtureRequest) -> Type[T]:
def primary_type(request: FixtureRequest) -> Type[Any]:
return getattr(request, "param", List)


Expand Down
18 changes: 10 additions & 8 deletions tests/unit_tests/test_parametric.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,18 @@ def test_get_instances_with_multiple_nested(self, monkeypatch: MonkeyPatch) -> N
def test__get_parameter_instance_sets(
self,
primary_type: Type[T],
type_args: Type[T],
type_args: Tuple[Union[Any, ExpandedType[Any]], ...],
expected_sets: Tuple[Set[Any], ...],
) -> None:
expected_sets = [tuple(expected_set) for expected_set in expected_sets]
expected: List[Tuple[Any, ...]] = [
tuple(iter(expected_set)) for expected_set in expected_sets
]
assert (
ExpandedType(
primary_type=primary_type,
type_args=type_args,
)._get_parameter_instance_sets()
== expected_sets
== expected
)

@pytest.mark.parametrize(
Expand Down Expand Up @@ -128,7 +130,7 @@ def test__get_parameter_combinations(
indirect=True,
)
def test__instantiate_each_parameter_combination_with_builtin(
self, expanded_type: ExpandedType
self, expanded_type: ExpandedType[Any]
) -> None:
with pytest.raises(ValueError):
expanded_type._instantiate_each_parameter_combination(
Expand Down Expand Up @@ -203,8 +205,8 @@ def test__instantiate_expanded(self) -> None:
@pytest.mark.parametrize(
argnames=["primary_type", "type_args", "combination"],
argvalues=[
(list, (int,), (1,)),
(list, (int,), (1, 2)),
(list, (int,), (1, 2, 3)),
(list, (int, str), (1, "2", 3)),
],
ids=[
"single_type_arg",
Expand All @@ -214,11 +216,11 @@ def test__instantiate_expanded(self) -> None:
)
def test__instantiate_not_expanded(
self,
expanded_type: ExpandedType,
expanded_type: ExpandedType[List[Any]],
combination: Tuple[Any, ...],
) -> None:
assert expanded_type._instantiate_not_expanded(
combination
combination=combination
) == expanded_type.primary_type(combination)


Expand Down

0 comments on commit 757bebf

Please sign in to comment.