-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use dg with entry function and builtin type
- Loading branch information
Showing
11 changed files
with
156 additions
and
14 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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import pytest | ||
|
||
from ididi.errors import UnsolvableDependencyError | ||
from ididi.graph import DependencyGraph | ||
|
||
|
||
|
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 pytest | ||
|
||
from ididi import DependencyGraph | ||
from ididi.errors import UnsolvableDependencyError | ||
|
||
|
||
class IgnoreNode: | ||
def __init__(self, name: str, age: int): ... | ||
|
||
|
||
def test_direct_resolve_fail(): | ||
dg = DependencyGraph() | ||
dg.node(IgnoreNode) | ||
with pytest.raises(UnsolvableDependencyError): | ||
dg.static_resolve(IgnoreNode) | ||
|
||
|
||
def test_resolve_fail_with_partial_ignore(): | ||
dg = DependencyGraph() | ||
|
||
dg.node(ignore=("name",))(IgnoreNode) | ||
with pytest.raises(UnsolvableDependencyError): | ||
dg.static_resolve(IgnoreNode) | ||
|
||
|
||
def test_resolve_with_ignore(): | ||
dg = DependencyGraph() | ||
dg.node(ignore=("name", int))(IgnoreNode) | ||
dg.static_resolve(IgnoreNode) |
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,58 @@ | ||
from dataclasses import dataclass | ||
|
||
import pytest | ||
|
||
from ididi import DependencyGraph | ||
from ididi.errors import BuiltinTypeFactoryError, TopLevelBulitinTypeError | ||
|
||
|
||
@dataclass | ||
class UserCommand: | ||
user_id: str | ||
|
||
|
||
@dataclass | ||
class CreateUser(UserCommand): | ||
user_name: str | ||
|
||
|
||
@dataclass | ||
class RemoveUser(UserCommand): | ||
user_name: str | ||
|
||
|
||
@dataclass | ||
class UpdateUser(UserCommand): | ||
old_name: str | ||
new_name: str | ||
|
||
|
||
def update_user(cmd: UpdateUser) -> str: | ||
return cmd.new_name | ||
|
||
|
||
class UserService: | ||
def __init__(self): | ||
self.name = "name" | ||
|
||
def create_user(self, cmd: CreateUser) -> str: | ||
return "hello" | ||
|
||
def remove_user(self, cmd: RemoveUser) -> str: | ||
return "goodbye" | ||
|
||
|
||
def test_static_resolve_all(): | ||
dg = DependencyGraph() | ||
dg.node(UserService) | ||
with pytest.raises(BuiltinTypeFactoryError): | ||
dg.node(update_user) | ||
|
||
dg.static_resolve_all() | ||
|
||
|
||
def test_dg_node_builtin(): | ||
dg = DependencyGraph() | ||
|
||
with pytest.raises(TopLevelBulitinTypeError): | ||
dg.node(int) |
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