Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
532a5b0
commit 22e5a3e
Showing
1 changed file
with
62 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
"""Tests related to setup and teardown of @value decorator.""" | ||
from dependencies import Injector | ||
from dependencies import value | ||
from helpers import CodeCollector | ||
|
||
|
||
setup_and_teardown = CodeCollector() | ||
|
||
|
||
@setup_and_teardown.parametrize | ||
def test_setup_and_teardown_value(code): | ||
"""@value could decorate a generator function.""" | ||
|
||
class App: | ||
def __init__(self, lock): | ||
assert isinstance(lock, Lock) | ||
assert lock.resource == "/" | ||
|
||
class Lock: | ||
def __init__(self, resource): | ||
self.resource = resource | ||
|
||
def acquire(self): | ||
result.append("setup") | ||
|
||
def release(self): | ||
result.append("teardown") | ||
|
||
result = [] | ||
Container = code(App, Lock) | ||
with Container as container: | ||
assert result == ["setup"] | ||
container.app | ||
assert result == ["setup", "teardown"] | ||
|
||
|
||
@setup_and_teardown | ||
def _u5GLvAblXmz1(App, Lock): | ||
class Container(Injector): | ||
app = App | ||
resource = "/" | ||
|
||
@value | ||
def lock(resource): | ||
instance = Lock(resource) | ||
instance.acquire() | ||
yield instance | ||
instance.release() | ||
|
||
return Container | ||
|
||
|
||
@setup_and_teardown | ||
def _imvsnuRtTGOL(App, Lock): | ||
@value | ||
def lock(resource): | ||
instance = Lock(resource) | ||
instance.acquire() | ||
yield instance | ||
instance.release() | ||
|
||
return Injector(app=App, lock=lock, resource="/") |