Skip to content

Commit

Permalink
add unit tests for activate as decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
shift0965 committed Oct 15, 2024
1 parent d58750d commit 014913c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/pook/activate_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ async def wrapper(*args, **kw):
fn(*args, **kw)
finally:
_engine.disable()
_engine.reset()

return wrapper
3 changes: 2 additions & 1 deletion src/pook/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ def wrapper(*args, **kw):
try:
fn(*args, **kw)
finally:
off()
_engine.disable()
_engine.reset()

return wrapper

Expand Down
28 changes: 28 additions & 0 deletions tests/unit/api_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import pytest

from pook import api
Expand Down Expand Up @@ -47,3 +48,30 @@ def test_mock_contructors(engine):

assert len(engine.mocks) == 0
assert engine.active is False


def test_activate_as_decorator(engine):

@api.activate
def test_activate():
api.get("foo.com")
assert engine.active is True
assert engine.isdone() is False

test_activate()
assert engine.active is False
assert engine.isdone() is True


def test_activate_as_decorator_for_async(engine):

@api.activate
async def test_activate():
await asyncio.sleep(0)
api.get("foo.com")
assert engine.active is True
assert engine.isdone() is False

await test_activate()
assert engine.active is False
assert engine.isdone() is True

0 comments on commit 014913c

Please sign in to comment.