Skip to content

Commit

Permalink
cleans up typing and sacrifices a goat for our mypy overlords
Browse files Browse the repository at this point in the history
  • Loading branch information
56kyle committed Aug 31, 2023
1 parent 757bebf commit f55b650
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/pytest_static/parametric.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,14 @@ def _instantiate_combinations_using_not_expanded(
def _instantiate_expanded(self, combination: Tuple[Any, ...]) -> T:
"""Returns an instance of the primary_type using the combination provided."""
if self.primary_type is dict:
return self.primary_type([combination])
instantiation_method: Callable[..., T] = self.primary_type
return instantiation_method([combination])
return self.primary_type(*combination)

def _instantiate_not_expanded(self, combination: Tuple[Any, ...]) -> T:
"""Returns an instance of the primary_type using the combination provided."""
return self.primary_type(combination)
instantiation_method: Callable[..., T] = self.primary_type
return instantiation_method(combination)


@dataclass(frozen=True)
Expand Down
21 changes: 16 additions & 5 deletions tests/unit_tests/test_parametric.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
import pytest
from _pytest.monkeypatch import MonkeyPatch

from pytest_static import type_sets
from pytest_static.parametric import Config
from pytest_static.parametric import ExpandedType
from pytest_static.parametric import expand_type
from pytest_static.type_sets import PREDEFINED_TYPE_SETS


T = TypeVar("T")
T = TypeVar("T", bound=Any)


class DummyClass:
Expand All @@ -42,8 +43,13 @@ def test_get_instances_with_nested(self) -> None:
)

def test_get_instances_with_multiple(self, monkeypatch: MonkeyPatch) -> None:
monkeypatch.setitem(PREDEFINED_TYPE_SETS, int, {1, 2})
monkeypatch.setitem(PREDEFINED_TYPE_SETS, str, {"a", "b"})
new_predefined_type_sets: Dict[Type[Any], Set[Any]] = {
**PREDEFINED_TYPE_SETS,
int: {1, 2},
str: {"a", "b"},
}
monkeypatch.setattr(type_sets, "PREDEFINED_TYPE_SETS", new_predefined_type_sets)

expected_instances: Tuple[List[Union[int, str]], ...] = (
[1, "a"],
[1, "b"],
Expand All @@ -56,8 +62,13 @@ def test_get_instances_with_multiple(self, monkeypatch: MonkeyPatch) -> None:
assert instance in expanded_instances

def test_get_instances_with_multiple_nested(self, monkeypatch: MonkeyPatch) -> None:
monkeypatch.setitem(PREDEFINED_TYPE_SETS, int, {1, 2})
monkeypatch.setitem(PREDEFINED_TYPE_SETS, str, {"a", "b"})
new_predefined_type_sets: Dict[Type[Any], Set[Any]] = {
**PREDEFINED_TYPE_SETS,
int: {1, 2},
str: {"a", "b"},
}
monkeypatch.setattr(type_sets, "PREDEFINED_TYPE_SETS", new_predefined_type_sets)

expected_instances: Tuple[List[Union[List[int], str]], ...] = (
[[1], "a"],
[[1], "b"],
Expand Down

0 comments on commit f55b650

Please sign in to comment.