style and typing fixes in tests

This commit is contained in:
Jan Petykiewicz 2020-10-17 17:48:58 -07:00
parent bc428f5e8e
commit db23cc1d6f
5 changed files with 35 additions and 26 deletions

View File

@ -3,34 +3,38 @@
Test fixtures Test fixtures
""" """
from typing import Tuple, Iterable, List from typing import Tuple, Iterable, List, Any
import numpy # type: ignore import numpy # type: ignore
import pytest # type: ignore import pytest # type: ignore
from .utils import PRNG from .utils import PRNG
FixtureRequest = Any
@pytest.fixture(scope='module', @pytest.fixture(scope='module',
params=[(5, 5, 1), params=[(5, 5, 1),
(5, 1, 5), (5, 1, 5),
(5, 5, 5), (5, 5, 5),
# (7, 7, 7), # (7, 7, 7),
]) ])
def shape(request: pytest.FixtureRequest) -> Iterable[Tuple[int, ...]]: def shape(request: FixtureRequest) -> Iterable[Tuple[int, ...]]:
yield (3, *request.param) yield (3, *request.param)
@pytest.fixture(scope='module', params=[1.0, 1.5]) @pytest.fixture(scope='module', params=[1.0, 1.5])
def epsilon_bg(request: pytest.FixtureRequest) -> Iterable[float]: def epsilon_bg(request: FixtureRequest) -> Iterable[float]:
yield request.param yield request.param
@pytest.fixture(scope='module', params=[1.0, 2.5]) @pytest.fixture(scope='module', params=[1.0, 2.5])
def epsilon_fg(request: pytest.FixtureRequest) -> Iterable[float]: def epsilon_fg(request: FixtureRequest) -> Iterable[float]:
yield request.param yield request.param
@pytest.fixture(scope='module', params=['center', '000', 'random']) @pytest.fixture(scope='module', params=['center', '000', 'random'])
def epsilon(request: pytest.FixtureRequest, def epsilon(request: FixtureRequest,
shape: Tuple[int, ...], shape: Tuple[int, ...],
epsilon_bg: float, epsilon_bg: float,
epsilon_fg: float, epsilon_fg: float,
@ -58,17 +62,17 @@ def epsilon(request: pytest.FixtureRequest,
@pytest.fixture(scope='module', params=[1.0]) # 1.5 @pytest.fixture(scope='module', params=[1.0]) # 1.5
def j_mag(request: pytest.FixtureRequest) -> Iterable[float]: def j_mag(request: FixtureRequest) -> Iterable[float]:
yield request.param yield request.param
@pytest.fixture(scope='module', params=[1.0, 1.5]) @pytest.fixture(scope='module', params=[1.0, 1.5])
def dx(request: pytest.FixtureRequest) -> Iterable[float]: def dx(request: FixtureRequest) -> Iterable[float]:
yield request.param yield request.param
@pytest.fixture(scope='module', params=['uniform', 'centerbig']) @pytest.fixture(scope='module', params=['uniform', 'centerbig'])
def dxes(request: pytest.FixtureRequest, def dxes(request: FixtureRequest,
shape: Tuple[int, ...], shape: Tuple[int, ...],
dx: float, dx: float,
) -> Iterable[List[List[numpy.ndarray]]]: ) -> Iterable[List[List[numpy.ndarray]]]:

View File

@ -7,6 +7,7 @@ import numpy # type: ignore
from .. import fdfd from .. import fdfd
from ..fdmath import vec, unvec from ..fdmath import vec, unvec
from .utils import assert_close # , assert_fields_close from .utils import assert_close # , assert_fields_close
from .conftest import FixtureRequest
def test_residual(sim: 'FDResult') -> None: def test_residual(sim: 'FDResult') -> None:
@ -53,17 +54,17 @@ def test_poynting_planes(sim: 'FDResult') -> None:
# Also see conftest.py # Also see conftest.py
@pytest.fixture(params=[1 / 1500]) @pytest.fixture(params=[1 / 1500])
def omega(request: pytest.FixtureRequest) -> Iterable[float]: def omega(request: FixtureRequest) -> Iterable[float]:
yield request.param yield request.param
@pytest.fixture(params=[None]) @pytest.fixture(params=[None])
def pec(request: pytest.FixtureRequest) -> Iterable[Optional[numpy.ndarray]]: def pec(request: FixtureRequest) -> Iterable[Optional[numpy.ndarray]]:
yield request.param yield request.param
@pytest.fixture(params=[None]) @pytest.fixture(params=[None])
def pmc(request: pytest.FixtureRequest) -> Iterable[Optional[numpy.ndarray]]: def pmc(request: FixtureRequest) -> Iterable[Optional[numpy.ndarray]]:
yield request.param yield request.param
@ -74,7 +75,7 @@ def pmc(request: pytest.FixtureRequest) -> Iterable[Optional[numpy.ndarray]]:
@pytest.fixture(params=['diag']) # 'center' @pytest.fixture(params=['diag']) # 'center'
def j_distribution(request: pytest.FixtureRequest, def j_distribution(request: FixtureRequest,
shape: Tuple[int, ...], shape: Tuple[int, ...],
j_mag: float, j_mag: float,
) -> Iterable[numpy.ndarray]: ) -> Iterable[numpy.ndarray]:
@ -103,7 +104,7 @@ class FDResult:
@pytest.fixture() @pytest.fixture()
def sim(request: pytest.FixtureRequest, def sim(request: FixtureRequest,
shape: Tuple[int, ...], shape: Tuple[int, ...],
epsilon: numpy.ndarray, epsilon: numpy.ndarray,
dxes: List[List[numpy.ndarray]], dxes: List[List[numpy.ndarray]],

View File

@ -7,6 +7,7 @@ from .. import fdfd
from ..fdmath import vec, unvec, dx_lists_mut from ..fdmath import vec, unvec, dx_lists_mut
#from .utils import assert_close, assert_fields_close #from .utils import assert_close, assert_fields_close
from .test_fdfd import FDResult from .test_fdfd import FDResult
from .conftest import FixtureRequest
def test_pml(sim: FDResult, src_polarity: int) -> None: def test_pml(sim: FDResult, src_polarity: int) -> None:
@ -42,34 +43,34 @@ def test_pml(sim: FDResult, src_polarity: int) -> None:
# Also see conftest.py # Also see conftest.py
@pytest.fixture(params=[1 / 1500]) @pytest.fixture(params=[1 / 1500])
def omega(request: pytest.FixtureRequest) -> Iterable[float]: def omega(request: FixtureRequest) -> Iterable[float]:
yield request.param yield request.param
@pytest.fixture(params=[None]) @pytest.fixture(params=[None])
def pec(request: pytest.FixtureRequest) -> Iterable[Optional[numpy.ndarray]]: def pec(request: FixtureRequest) -> Iterable[Optional[numpy.ndarray]]:
yield request.param yield request.param
@pytest.fixture(params=[None]) @pytest.fixture(params=[None])
def pmc(request: pytest.FixtureRequest) -> Iterable[Optional[numpy.ndarray]]: def pmc(request: FixtureRequest) -> Iterable[Optional[numpy.ndarray]]:
yield request.param yield request.param
@pytest.fixture(params=[(30, 1, 1), @pytest.fixture(params=[(30, 1, 1),
(1, 30, 1), (1, 30, 1),
(1, 1, 30)]) (1, 1, 30)])
def shape(request: pytest.FixtureRequest) -> Iterable[Tuple[int, ...]]: def shape(request: FixtureRequest) -> Iterable[Tuple[int, ...]]:
yield (3, *request.param) yield (3, *request.param)
@pytest.fixture(params=[+1, -1]) @pytest.fixture(params=[+1, -1])
def src_polarity(request: pytest.FixtureRequest) -> Iterable[int]: def src_polarity(request: FixtureRequest) -> Iterable[int]:
yield request.param yield request.param
@pytest.fixture() @pytest.fixture()
def j_distribution(request: pytest.FixtureRequest, def j_distribution(request: FixtureRequest,
shape: Tuple[int, ...], shape: Tuple[int, ...],
epsilon: numpy.ndarray, epsilon: numpy.ndarray,
dxes: dx_lists_mut, dxes: dx_lists_mut,
@ -107,7 +108,7 @@ def j_distribution(request: pytest.FixtureRequest,
@pytest.fixture() @pytest.fixture()
def epsilon(request: pytest.FixtureRequest, def epsilon(request: FixtureRequest,
shape: Tuple[int, ...], shape: Tuple[int, ...],
epsilon_bg: float, epsilon_bg: float,
epsilon_fg: float, epsilon_fg: float,
@ -117,7 +118,7 @@ def epsilon(request: pytest.FixtureRequest,
@pytest.fixture(params=['uniform']) @pytest.fixture(params=['uniform'])
def dxes(request: pytest.FixtureRequest, def dxes(request: FixtureRequest,
shape: Tuple[int, ...], shape: Tuple[int, ...],
dx: float, dx: float,
omega: float, omega: float,
@ -135,7 +136,7 @@ def dxes(request: pytest.FixtureRequest,
@pytest.fixture() @pytest.fixture()
def sim(request: pytest.FixtureRequest, def sim(request: FixtureRequest,
shape: Tuple[int, ...], shape: Tuple[int, ...],
epsilon: numpy.ndarray, epsilon: numpy.ndarray,
dxes: dx_lists_mut, dxes: dx_lists_mut,

View File

@ -6,6 +6,7 @@ import numpy # type: ignore
from .. import fdtd from .. import fdtd
from .utils import assert_close, assert_fields_close, PRNG from .utils import assert_close, assert_fields_close, PRNG
from .conftest import FixtureRequest
def test_initial_fields(sim: 'TDResult') -> None: def test_initial_fields(sim: 'TDResult') -> None:
@ -140,7 +141,7 @@ def test_poynting_planes(sim: 'TDResult') -> None:
@pytest.fixture(params=[0.3]) @pytest.fixture(params=[0.3])
def dt(request: pytest.FixtureRequest) -> Iterable[float]: def dt(request: FixtureRequest) -> Iterable[float]:
yield request.param yield request.param
@ -158,12 +159,12 @@ class TDResult:
@pytest.fixture(params=[(0, 4, 8)]) # (0,) @pytest.fixture(params=[(0, 4, 8)]) # (0,)
def j_steps(request: pytest.fixtureRequest) -> Iterable[Tuple[int, ...]]: def j_steps(request: FixtureRequest) -> Iterable[Tuple[int, ...]]:
yield request.param yield request.param
@pytest.fixture(params=['center', 'random']) @pytest.fixture(params=['center', 'random'])
def j_distribution(request: pytest.FixtureRequest, def j_distribution(request: FixtureRequest,
shape: Tuple[int, ...], shape: Tuple[int, ...],
j_mag: float, j_mag: float,
) -> Iterable[numpy.ndarray]: ) -> Iterable[numpy.ndarray]:
@ -178,7 +179,7 @@ def j_distribution(request: pytest.FixtureRequest,
@pytest.fixture() @pytest.fixture()
def sim(request: pytest.FixtureRequest, def sim(request: FixtureRequest,
shape: Tuple[int, ...], shape: Tuple[int, ...],
epsilon: numpy.ndarray, epsilon: numpy.ndarray,
dxes: List[List[numpy.ndarray]], dxes: List[List[numpy.ndarray]],

View File

@ -1,8 +1,10 @@
from typing import Any from typing import Any
import numpy # type: ignore import numpy # type: ignore
PRNG = numpy.random.RandomState(12345) PRNG = numpy.random.RandomState(12345)
def assert_fields_close(x: numpy.ndarray, def assert_fields_close(x: numpy.ndarray,
y: numpy.ndarray, y: numpy.ndarray,
*args: Any, *args: Any,