-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add resolver and refactor tests (#12)
* add resolver and refactor tests * python 3.10 tests fix
- Loading branch information
Showing
9 changed files
with
170 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import dataclasses | ||
|
||
import pytest | ||
|
||
from tests import container | ||
from tests.container import DIContainer | ||
|
||
|
||
@dataclasses.dataclass(kw_only=True, slots=True) | ||
class WrongFactory: | ||
some_dep: int = 1 | ||
not_existing_name: container.DependentFactory | ||
sync_resource: str | ||
|
||
|
||
async def test_dependency_resolver() -> None: | ||
resolver = DIContainer.resolver(container.FreeFactory) | ||
dep1 = await resolver() | ||
dep2 = await DIContainer.resolve(container.FreeFactory) | ||
|
||
assert dep1 | ||
assert dep2 | ||
assert dep1 is not dep2 | ||
|
||
|
||
async def test_dependency_resolver_failed() -> None: | ||
resolver = DIContainer.resolver(WrongFactory) | ||
with pytest.raises(RuntimeError, match="Provider is not found, field_name='not_existing_name'"): | ||
await resolver() |
Oops, something went wrong.