Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions tests/providers/test_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ def test_alias_delegates_to_source() -> None:
assert concrete is abstract


def test_alias_resolve_provider() -> None:
container = Container(groups=[MyGroup])
instance = container.resolve_provider(MyGroup.abstract_repo)
assert isinstance(instance, PostgresRepository)


def test_alias_without_caching_returns_fresh_instance_per_call() -> None:
class G(Group):
repo = providers.Factory(creator=PostgresRepository)
Expand Down
11 changes: 7 additions & 4 deletions tests/providers/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class MyGroup(Group):
creator=SimpleCreator, skip_creator_parsing=True, bound_type=None
)
func_with_union_factory = providers.Factory(creator=func_with_union, bound_type=None)
func_with_broken_annotation = providers.Factory(creator=func_with_broken_annotation, bound_type=None)
request_factory = providers.Factory(scope=Scope.REQUEST, creator=DependentCreator)
request_factory_with_di_container = providers.Factory(scope=Scope.REQUEST, creator=AnotherCreator)

Expand Down Expand Up @@ -72,13 +71,17 @@ def test_app_factory_unresolvable() -> None:
def test_func_with_union_factory() -> None:
app_container = Container(groups=[MyGroup])
instance1 = app_container.resolve_provider(MyGroup.func_with_union_factory)
assert instance1
assert instance1 == str(SimpleCreator(dep1="original"))


def test_func_with_broken_annotation() -> None:
app_container = Container(groups=[MyGroup])
with pytest.warns(UserWarning, match="Failed to resolve type hints"):
factory = providers.Factory(creator=func_with_broken_annotation, bound_type=None)

app_container = Container()
app_container.providers_registry.add_providers(factory)
with pytest.raises(ArgumentResolutionError, match="Argument dep1 of type None cannot be resolved"):
app_container.resolve_provider(MyGroup.func_with_broken_annotation)
app_container.resolve_provider(factory)


def test_request_factory() -> None:
Expand Down
6 changes: 4 additions & 2 deletions tests/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_container_resolve_missing_provider() -> None:
ProviderNotRegisteredError,
match=r"Provider of type <class 'str'> is not registered in providers registry.",
) as exc:
assert app_container.resolve(str) is None
app_container.resolve(str)
assert exc.value.provider_type is str


Expand Down Expand Up @@ -143,7 +143,9 @@ def test_validate_detects_cycle() -> None:
container.validate()
[issue] = exc.value.errors
assert isinstance(issue, CircularDependencyError)
assert issue.cycle_path == ["CycleA", "CycleB", "CycleA"]
cycle = issue.cycle_path
assert cycle[0] == cycle[-1]
assert set(cycle) == {"CycleA", "CycleB"}


def test_validate_passes_for_valid_graph() -> None:
Expand Down
Loading