mirror of https://github.com/scrapy/scrapy.git
Add a test function that uses asyncio.Queue().
This commit is contained in:
parent
e3b8ba6188
commit
2b9254c2bd
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
This module contains some assorted functions used in tests
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from importlib import import_module
|
||||
|
|
@ -96,3 +96,10 @@ def assert_samelines(testcase, text1, text2, msg=None):
|
|||
line endings between platforms
|
||||
"""
|
||||
testcase.assertEqual(text1.splitlines(), text2.splitlines(), msg)
|
||||
|
||||
|
||||
def get_from_asyncio_queue(value):
|
||||
q = asyncio.Queue()
|
||||
getter = q.get()
|
||||
q.put_nowait(value)
|
||||
return getter
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ from scrapy.http import Request, Response
|
|||
from scrapy.spiders import Spider
|
||||
from scrapy.exceptions import _InvalidOutput
|
||||
from scrapy.core.downloader.middleware import DownloaderMiddlewareManager
|
||||
from scrapy.utils.test import get_crawler
|
||||
from scrapy.utils.test import get_crawler, get_from_asyncio_queue
|
||||
from scrapy.utils.python import to_bytes
|
||||
|
||||
|
||||
|
|
@ -240,7 +240,8 @@ class MiddlewareUsingCoro(ManagerTestCase):
|
|||
class CoroMiddleware:
|
||||
async def process_request(self, request, spider):
|
||||
await asyncio.sleep(0.1)
|
||||
return resp
|
||||
result = await get_from_asyncio_queue(resp)
|
||||
return result
|
||||
|
||||
self.mwman._add_middleware(CoroMiddleware())
|
||||
req = Request('http://example.com/index.html')
|
||||
|
|
|
|||
Loading…
Reference in New Issue