From 63aec9aa755a6d4f6d077eb23774caaf3ab67525 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Fri, 12 Oct 2018 17:02:17 -0400 Subject: [PATCH] Consolidate test fixtures --- tests/__init__.py | 0 tests/fixtures.py | 8 ++++++++ tests/test_applicatives.py | 10 +++------- tests/test_functors.py | 11 ++++------- tests/test_monads.py | 8 ++------ tests/test_monoids.py | 1 + 6 files changed, 18 insertions(+), 20 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/fixtures.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/fixtures.py b/tests/fixtures.py new file mode 100644 index 0000000..1af09dd --- /dev/null +++ b/tests/fixtures.py @@ -0,0 +1,8 @@ +import pytest # type: ignore +from typing import Type +from monads import Maybe, Result, Reader + + +@pytest.fixture(scope="module", params=[Maybe, Result]) +def monad(request) -> Type: + return request.param diff --git a/tests/test_applicatives.py b/tests/test_applicatives.py index 0f686c6..2e1375c 100644 --- a/tests/test_applicatives.py +++ b/tests/test_applicatives.py @@ -1,17 +1,13 @@ import pytest # type: ignore -from typing import Callable, Type, TypeVar +from typing import Callable, TypeVar -from monads import Applicative, Functor, Maybe, Result +from monads import Applicative +from .fixtures import monad T = TypeVar("T") S = TypeVar("S") -@pytest.fixture(scope="module", params=[Maybe, Result]) -def monad(request) -> Type: - return request.param - - def test_fmap_using_ap(monad) -> None: f: Callable[[int], int] = lambda x: x + 1 m: Applicative[int] = monad.pure(3) diff --git a/tests/test_functors.py b/tests/test_functors.py index 9fb1ea2..88a074f 100644 --- a/tests/test_functors.py +++ b/tests/test_functors.py @@ -1,16 +1,13 @@ import pytest # type: ignore -from typing import Callable, Type, TypeVar -from monads import Functor, Maybe, Result +from typing import Callable, TypeVar + +from monads import Functor +from .fixtures import monad T = TypeVar("T") S = TypeVar("S") -@pytest.fixture(scope="module", params=[Maybe, Result]) -def monad(request) -> Type: - return request.param - - def test_identity(monad) -> None: m: Functor = monad.pure(3) identity: Callable[[T], T] = lambda x: x diff --git a/tests/test_monads.py b/tests/test_monads.py index 2419861..16036f6 100644 --- a/tests/test_monads.py +++ b/tests/test_monads.py @@ -1,11 +1,7 @@ import pytest # type: ignore -from typing import List, Type -from monads import Monad, Maybe, Result - -@pytest.fixture(scope="module", params=[Maybe, Result]) -def monad(request) -> Type: - return request.param +from monads import Monad +from .fixtures import monad def test_bind(monad) -> None: diff --git a/tests/test_monoids.py b/tests/test_monoids.py index 4b46904..d7ca3bc 100644 --- a/tests/test_monoids.py +++ b/tests/test_monoids.py @@ -1,5 +1,6 @@ import pytest # type: ignore from typing import Any, Callable, Type + from monads.monoid import Monoid from monads.maybe import First, Last, Just