Skip to content

Commit

Permalink
chore: add tests for build/run time decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
kkiani committed Jul 31, 2024
1 parent e32ab1f commit b7561fb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/damavand/resource/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
def buildtime(func):
def wrapper(self, *args, **kwargs):
if not utils.is_building():
return lambda _: None
return None

return func(self, *args, **kwargs)

Expand All @@ -17,7 +17,7 @@ def wrapper(self, *args, **kwargs):
def runtime(func):
def wrapper(self, *args, **kwargs):
if utils.is_building():
return lambda _: None
return None

return func(self, *args, **kwargs)

Expand Down
Empty file added tests/resources/__init__.py
Empty file.
27 changes: 27 additions & 0 deletions tests/resources/test_resource.py
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"

0 comments on commit b7561fb

Please sign in to comment.