aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Harrison <paul@harrison.sh>2022-11-18 20:27:21 +0000
committerPaul Harrison <paul@harrison.sh>2022-12-15 16:02:14 +0000
commit68bfee17f1dc7b1126de11b6f0ea3b20108266d3 (patch)
tree1ee9f4fded1ea3cab0d20965a253a8eca5bcf4ad
parent6be02c447dd19a3a103c9735600604f5be58de75 (diff)
chore: Introduce card factory
-rw-r--r--tests/conftest.py24
-rw-r--r--tests/test_models.py29
2 files changed, 35 insertions, 18 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
index 0000000..85d2ec3
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1,24 @@
+from typing import Any, Callable, TypeVar
+
+import pytest
+from mypy_extensions import KwArg
+
+from poker.constants import Suit, Value
+from poker.models import Card
+
+T = TypeVar("T")
+Factory = Callable[[KwArg(Any)], T]
+
+
+@pytest.fixture(scope="session")
+def card_factory() -> Factory[Card]:
+ """Get Card object factory."""
+ default = {
+ "suit": Suit.CLUBS,
+ "value": Value.ACE,
+ }
+
+ def factory(**kwargs: Any) -> Card:
+ return Card(**(default | kwargs))
+
+ return factory
diff --git a/tests/test_models.py b/tests/test_models.py
index 37e9c03..c94756d 100644
--- a/tests/test_models.py
+++ b/tests/test_models.py
@@ -1,28 +1,21 @@
import pytest
from pydantic import ValidationError
-from poker.constants import Suit, Value
+from poker.constants import Value
from poker.models import Card, Hand
+from tests.conftest import Factory
-def test_hand_should_contain_unique_cards() -> None:
+def test_hand_should_contain_unique_cards(card_factory: Factory[Card]) -> None:
+ cards = [
+ Value.ACE,
+ Value.TWO,
+ Value.THREE,
+ Value.FOUR,
+ ]
with pytest.raises(ValidationError):
_ = Hand(
- cards=(
- Card(suit=Suit.CLUBS, value=Value.ACE),
- Card(suit=Suit.CLUBS, value=Value.TWO),
- Card(suit=Suit.CLUBS, value=Value.THREE),
- Card(suit=Suit.CLUBS, value=Value.FOUR),
- Card(suit=Suit.CLUBS, value=Value.FOUR),
- )
+ cards=tuple(card_factory(value=value) for value in cards + [Value.FOUR])
)
- _ = Hand(
- cards=(
- Card(suit=Suit.CLUBS, value=Value.ACE),
- Card(suit=Suit.CLUBS, value=Value.TWO),
- Card(suit=Suit.CLUBS, value=Value.THREE),
- Card(suit=Suit.CLUBS, value=Value.FOUR),
- Card(suit=Suit.CLUBS, value=Value.FIVE),
- )
- )
+ _ = Hand(cards=tuple(card_factory(value=value) for value in cards + [Value.FIVE]))