From b7561fb78ec7d289711c1a3e1e0a64c0a72631ba Mon Sep 17 00:00:00 2001 From: kiarash kiani Date: Wed, 31 Jul 2024 11:10:44 +0200 Subject: [PATCH] chore: add tests for build/run time decorators --- src/damavand/resource/resource.py | 4 ++-- tests/resources/__init__.py | 0 tests/resources/test_resource.py | 27 +++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 tests/resources/__init__.py create mode 100644 tests/resources/test_resource.py diff --git a/src/damavand/resource/resource.py b/src/damavand/resource/resource.py index f502e39..ff357e6 100644 --- a/src/damavand/resource/resource.py +++ b/src/damavand/resource/resource.py @@ -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) @@ -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) diff --git a/tests/resources/__init__.py b/tests/resources/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/resources/test_resource.py b/tests/resources/test_resource.py new file mode 100644 index 0000000..78f4543 --- /dev/null +++ b/tests/resources/test_resource.py @@ -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"