Skip to content

Commit

Permalink
call pook.off in the end of pook.activate wrapper function (#145)
Browse files Browse the repository at this point in the history
* call pook.off in the end of pook.activate wrapper function

* add unit tests for activate as decorator

* Update tests/unit/api_test.py

* Fix formatting

---------

Co-authored-by: sarayourfriend <git@sarayourfriend.pictures>
  • Loading branch information
shift0965 and sarayourfriend authored Oct 15, 2024
1 parent e2fa075 commit e95e259
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
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
1 change: 1 addition & 0 deletions src/pook/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def wrapper(*args, **kw):
fn(*args, **kw)
finally:
_engine.disable()
_engine.reset()

return wrapper

Expand Down
26 changes: 26 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,28 @@ 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


async 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 e95e259

Please sign in to comment.