Skip to content

Commit

Permalink
Merge pull request #82 from ikalnytskyi/chore/tests-housekeeping
Browse files Browse the repository at this point in the history
Tests housekeeping, stylistic mostly
  • Loading branch information
ikalnytskyi committed Nov 30, 2023
2 parents c1c6725 + d784746 commit d160db5
Show file tree
Hide file tree
Showing 3 changed files with 376 additions and 281 deletions.
52 changes: 25 additions & 27 deletions tests/test_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ def test_box_get_keyerror(boxclass):

def test_box_get_default(boxclass):
testbox = boxclass()
sentinel = object()
default = object()

assert testbox.get("the-key", sentinel) is sentinel
assert testbox.get("the-key", default) is default


@pytest.mark.parametrize(
Expand All @@ -151,7 +151,7 @@ def test_box_get_default(boxclass):
((), {"b": 2, "c": 3}, 15),
],
)
def test_box_pass_a(args, kwargs, rv, boxclass):
def test_box_pass_a(boxclass, args, kwargs, rv):
testbox = boxclass()
testbox.put("a", 10)

Expand All @@ -173,7 +173,7 @@ def fn(a, b, c):
((), {"a": 1, "c": 3}, 14),
],
)
def test_box_pass_b(args, kwargs, rv, boxclass):
def test_box_pass_b(boxclass, args, kwargs, rv):
testbox = boxclass()
testbox.put("b", 10)

Expand All @@ -196,7 +196,7 @@ def fn(a, b, c):
((), {"a": 1, "b": 2}, 13),
],
)
def test_box_pass_c(args, kwargs, rv, boxclass):
def test_box_pass_c(boxclass, args, kwargs, rv):
testbox = boxclass()
testbox.put("c", 10)

Expand All @@ -219,7 +219,7 @@ def fn(a, b, c):
((), {"a": 1, "b": 2}, 13),
],
)
def test_box_pass_c_default(args, kwargs, rv, boxclass):
def test_box_pass_c_default(boxclass, args, kwargs, rv):
testbox = boxclass()
testbox.put("c", 10)

Expand All @@ -243,7 +243,7 @@ def fn(a, b, c=20):
((), {"c": 3}, 113),
],
)
def test_box_pass_ab(args, kwargs, rv, boxclass):
def test_box_pass_ab(boxclass, args, kwargs, rv):
testbox = boxclass()
testbox.put("a", 10)
testbox.put("b", 100)
Expand Down Expand Up @@ -272,7 +272,7 @@ def fn(a, b, c):
((), {"a": 1}, 111),
],
)
def test_box_pass_bc(args, kwargs, rv, boxclass):
def test_box_pass_bc(boxclass, args, kwargs, rv):
testbox = boxclass()
testbox.put("b", 10)
testbox.put("c", 100)
Expand All @@ -299,7 +299,7 @@ def fn(a, b, c):
((), {"b": 2}, 112),
],
)
def test_box_pass_ac(args, kwargs, rv, boxclass):
def test_box_pass_ac(boxclass, args, kwargs, rv):
testbox = boxclass()
testbox.put("a", 10)
testbox.put("c", 100)
Expand Down Expand Up @@ -329,7 +329,7 @@ def fn(a, b, c):
((), {}, 1110),
],
)
def test_box_pass_abc(args, kwargs, rv, boxclass):
def test_box_pass_abc(boxclass, args, kwargs, rv):
testbox = boxclass()
testbox.put("a", 10)
testbox.put("b", 100)
Expand All @@ -355,7 +355,7 @@ def fn(a, b, c):
((), {"a": 1, "c": 3}, 14),
],
)
def test_box_pass_d_as_b(args, kwargs, rv, boxclass):
def test_box_pass_d_as_b(boxclass, args, kwargs, rv):
testbox = boxclass()
testbox.put("d", 10)

Expand All @@ -374,7 +374,7 @@ def fn(a, b, c):
((), {}, 42),
],
)
def test_box_pass_method(args, kwargs, rv, boxclass):
def test_box_pass_method(boxclass, args, kwargs, rv):
testbox = boxclass()
testbox.put("x", 42)

Expand All @@ -395,16 +395,16 @@ def __init__(self, x):
((), {}, 42),
],
)
async def test_box_pass_coroutine(args, kwargs, rv, boxclass):
async def test_box_pass_coroutine(boxclass, args, kwargs, rv):
testbox = boxclass()
testbox.put("x", 42)

@testbox.pass_("x")
async def co(x):
async def fn(x):
return x

assert inspect.iscoroutinefunction(co)
assert await co(*args, **kwargs) == rv
assert inspect.iscoroutinefunction(fn)
assert await fn(*args, **kwargs) == rv


@pytest.mark.parametrize(
Expand All @@ -415,14 +415,11 @@ async def co(x):
((), {}, 42),
],
)
def test_box_pass_key_type(args, kwargs, rv, boxclass):
class key:
pass

def test_box_pass_key(boxclass, supported_key, args, kwargs, rv):
testbox = boxclass()
testbox.put(key, 1)
testbox.put(supported_key, 1)

@testbox.pass_(key, as_="x")
@testbox.pass_(supported_key, as_="x")
def fn(x):
return x + 41

Expand Down Expand Up @@ -460,7 +457,7 @@ def fn(a, b):
assert str(excinfo.value) == "'b'"


def test_box_pass_optimization(boxclass, request):
def test_box_pass_optimization(request, boxclass):
testbox = boxclass()
testbox.put("a", 1)
testbox.put("b", 1)
Expand All @@ -481,7 +478,7 @@ def fn(a, b, c):
assert len(fn()) == 1


def test_box_pass_optimization_complex(boxclass, request):
def test_box_pass_optimization_complex(request, boxclass):
testbox = boxclass()
testbox.put("a", 1)
testbox.put("b", 1)
Expand Down Expand Up @@ -512,7 +509,7 @@ def fn(a, b, c, d):


@pytest.mark.asyncio()
async def test_box_pass_optimization_async(boxclass, request):
async def test_box_pass_optimization_async(request, boxclass):
testbox = boxclass()
testbox.put("a", 1)
testbox.put("b", 1)
Expand All @@ -537,10 +534,11 @@ def test_chainbox_put_changes_box():
testbox = picobox.Box()
testchainbox = picobox.ChainBox(testbox)

with pytest.raises(KeyError, match="the-key"):
with pytest.raises(KeyError) as excinfo:
testchainbox.get("the-key")
testchainbox.put("the-key", 42)
assert str(excinfo.value) == "'the-key'"

testchainbox.put("the-key", 42)
assert testbox.get("the-key") == 42


Expand Down

0 comments on commit d160db5

Please sign in to comment.