Skip to content

Commit

Permalink
Returns test coverage to 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
56kyle committed Aug 31, 2023
1 parent a2e757b commit b44dde9
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 8 deletions.
71 changes: 63 additions & 8 deletions tests/unit_tests/test_parametric.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,75 @@ def test__get_parameter_combinations(
)

@pytest.mark.parametrize(
argnames=["primary_type"], argvalues=[(dict,)], indirect=True
argnames=["primary_type"],
argvalues=[
(type,),
],
indirect=True,
)
def test__instantiate_each_parameter_combination_with_builtin(
self, expanded_type: ExpandedType
) -> None:
expanded_type._instantiate_each_parameter_combination(
parameter_combinations=[("foo", {"a": "b"})]
)
with pytest.raises(ValueError):
expanded_type._instantiate_each_parameter_combination(
parameter_combinations=[("foo", "bar")]
)

def test__instantiate_from_signature(self) -> None:
pass
@pytest.mark.parametrize(
argnames=["primary_type", "type_args", "combinations", "expected"],
argvalues=[
(lambda: None, tuple(), tuple(), tuple()),
(list, (int,), ((1, 2),), ([1, 2],)),
(
lambda a, b, c: [a, b, c],
(bool, bool, bool),
((True, False, True),),
([True, False, True],),
),
],
ids=["no_parameters_sig", "one_parameter_sig", "many_parameters_sig"],
indirect=["primary_type", "type_args"],
)
def test__instantiate_from_signature(
self,
expanded_type: ExpandedType[T],
combinations: List[Tuple[Any, ...]],
expected: Tuple[T, ...],
) -> None:
assert (
expanded_type._instantiate_from_signature(
parameter_combinations=combinations
)
== expected
)

def test__instantiate_from_trial_and_error(self) -> None:
pass
@pytest.mark.parametrize(
argnames=["primary_type", "type_args", "combinations", "expected"],
argvalues=[
(lambda: None, tuple(), tuple(), tuple()),
(list, (int,), ((1, 2),), ([1, 2],)),
(
lambda a, b, c: [a, b, c],
(bool, bool, bool),
((True, False, True),),
([True, False, True],),
),
],
ids=["no_parameters_sig", "one_parameter_sig", "many_parameters_sig"],
indirect=["primary_type", "type_args"],
)
def test__instantiate_from_trial_and_error(
self,
expanded_type: ExpandedType[T],
combinations: List[Tuple[Any, ...]],
expected: Tuple[T, ...],
) -> None:
assert (
expanded_type._instantiate_from_trial_and_error(
parameter_combinations=combinations
)
== expected
)

def test__instantiate_combinations_using_expanded(self) -> None:
pass
Expand Down
66 changes: 66 additions & 0 deletions tests/unit_tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,72 @@ def test_func({signature}) -> None:
)


def test_parametrize_types_with_unequal_names_and_types(
pytester: pytest.Pytester, conftest: Path
) -> None:
test_path: Path = pytester.makepyfile(
"""
import pytest
import typing
from typing import *
@pytest.mark.parametrize_types(
argnames=["a", "b"],
argtypes=[int, float, str],
)
def test_func(a, b) -> None:
assert a
assert b
"""
)
result: pytest.RunResult = pytester.runpytest(test_path)
result.assert_outcomes(errors=1)


def test_parametrize_types_with_no_ids_provided(
pytester: pytest.Pytester, conftest: Path
) -> None:
test_path: Path = pytester.makepyfile(
"""
import pytest
import typing
from typing import *
@pytest.mark.parametrize_types(
argnames=["a", "b"],
argtypes=[bool, bool],
)
def test_func(a, b) -> None:
assert a is not None
assert b is not None
"""
)
result: pytest.RunResult = pytester.runpytest(test_path)
result.assert_outcomes(passed=4)


def test_parametrize_types_with_argnames_as_string(
pytester: pytest.Pytester, conftest: Path
) -> None:
test_path: Path = pytester.makepyfile(
"""
import pytest
import typing
from typing import *
@pytest.mark.parametrize_types(
argnames="a, b",
argtypes=[bool, bool],
)
def test_func(a, b) -> None:
assert a is not None
assert b is not None
"""
)
result: pytest.RunResult = pytester.runpytest(test_path)
result.assert_outcomes(passed=4)


@pytest.mark.parametrize(
argnames=["argtypes", "expected"],
argvalues=[
Expand Down

0 comments on commit b44dde9

Please sign in to comment.