mirror of https://github.com/scrapy/scrapy.git
PY3 fix DownloaderStats middleware tests
This commit is contained in:
parent
78a4cd0f1c
commit
3a9c73bc5d
|
|
@ -12,7 +12,6 @@ tests/test_downloadermiddleware_httpproxy.py
|
|||
tests/test_downloadermiddleware.py
|
||||
tests/test_downloadermiddleware_redirect.py
|
||||
tests/test_downloadermiddleware_retry.py
|
||||
tests/test_downloadermiddleware_stats.py
|
||||
tests/test_downloadermiddleware_useragent.py
|
||||
tests/test_engine.py
|
||||
tests/test_mail.py
|
||||
|
|
|
|||
|
|
@ -6,6 +6,10 @@ from scrapy.spiders import Spider
|
|||
from scrapy.utils.test import get_crawler
|
||||
|
||||
|
||||
class MyException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class TestDownloaderStats(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
|
@ -18,21 +22,28 @@ class TestDownloaderStats(TestCase):
|
|||
self.req = Request('http://scrapytest.org')
|
||||
self.res = Response('scrapytest.org', status=400)
|
||||
|
||||
def assertStatsEqual(self, key, value):
|
||||
self.assertEqual(
|
||||
self.crawler.stats.get_value(key, spider=self.spider),
|
||||
value,
|
||||
str(self.crawler.stats.get_stats(self.spider))
|
||||
)
|
||||
|
||||
def test_process_request(self):
|
||||
self.mw.process_request(self.req, self.spider)
|
||||
self.assertEqual(self.crawler.stats.get_value('downloader/request_count', \
|
||||
spider=self.spider), 1)
|
||||
self.assertStatsEqual('downloader/request_count', 1)
|
||||
|
||||
def test_process_response(self):
|
||||
self.mw.process_response(self.req, self.res, self.spider)
|
||||
self.assertEqual(self.crawler.stats.get_value('downloader/response_count', \
|
||||
spider=self.spider), 1)
|
||||
self.assertStatsEqual('downloader/response_count', 1)
|
||||
|
||||
def test_process_exception(self):
|
||||
self.mw.process_exception(self.req, Exception(), self.spider)
|
||||
self.assertEqual(self.crawler.stats.get_value('downloader/exception_count', \
|
||||
spider=self.spider), 1)
|
||||
self.mw.process_exception(self.req, MyException(), self.spider)
|
||||
self.assertStatsEqual('downloader/exception_count', 1)
|
||||
self.assertStatsEqual(
|
||||
'downloader/exception_type_count/tests.test_downloadermiddleware_stats.MyException',
|
||||
1
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
self.crawler.stats.close_spider(self.spider, '')
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue