-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add `fast_depends.shema.get_schema` method to generate wrapped function payload (close #6) * Improve ForwardRef resolution * Update copyrights * Update Readme and docs to close #59
- Loading branch information
Showing
22 changed files
with
844 additions
and
113 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
from fast_depends import Depends, inject, dependency_provider | ||
|
||
def original_dependency(): | ||
return 1 | ||
raise NotImplementedError() | ||
|
||
def override_dependency(): | ||
return 2 | ||
return 1 | ||
|
||
@inject | ||
def func(d = Depends(original_dependency)): | ||
return d | ||
|
||
dependency_provider.override(original_dependency, override_dependency) | ||
# or | ||
dependency_provider.dependency_overrides[original_dependency] = override_dependency | ||
|
||
def test(): | ||
@inject | ||
def func(d = Depends(original_dependency)): | ||
return d | ||
|
||
assert func() == 2 | ||
assert func() == 1 |
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 |
---|---|---|
@@ -1,32 +1,25 @@ | ||
from unittest.mock import Mock | ||
|
||
import pytest | ||
from fast_depends import dependency_provider, inject, Depends | ||
|
||
# Base code | ||
|
||
def base_dep(): | ||
return 1 | ||
|
||
def override_dep(): | ||
return 2 | ||
|
||
@inject | ||
def func(d = Depends(base_dep)): | ||
return d | ||
|
||
# Tests | ||
|
||
@pytest.fixture | ||
def provider(): | ||
yield dependency_provider | ||
dependency_provider.clear() # (1)! | ||
|
||
def test_sync_overide(provider): | ||
mock = Mock() | ||
|
||
def base_dep(): | ||
mock.original() | ||
return 1 | ||
|
||
def override_dep(): | ||
mock.override() | ||
return 2 | ||
|
||
provider.override(base_dep, override_dep) | ||
|
||
@inject | ||
def func(d = Depends(base_dep)): | ||
assert d == 2 | ||
|
||
func() | ||
|
||
mock.override.assert_called_once() | ||
assert not mock.original.called | ||
assert func() == 2 |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
"""FastDepends - extracted and cleared from HTTP domain FastAPI Dependency Injection System""" | ||
|
||
__version__ = "2.3.1" | ||
__version__ = "2.4.0b0" |
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
from fast_depends.dependencies import dependency_provider | ||
from fast_depends.dependencies import Provider, dependency_provider | ||
from fast_depends.use import Depends, inject | ||
|
||
__all__ = ( | ||
"Depends", | ||
"dependency_provider", | ||
"Provider", | ||
"inject", | ||
) |
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
Oops, something went wrong.