Skip to content

Commit

Permalink
chore: Split test_base into separate modules per entity (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonagestam authored Nov 5, 2023
1 parent 28dbd32 commit 1a22c2d
Show file tree
Hide file tree
Showing 6 changed files with 1,156 additions and 1,017 deletions.
38 changes: 38 additions & 0 deletions tests/strategies.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
from __future__ import annotations

import random
from typing import Final

from hypothesis.strategies import composite
from hypothesis.strategies import decimals
from hypothesis.strategies import integers
from hypothesis.strategies import text

from immoney import Currency
from immoney import Money
from immoney._base import Overdraft
from immoney._base import valid_subunit

valid_sek_decimals: Final = decimals(
min_value=0,
Expand All @@ -15,3 +23,33 @@

valid_money_subunits: Final = integers(min_value=0)
valid_overdraft_subunits: Final = integers(min_value=1)


@composite
def currencies(
draw,
code_values=text(max_size=3, min_size=3),
):
class Subclass(Currency):
subunit = random.choice(tuple(valid_subunit))
code = draw(code_values)

return Subclass()


@composite
def monies(
draw,
currencies=currencies(),
subunits=integers(min_value=0),
) -> Money[Currency]:
return Money.from_subunit(draw(subunits), draw(currencies))


@composite
def overdrafts(
draw,
currencies=currencies(),
subunits=integers(min_value=1),
) -> Overdraft[Currency]:
return Overdraft.from_subunit(draw(subunits), draw(currencies))
Loading

0 comments on commit 1a22c2d

Please sign in to comment.