def test_inline_task self class TestSpider Spider calls def task_gener

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def test_inline_task(self):
class TestSpider(Spider):
calls = []
def task_generator(self):
yield Task('inline', url=SERVER.BASE_URL)
@inline_task
def task_inline(self, grab, task):
self.calls.append('generator')
url = SERVER.BASE_URL
grab.setup(url=url)
grab = yield Task(grab=grab)
self.calls.append('inline1')
url = SERVER.BASE_URL
grab.setup(url=url)
grab = yield Task(grab=grab)
self.calls.append('inline2')
url = SERVER.BASE_URL
grab.setup(url=url)
grab = yield Task(grab=grab)
self.calls.append('inline3')
self.add_task(Task('yield', url=SERVER.BASE_URL))
def task_yield(self, grab, task):
self.calls.append('yield')
yield Task('end', url=SERVER.BASE_URL)
def task_end(self, grab, task):
self.calls.append('end')
bot = TestSpider()
bot.run()
self.assertEqual(['generator', 'inline1', 'inline2', 'inline3', 'yield', 'end'],
bot.calls)