Add a test function that uses asyncio.Queue().

This commit is contained in:
Andrey Rakhmatullin 2019-12-31 17:54:41 +05:00
parent e3b8ba6188
commit 2b9254c2bd
2 changed files with 11 additions and 3 deletions

View File

@ -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

View File

@ -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')