Skip to content

Commit

Permalink
add sync -> async failure tests
Browse files Browse the repository at this point in the history
  • Loading branch information
biniona committed Oct 7, 2024
1 parent 8e7d796 commit f18dd14
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion tests/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest

from minject.inject import async_context, bind, config, define, nested_config, reference
from minject.registry import Registry
from minject.registry import AUTO_OR_NONE, Registry

TEXT = "we love tests"

Expand Down Expand Up @@ -67,6 +67,12 @@ async def __aexit__(
self.in_context = False


@bind(dep_async=reference(MyDependencyAsync))
class MySyncClassWithAsyncDependency:
def __init__(self, dep_async: MyDependencyAsync) -> None:
self.dep_async = dep_async


@async_context
@bind(text=TEXT)
@bind(dep_async=reference(MyDependencyAsync))
Expand Down Expand Up @@ -258,3 +264,13 @@ async def test_define(registry: Registry) -> None:
assert my_api.dep_not_specified.in_context == False
assert my_api.dep_context_counter.in_context == False
assert my_api.dep_context_counter.exited_context_counter == 1


def test_get_item_sync_class_async_dependency_throws(registry: Registry) -> None:
with pytest.raises(AssertionError):
_ = registry[MySyncClassWithAsyncDependency]


def test_get_sync_class_async_dependency_throws(registry: Registry) -> None:
with pytest.raises(AssertionError):
_ = registry.get(MySyncClassWithAsyncDependency, AUTO_OR_NONE)

0 comments on commit f18dd14

Please sign in to comment.