-
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.
chore: add tests for build/run time decorators
- Loading branch information
Showing
3 changed files
with
29 additions
and
2 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
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,27 @@ | ||
from _pytest.monkeypatch import MonkeyPatch | ||
|
||
from damavand.resource import buildtime, runtime | ||
|
||
|
||
def test_buildtime_decorator(monkeypatch: MonkeyPatch): | ||
@buildtime | ||
def test_func(_): | ||
return "building" | ||
|
||
monkeypatch.setattr("damavand.utils.is_building", lambda: True) | ||
assert test_func(None) == "building" | ||
|
||
monkeypatch.setattr("damavand.utils.is_building", lambda: False) | ||
assert test_func(None) == None | ||
|
||
|
||
def test_runtime_decorator(monkeypatch: MonkeyPatch): | ||
@runtime | ||
def test_func(_): | ||
return "running" | ||
|
||
monkeypatch.setattr("damavand.utils.is_building", lambda: True) | ||
assert test_func(None) == None | ||
|
||
monkeypatch.setattr("damavand.utils.is_building", lambda: False) | ||
assert test_func(None) == "running" |