Scrapy, a fast high-level web crawling & scraping framework for Python.
unskip part of test_download_gzip_response on py3, file a twisted issue for the remaining part
Konstantin Lopuhin81a90c3af65c
diff --git a/tests/mockserver.py b/tests/mockserver.pyindex 1ab8e4b8d..02bab0efd 100644--- a/tests/mockserver.py+++ b/tests/mockserver.py@@ -170,12 +170,12 @@ class Root(Resource):self.putChild(b"raw", Raw())self.putChild(b"echo", Echo())- if six.PY2 and twisted_version > (12, 3, 0):+ if twisted_version > (12, 3, 0):from twisted.web.test.test_webclient import PayloadResourcefrom twisted.web.server import GzipEncoderFactoryfrom twisted.web.resource import EncodingResourceWrapper- self.putChild('payload', PayloadResource())- self.putChild("xpayload", EncodingResourceWrapper(PayloadResource(), [GzipEncoderFactory()]))+ self.putChild(b"payload", PayloadResource())+ self.putChild(b"xpayload", EncodingResourceWrapper(PayloadResource(), [GzipEncoderFactory()]))def getChild(self, name, request):return selfdiff --git a/tests/test_downloader_handlers.py b/tests/test_downloader_handlers.pyindex b3c1c565f..a8de28d4b 100644--- a/tests/test_downloader_handlers.py+++ b/tests/test_downloader_handlers.py@@ -294,27 +294,30 @@ class Http11MockServerTestCase(unittest.TestCase):@defer.inlineCallbacksdef test_download_gzip_response(self):- if six.PY2 and twisted_version > (12, 3, 0):+ if twisted_version > (12, 3, 0):crawler = get_crawler(SingleRequestSpider)- body = '1'*100 # PayloadResource requires body length to be 100+ body = b'1'*100 # PayloadResource requires body length to be 100request = Request('http://localhost:8998/payload', method='POST', body=body, meta={'download_maxsize': 50})yield crawler.crawl(seed=request)failure = crawler.spider.meta['failure']# download_maxsize < 100, hence the CancelledErrorself.assertIsInstance(failure.value, defer.CancelledError)- request.headers.setdefault('Accept-Encoding', 'gzip,deflate')+ request.headers.setdefault(b'Accept-Encoding', b'gzip,deflate')request = request.replace(url='http://localhost:8998/xpayload')yield crawler.crawl(seed=request)- # download_maxsize = 50 is enough for the gzipped response- failure = crawler.spider.meta.get('failure')- self.assertTrue(failure == None)- reason = crawler.spider.meta['close_reason']- self.assertTrue(reason, 'finished')+ if six.PY2:+ # download_maxsize = 50 is enough for the gzipped response+ # See issue https://twistedmatrix.com/trac/ticket/8175+ raise unittest.SkipTest("xpayload only enabled for PY2")+ failure = crawler.spider.meta.get('failure')+ self.assertTrue(failure == None)+ reason = crawler.spider.meta['close_reason']+ self.assertTrue(reason, 'finished')else:- raise unittest.SkipTest("xpayload and payload endpoint only enabled for twisted > 12.3.0 and python 2.x")+ raise unittest.SkipTest("xpayload and payload endpoint only enabled for twisted > 12.3.0")class UriResource(resource.Resource):