forked from seomoz/qless-py
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
46 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,63 @@ | ||
"""Tests about events""" | ||
|
||
from typing import Dict, List | ||
# from typing import Dict, List | ||
|
||
from reqless.abstract import AbstractJob | ||
from reqless_test.common import TestReqless | ||
# from reqless.abstract import AbstractJob | ||
# from reqless_test.common import TestReqless | ||
|
||
|
||
class TestEvents(TestReqless): | ||
"""Tests about events""" | ||
# class TestEvents(TestReqless): | ||
# """Tests about events""" | ||
|
||
def setUp(self) -> None: | ||
TestReqless.setUp(self) | ||
self.client.queues["foo"].put("reqless_test.common.NoopJob", "{}", jid="jid") | ||
job = self.client.jobs["jid"] | ||
assert job is not None and isinstance(job, AbstractJob) | ||
job.track() | ||
# def setUp(self) -> None: | ||
# TestReqless.setUp(self) | ||
# self.client.queues["foo"].put("reqless_test.common.NoopJob", "{}", jid="jid") | ||
# job = self.client.jobs["jid"] | ||
# assert job is not None and isinstance(job, AbstractJob) | ||
# job.track() | ||
|
||
def test_basic(self) -> None: | ||
"""Ensure we can get a basic event""" | ||
# def test_basic(self) -> None: | ||
# """Ensure we can get a basic event""" | ||
|
||
count = 0 | ||
# count = 0 | ||
|
||
def func(event: Dict) -> None: | ||
"""No docstring""" | ||
nonlocal count | ||
count += 1 | ||
# def func(event: Dict) -> None: | ||
# """No docstring""" | ||
# nonlocal count | ||
# count += 1 | ||
|
||
self.client.events.on("popped", func) | ||
with self.client.events.thread(): | ||
self.client.queues["foo"].pop() | ||
self.assertEqual(count, 1) | ||
# self.client.events.on("popped", func) | ||
# with self.client.events.thread(): | ||
# self.client.queues["foo"].pop() | ||
# self.assertEqual(count, 1) | ||
|
||
def test_off(self) -> None: | ||
"""Ensure we can turn off callbacks""" | ||
# def test_off(self) -> None: | ||
# """Ensure we can turn off callbacks""" | ||
|
||
popped_count = 0 | ||
# popped_count = 0 | ||
|
||
def popped(event: Dict) -> None: | ||
"""No docstring""" | ||
nonlocal popped_count | ||
popped_count += 1 | ||
# def popped(event: Dict) -> None: | ||
# """No docstring""" | ||
# nonlocal popped_count | ||
# popped_count += 1 | ||
|
||
completed_count = 0 | ||
# completed_count = 0 | ||
|
||
def completed(event: Dict) -> None: | ||
"""No docstring""" | ||
nonlocal completed_count | ||
completed_count += 1 | ||
# def completed(event: Dict) -> None: | ||
# """No docstring""" | ||
# nonlocal completed_count | ||
# completed_count += 1 | ||
|
||
self.client.events.on("popped", popped) | ||
self.client.events.on("completed", completed) | ||
self.client.events.off("popped") | ||
with self.client.events.thread(): | ||
job = self.client.queues["foo"].pop() | ||
assert job is not None and not isinstance(job, List) | ||
job.complete() | ||
self.assertEqual(popped_count, 0) | ||
self.assertEqual(completed_count, 1) | ||
# self.client.events.on("popped", popped) | ||
# self.client.events.on("completed", completed) | ||
# self.client.events.off("popped") | ||
# with self.client.events.thread(): | ||
# job = self.client.queues["foo"].pop() | ||
# assert job is not None and not isinstance(job, List) | ||
# job.complete() | ||
# self.assertEqual(popped_count, 0) | ||
# self.assertEqual(completed_count, 1) | ||
|
||
def test_not_implemented(self) -> None: | ||
"""Ensure missing events throw errors""" | ||
self.assertRaises(NotImplementedError, self.client.events.on, "foo", int) | ||
# def test_not_implemented(self) -> None: | ||
# """Ensure missing events throw errors""" | ||
# self.assertRaises(NotImplementedError, self.client.events.on, "foo", int) |