-
Notifications
You must be signed in to change notification settings - Fork 573
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Remove classes from tests (spiderqueue)
- Loading branch information
1 parent
3a7311d
commit 1a50168
Showing
2 changed files
with
48 additions
and
44 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 |
---|---|---|
|
@@ -35,6 +35,7 @@ | |
"coveralls", | ||
"pytest", | ||
"pytest-cov", | ||
"pytest-twisted", | ||
"requests", | ||
], | ||
"docs": [ | ||
|
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,66 +1,69 @@ | ||
import pytest | ||
from twisted.internet.defer import inlineCallbacks, maybeDeferred | ||
from twisted.trial import unittest | ||
from zope.interface.verify import verifyObject | ||
|
||
from scrapyd import spiderqueue | ||
from scrapyd.config import Config | ||
from scrapyd.interfaces import ISpiderQueue | ||
|
||
name = "spider1" | ||
priority = 5 | ||
args = { | ||
"arg1": "val1", | ||
"arg2": 2, | ||
"arg3": "\N{SNOWMAN}", | ||
} | ||
expected = args.copy() | ||
expected["name"] = name | ||
|
||
class SpiderQueueTest(unittest.TestCase): | ||
"""This test case also supports queues with deferred methods.""" | ||
|
||
def setUp(self): | ||
self.q = spiderqueue.SqliteSpiderQueue(Config(values={"dbs_dir": ":memory:"}), "quotesbot") | ||
self.name = "spider1" | ||
self.priority = 5 | ||
self.args = { | ||
"arg1": "val1", | ||
"arg2": 2, | ||
"arg3": "\N{SNOWMAN}", | ||
} | ||
self.msg = self.args.copy() | ||
self.msg["name"] = self.name | ||
@pytest.fixture() | ||
def queue(): | ||
return spiderqueue.SqliteSpiderQueue(Config(values={"dbs_dir": ":memory:"}), "quotesbot") | ||
|
||
def test_interface(self): | ||
verifyObject(ISpiderQueue, self.q) | ||
|
||
@inlineCallbacks | ||
def test_add_pop_count(self): | ||
c = yield maybeDeferred(self.q.count) | ||
self.assertEqual(c, 0) | ||
def test_interface(queue): | ||
verifyObject(ISpiderQueue, queue) | ||
|
||
yield maybeDeferred(self.q.add, self.name, self.priority, **self.args) | ||
|
||
c = yield maybeDeferred(self.q.count) | ||
self.assertEqual(c, 1) | ||
@inlineCallbacks | ||
def test_add_pop_count(queue): | ||
c = yield maybeDeferred(queue.count) | ||
assert c == 0 | ||
|
||
m = yield maybeDeferred(self.q.pop) | ||
self.assertEqual(m, self.msg) | ||
yield maybeDeferred(queue.add, name, priority, **args) | ||
|
||
c = yield maybeDeferred(self.q.count) | ||
self.assertEqual(c, 0) | ||
c = yield maybeDeferred(queue.count) | ||
assert c == 1 | ||
|
||
@inlineCallbacks | ||
def test_list(self): | ||
actual = yield maybeDeferred(self.q.list) | ||
self.assertEqual(actual, []) | ||
m = yield maybeDeferred(queue.pop) | ||
assert m == expected | ||
|
||
yield maybeDeferred(self.q.add, self.name, self.priority, **self.args) | ||
yield maybeDeferred(self.q.add, self.name, self.priority, **self.args) | ||
c = yield maybeDeferred(queue.count) | ||
assert c == 0 | ||
|
||
actual = yield maybeDeferred(self.q.list) | ||
self.assertEqual(actual, [self.msg, self.msg]) | ||
|
||
@inlineCallbacks | ||
def test_clear(self): | ||
yield maybeDeferred(self.q.add, self.name, self.priority, **self.args) | ||
yield maybeDeferred(self.q.add, self.name, self.priority, **self.args) | ||
@inlineCallbacks | ||
def test_list(queue): | ||
actual = yield maybeDeferred(queue.list) | ||
assert actual == [] | ||
|
||
c = yield maybeDeferred(self.q.count) | ||
self.assertEqual(c, 2) | ||
yield maybeDeferred(queue.add, name, priority, **args) | ||
yield maybeDeferred(queue.add, name, priority, **args) | ||
|
||
yield maybeDeferred(self.q.clear) | ||
actual = yield maybeDeferred(queue.list) | ||
assert actual == [expected, expected] | ||
|
||
c = yield maybeDeferred(self.q.count) | ||
self.assertEqual(c, 0) | ||
|
||
@inlineCallbacks | ||
def test_clear(queue): | ||
yield maybeDeferred(queue.add, name, priority, **args) | ||
yield maybeDeferred(queue.add, name, priority, **args) | ||
|
||
c = yield maybeDeferred(queue.count) | ||
assert c == 2 | ||
|
||
yield maybeDeferred(queue.clear) | ||
|
||
c = yield maybeDeferred(queue.count) | ||
assert c == 0 |