From a2efd389b09984de15ee0653d169c0bbbfd61a05 Mon Sep 17 00:00:00 2001 From: Konstantin Lopuhin Date: Mon, 18 Jan 2016 15:09:54 +0300 Subject: [PATCH 1/2] clarify: rename r_transform to response_transform --- tests/test_webclient.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_webclient.py b/tests/test_webclient.py index 3ee6c24c2..dbe659d5c 100644 --- a/tests/test_webclient.py +++ b/tests/test_webclient.py @@ -18,14 +18,14 @@ from scrapy.http import Request, Headers from scrapy.utils.python import to_bytes, to_unicode -def getPage(url, contextFactory=None, r_transform=None, *args, **kwargs): +def getPage(url, contextFactory=None, response_transform=None, *args, **kwargs): """Adapted version of twisted.web.client.getPage""" def _clientfactory(url, *args, **kwargs): url = to_unicode(url) timeout = kwargs.pop('timeout', 0) f = client.ScrapyHTTPClientFactory( Request(url, *args, **kwargs), timeout=timeout) - f.deferred.addCallback(r_transform or (lambda r: r.body)) + f.deferred.addCallback(response_transform or (lambda r: r.body)) return f from twisted.web.client import _makeGetterFactory @@ -355,7 +355,7 @@ class WebClientTestCase(unittest.TestCase): Content-Encoding header """ body = b'\xd0\x81\xd1\x8e\xd0\xaf' return getPage( - self.getURL('encoding'), body=body, r_transform=lambda r: r)\ + self.getURL('encoding'), body=body, response_transform=lambda r: r)\ .addCallback(self._check_Encoding, body) def _check_Encoding(self, response, original_body): From 494643458270311341c509f5476c61737aa27a70 Mon Sep 17 00:00:00 2001 From: Konstantin Lopuhin Date: Mon, 18 Jan 2016 15:23:01 +0300 Subject: [PATCH 2/2] revert most changes to this test, and clarify - it is valid only on py2, because urls are strictly unicode on py3 --- tests/test_webclient.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/test_webclient.py b/tests/test_webclient.py index dbe659d5c..9b5beda4c 100644 --- a/tests/test_webclient.py +++ b/tests/test_webclient.py @@ -78,16 +78,17 @@ class ParseUrlTestCase(unittest.TestCase): elements of its return tuple, even when passed an URL which has previously been passed to L{urlparse} as a C{unicode} string. """ - goodInput = u'http://example.com/path' - badInput = goodInput.encode('ascii') - if six.PY2: - goodInput, badInput = badInput, goodInput - urlparse(badInput) + if not six.PY2: + raise unittest.SkipTest( + "Applies only to Py2, as urls can be ONLY unicode on Py3") + badInput = u'http://example.com/path' + goodInput = badInput.encode('ascii') + self._parse(badInput) # cache badInput in urlparse_cached scheme, netloc, host, port, path = self._parse(goodInput) - self.assertTrue(isinstance(scheme, bytes)) - self.assertTrue(isinstance(netloc, bytes)) - self.assertTrue(isinstance(host, bytes)) - self.assertTrue(isinstance(path, bytes)) + self.assertTrue(isinstance(scheme, str)) + self.assertTrue(isinstance(netloc, str)) + self.assertTrue(isinstance(host, str)) + self.assertTrue(isinstance(path, str)) self.assertTrue(isinstance(port, int))