-
Notifications
You must be signed in to change notification settings - Fork 48
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 #277 from IvanKirpichnikov/override-provides
add override for alias and from context
- Loading branch information
Showing
14 changed files
with
313 additions
and
47 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
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
Empty file.
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,88 @@ | ||
import pytest | ||
|
||
from dishka import Provider, Scope, alias, make_container, provide | ||
from dishka.entities.validation_settigs import ( | ||
STRICT_VALIDATION, | ||
ValidationSettings, | ||
) | ||
from dishka.exceptions import ( | ||
ImplicitOverrideDetectedError, | ||
NothingOverriddenError, | ||
) | ||
|
||
|
||
def test_no_override() -> None: | ||
class TestProvider(Provider): | ||
scope = Scope.APP | ||
provides = ( | ||
provide(int, provides=int) | ||
+ alias(source=int, provides=float) | ||
+ alias(source=int, provides=float) | ||
) | ||
|
||
with pytest.raises(ImplicitOverrideDetectedError) as e: | ||
make_container( | ||
TestProvider(), | ||
validation_settings=STRICT_VALIDATION, | ||
) | ||
assert str(e.value) | ||
|
||
|
||
def test_skip_no_override() -> None: | ||
class TestProvider(Provider): | ||
scope = Scope.APP | ||
provides = ( | ||
provide(int, provides=int) | ||
+ alias(source=int, provides=float) | ||
+ alias(source=int, provides=float) | ||
) | ||
|
||
make_container( | ||
TestProvider(), | ||
validation_settings=ValidationSettings(implicit_override=False), | ||
) | ||
|
||
|
||
def test_override_ok() -> None: | ||
class TestProvider(Provider): | ||
scope = Scope.APP | ||
provides = ( | ||
provide(int, provides=int) | ||
+ alias(source=int, provides=float) | ||
+ alias(source=int, provides=float, override=True) | ||
) | ||
|
||
make_container( | ||
TestProvider(), | ||
validation_settings=STRICT_VALIDATION, | ||
) | ||
|
||
|
||
def test_cant_override() -> None: | ||
class TestProvider(Provider): | ||
scope = Scope.APP | ||
provides = ( | ||
provide(int, provides=int) | ||
+ alias(source=int, provides=float, override=True) | ||
) | ||
|
||
with pytest.raises(NothingOverriddenError) as e: | ||
make_container( | ||
TestProvider(), | ||
validation_settings=STRICT_VALIDATION, | ||
) | ||
assert str(e.value) | ||
|
||
|
||
def test_skip_cant_override() -> None: | ||
class TestProvider(Provider): | ||
scope = Scope.APP | ||
provides = ( | ||
provide(int, provides=int) | ||
+ alias(source=int, provides=float, override=True) | ||
) | ||
|
||
make_container( | ||
TestProvider(), | ||
validation_settings=ValidationSettings(nothing_overridden=False), | ||
) |
Oops, something went wrong.