-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from reagento/refactor/dependency_sources_list
use inspect to collect dependency sources
- Loading branch information
Showing
7 changed files
with
155 additions
and
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import pytest | ||
|
||
from dishka import Provider, Scope, alias, make_container, provide | ||
|
||
|
||
class AliasProvider(Provider): | ||
@provide(scope=Scope.APP) | ||
def provide_int(self) -> int: | ||
return 42 | ||
|
||
aliased_complex = alias(source=float, provides=complex) | ||
aliased_float = alias(source=int, provides=float) | ||
|
||
|
||
def test_alias(): | ||
with make_container(AliasProvider()) as container: | ||
assert container.get(float) == container.get(int) | ||
|
||
|
||
def test_alias_to_alias(): | ||
with make_container(AliasProvider()) as container: | ||
assert container.get(complex) == container.get(int) | ||
|
||
|
||
class CycleProvider(Provider): | ||
a = alias(source=int, provides=bool) | ||
b = alias(source=bool, provides=float) | ||
c = alias(source=float, provides=int) | ||
|
||
|
||
def test_cycle(): | ||
with pytest.raises(ValueError): | ||
make_container(CycleProvider()) |
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