Skip to content

Commit 136a6b2

Browse files
Fix #130 -- FakeLock context enter returns lock instance (#136)
* context manager returns a lock * extend returns correct True value instead of None --------- Co-authored-by: Anchal Gurung <[email protected]>
1 parent b353ab1 commit 136a6b2

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

dramatiq_crontab/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
class FakeLock:
77
def __enter__(self):
8-
pass
8+
return self
99

1010
def __exit__(self, exc_type, exc_val, exc_tb):
1111
pass
1212

1313
def extend(self, additional_time=None, replace_ttl=False):
14-
pass
14+
return True
1515

1616

1717
if redis_url := get_settings().REDIS_URL:

tests/test_utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,17 @@ def test_extend_lock__error():
2020
utils.extend_lock(lock, scheduler)
2121
assert lock.extend.call_count == 1
2222
assert scheduler.shutdown.call_count == 1
23+
24+
25+
class TestFakeLock:
26+
def test_enter(self):
27+
fake_lock = utils.FakeLock()
28+
assert fake_lock.__enter__() is fake_lock
29+
30+
def test_exit(self):
31+
fake_lock = utils.FakeLock()
32+
assert fake_lock.__exit__(None, None, None) is None
33+
34+
def test_extend(self):
35+
fake_lock = utils.FakeLock()
36+
assert fake_lock.extend(additional_time=10, replace_ttl=True)

0 commit comments

Comments
 (0)