diff --git a/pytest.ini b/pytest.ini index 8177fedd3..0e289866c 100644 --- a/pytest.ini +++ b/pytest.ini @@ -20,227 +20,25 @@ addopts = twisted = 1 markers = only_asyncio: marks tests as only enabled when --reactor=asyncio is passed +flake8-max-line-length = 119 flake8-ignore = W503 - # Files that are only meant to provide top-level imports are expected not - # to use any of their imports: + + # Exclude files that are meant to provide top-level imports + # E402: Module level import not at top of file + # F401: Module imported but unused scrapy/core/downloader/handlers/http.py F401 scrapy/http/__init__.py F401 + scrapy/linkextractors/__init__.py E402 F401 + scrapy/spiders/__init__.py E402 F401 + # Issues pending a review: - # extras - extras/qps-bench-server.py E501 - extras/qpsclient.py E501 E501 - # scrapy/commands - scrapy/commands/__init__.py E501 - scrapy/commands/check.py E501 - scrapy/commands/crawl.py E501 - scrapy/commands/edit.py E501 - scrapy/commands/fetch.py E501 - scrapy/commands/genspider.py E501 - scrapy/commands/parse.py E501 - scrapy/commands/runspider.py E501 - scrapy/commands/settings.py E501 - scrapy/commands/shell.py E501 - scrapy/commands/startproject.py E501 - scrapy/commands/version.py E501 - # scrapy/contracts - scrapy/contracts/__init__.py E501 - # scrapy/core - scrapy/core/engine.py E501 - scrapy/core/scheduler.py E501 - scrapy/core/scraper.py E501 - scrapy/core/spidermw.py E501 - scrapy/core/downloader/__init__.py E501 - scrapy/core/downloader/contextfactory.py E501 - scrapy/core/downloader/middleware.py E501 - scrapy/core/downloader/tls.py E501 - scrapy/core/downloader/webclient.py E501 - scrapy/core/downloader/handlers/__init__.py E501 - scrapy/core/downloader/handlers/ftp.py E501 - scrapy/core/downloader/handlers/http10.py E501 - scrapy/core/downloader/handlers/http11.py E501 - scrapy/core/downloader/handlers/s3.py E501 - # scrapy/downloadermiddlewares - scrapy/downloadermiddlewares/ajaxcrawl.py E501 - scrapy/downloadermiddlewares/decompression.py E501 - scrapy/downloadermiddlewares/defaultheaders.py E501 - scrapy/downloadermiddlewares/httpcache.py E501 - scrapy/downloadermiddlewares/httpcompression.py E501 - scrapy/downloadermiddlewares/httpproxy.py E501 - scrapy/downloadermiddlewares/redirect.py E501 - scrapy/downloadermiddlewares/retry.py E501 - scrapy/downloadermiddlewares/robotstxt.py E501 - scrapy/downloadermiddlewares/stats.py E501 - # scrapy/extensions - scrapy/extensions/closespider.py E501 - scrapy/extensions/corestats.py E501 - scrapy/extensions/feedexport.py E501 - scrapy/extensions/httpcache.py E501 - scrapy/extensions/memdebug.py E501 - scrapy/extensions/spiderstate.py E501 - scrapy/extensions/telnet.py E501 - scrapy/extensions/throttle.py E501 - # scrapy/http - scrapy/http/common.py E501 - scrapy/http/cookies.py E501 - scrapy/http/request/__init__.py E501 - scrapy/http/request/form.py E501 - scrapy/http/request/json_request.py E501 - scrapy/http/response/__init__.py E501 - scrapy/http/response/text.py E501 - # scrapy/linkextractors - scrapy/linkextractors/__init__.py E501 E402 - scrapy/linkextractors/lxmlhtml.py E501 - # scrapy/loader - scrapy/loader/__init__.py E501 - scrapy/loader/processors.py E501 - # scrapy/pipelines - scrapy/pipelines/__init__.py E501 - scrapy/pipelines/files.py E501 - scrapy/pipelines/images.py E501 - scrapy/pipelines/media.py E501 - # scrapy/selector + scrapy/__init__.py E402 scrapy/selector/__init__.py F403 - scrapy/selector/unified.py E501 - # scrapy/settings - scrapy/settings/__init__.py E501 - scrapy/settings/default_settings.py E501 - scrapy/settings/deprecated.py E501 - # scrapy/spidermiddlewares - scrapy/spidermiddlewares/httperror.py E501 - scrapy/spidermiddlewares/offsite.py E501 - scrapy/spidermiddlewares/referer.py E501 - scrapy/spidermiddlewares/urllength.py E501 - # scrapy/spiders - scrapy/spiders/__init__.py E501 E402 - scrapy/spiders/crawl.py E501 - scrapy/spiders/feed.py E501 - scrapy/spiders/sitemap.py E501 - # scrapy/utils - scrapy/utils/asyncio.py E501 - scrapy/utils/benchserver.py E501 - scrapy/utils/conf.py E402 E501 - scrapy/utils/datatypes.py E501 - scrapy/utils/decorators.py E501 - scrapy/utils/defer.py E501 - scrapy/utils/deprecate.py E501 - scrapy/utils/gz.py E501 + scrapy/spiders/__init__.py E402 scrapy/utils/http.py F403 - scrapy/utils/httpobj.py E501 - scrapy/utils/iterators.py E501 - scrapy/utils/log.py E501 scrapy/utils/markup.py F403 - scrapy/utils/misc.py E501 scrapy/utils/multipart.py F403 - scrapy/utils/project.py E501 - scrapy/utils/python.py E501 - scrapy/utils/reactor.py E501 - scrapy/utils/reqser.py E501 - scrapy/utils/request.py E501 - scrapy/utils/response.py E501 - scrapy/utils/signal.py E501 - scrapy/utils/sitemap.py E501 - scrapy/utils/spider.py E501 - scrapy/utils/ssl.py E501 - scrapy/utils/test.py E501 - scrapy/utils/url.py E501 F403 F405 - # scrapy - scrapy/__init__.py E402 E501 - scrapy/cmdline.py E501 - scrapy/crawler.py E501 - scrapy/dupefilters.py E501 - scrapy/exceptions.py E501 - scrapy/exporters.py E501 - scrapy/interfaces.py E501 - scrapy/item.py E501 - scrapy/link.py E501 - scrapy/logformatter.py E501 - scrapy/mail.py E402 E501 - scrapy/middleware.py E501 - scrapy/pqueues.py E501 - scrapy/resolver.py E501 - scrapy/responsetypes.py E501 - scrapy/robotstxt.py E501 - scrapy/shell.py E501 - scrapy/signalmanager.py E501 - scrapy/spiderloader.py E501 - scrapy/squeues.py E501 - scrapy/statscollectors.py E501 - # tests - tests/__init__.py E402 E501 - tests/mockserver.py E501 - tests/spiders.py E501 - tests/test_closespider.py E501 - tests/test_command_fetch.py E501 - tests/test_command_parse.py E501 - tests/test_command_shell.py E501 - tests/test_commands.py E501 - tests/test_contracts.py E501 - tests/test_crawl.py E501 - tests/test_crawler.py E501 - tests/test_dependencies.py E501 - tests/test_downloader_handlers.py E501 - tests/test_downloadermiddleware.py E501 - tests/test_downloadermiddleware_ajaxcrawlable.py E501 - tests/test_downloadermiddleware_cookies.py E501 - tests/test_downloadermiddleware_defaultheaders.py E501 - tests/test_downloadermiddleware_downloadtimeout.py E501 - tests/test_downloadermiddleware_httpcache.py E501 - tests/test_downloadermiddleware_httpcompression.py E501 - tests/test_downloadermiddleware_decompression.py E501 - tests/test_downloadermiddleware_httpproxy.py E501 - tests/test_downloadermiddleware_redirect.py E501 - tests/test_downloadermiddleware_retry.py E501 - tests/test_downloadermiddleware_robotstxt.py E501 - tests/test_downloadermiddleware_stats.py E501 - tests/test_dupefilters.py E501 - tests/test_engine.py E501 - tests/test_exporters.py E501 - tests/test_feedexport.py E501 - tests/test_http_cookies.py E501 - tests/test_http_headers.py E501 - tests/test_http_request.py E402 E501 - tests/test_http_response.py E501 - tests/test_item.py E501 - tests/test_link.py E501 - tests/test_linkextractors.py E501 - tests/test_loader.py E501 E741 - tests/test_logformatter.py E501 - tests/test_mail.py E501 - tests/test_middleware.py E501 - tests/test_pipeline_crawl.py E501 - tests/test_pipeline_files.py E501 - tests/test_pipeline_images.py E501 - tests/test_pipeline_media.py E501 - tests/test_proxy_connect.py E501 - tests/test_request_cb_kwargs.py E501 - tests/test_responsetypes.py E501 - tests/test_robotstxt_interface.py E501 E501 - tests/test_scheduler.py E501 - tests/test_selector.py E501 - tests/test_spider.py E501 - tests/test_spidermiddleware.py E501 - tests/test_spidermiddleware_httperror.py E501 - tests/test_spidermiddleware_offsite.py E501 - tests/test_spidermiddleware_output_chain.py E501 - tests/test_spidermiddleware_referer.py E501 - tests/test_squeues.py E501 - tests/test_utils_asyncio.py E501 - tests/test_utils_conf.py E501 - tests/test_utils_curl.py E501 - tests/test_utils_datatypes.py E402 E501 - tests/test_utils_defer.py E501 - tests/test_utils_deprecate.py E501 - tests/test_utils_http.py E501 - tests/test_utils_iterators.py E501 - tests/test_utils_python.py E501 - tests/test_utils_reqser.py E501 - tests/test_utils_request.py E501 - tests/test_utils_response.py E501 - tests/test_utils_sitemap.py E501 - tests/test_utils_url.py E501 E501 - tests/test_webclient.py E501 E402 - tests/test_cmdline/__init__.py E501 - tests/test_settings/__init__.py E501 - tests/test_spiderloader/__init__.py E501 - tests/test_utils_misc/__init__.py E501 + scrapy/utils/url.py F403 F405 + tests/test_loader.py E741 + tests/test_webclient.py E402 diff --git a/scrapy/cmdline.py b/scrapy/cmdline.py index a4ec7c8ae..b189e016b 100644 --- a/scrapy/cmdline.py +++ b/scrapy/cmdline.py @@ -165,6 +165,7 @@ if __name__ == '__main__': try: execute() finally: - # Twisted prints errors in DebugInfo.__del__, but PyPy does not run gc.collect() - # on exit: http://doc.pypy.org/en/latest/cpython_differences.html?highlight=gc.collect#differences-related-to-garbage-collection-strategies + # Twisted prints errors in DebugInfo.__del__, but PyPy does not run gc.collect() on exit: + # http://doc.pypy.org/en/latest/cpython_differences.html + # ?highlight=gc.collect#differences-related-to-garbage-collection-strategies garbage_collect() diff --git a/scrapy/robotstxt.py b/scrapy/robotstxt.py index 0a9af3a62..52cf09844 100644 --- a/scrapy/robotstxt.py +++ b/scrapy/robotstxt.py @@ -17,10 +17,12 @@ def decode_robotstxt(robotstxt_body, spider, to_native_str_type=False): except UnicodeDecodeError: # If we found garbage or robots.txt in an encoding other than UTF-8, disregard it. # Switch to 'allow all' state. - logger.warning("Failure while parsing robots.txt. " - "File either contains garbage or is in an encoding other than UTF-8, treating it as an empty file.", - exc_info=sys.exc_info(), - extra={'spider': spider}) + logger.warning( + "Failure while parsing robots.txt. File either contains garbage or " + "is in an encoding other than UTF-8, treating it as an empty file.", + exc_info=sys.exc_info(), + extra={'spider': spider}, + ) robotstxt_body = '' return robotstxt_body diff --git a/scrapy/spiders/crawl.py b/scrapy/spiders/crawl.py index d76a96451..cb021a5a7 100644 --- a/scrapy/spiders/crawl.py +++ b/scrapy/spiders/crawl.py @@ -54,8 +54,12 @@ class Rule: self.process_request = _get_method(self.process_request, spider) self.process_request_argcount = len(get_func_args(self.process_request)) if self.process_request_argcount == 1: - msg = 'Rule.process_request should accept two arguments (request, response), accepting only one is deprecated' - warnings.warn(msg, category=ScrapyDeprecationWarning, stacklevel=2) + warnings.warn( + "Rule.process_request should accept two arguments " + "(request, response), accepting only one is deprecated", + category=ScrapyDeprecationWarning, + stacklevel=2, + ) def _process_request(self, request, response): """ diff --git a/tests/test_command_shell.py b/tests/test_command_shell.py index 93fda2648..01f164727 100644 --- a/tests/test_command_shell.py +++ b/tests/test_command_shell.py @@ -56,7 +56,9 @@ class ShellTest(ProcessTest, SiteTest, unittest.TestCase): @defer.inlineCallbacks def test_redirect_not_follow_302(self): - _, out, _ = yield self.execute(['--no-redirect', self.url('/redirect-no-meta-refresh'), '-c', 'response.status']) + _, out, _ = yield self.execute( + ['--no-redirect', self.url('/redirect-no-meta-refresh'), '-c', 'response.status'] + ) assert out.strip().endswith(b'302') @defer.inlineCallbacks diff --git a/tests/test_crawler.py b/tests/test_crawler.py index ecc0cd7af..038fae323 100644 --- a/tests/test_crawler.py +++ b/tests/test_crawler.py @@ -305,8 +305,10 @@ class CrawlerProcessSubprocess(ScriptRunnerMixin, unittest.TestCase): def test_ipv6_default_name_resolver(self): log = self.run_script('default_name_resolver.py') self.assertIn('Spider closed (finished)', log) - self.assertIn("twisted.internet.error.DNSLookupError: DNS lookup failed: no results for hostname lookup: ::1.", log) self.assertIn("'downloader/exception_type_count/twisted.internet.error.DNSLookupError': 1,", log) + self.assertIn( + "twisted.internet.error.DNSLookupError: DNS lookup failed: no results for hostname lookup: ::1.", + log) def test_ipv6_alternative_name_resolver(self): log = self.run_script('alternative_name_resolver.py') diff --git a/tests/test_downloader_handlers.py b/tests/test_downloader_handlers.py index c1e6f744b..51deb20f4 100644 --- a/tests/test_downloader_handlers.py +++ b/tests/test_downloader_handlers.py @@ -493,7 +493,10 @@ class Http11TestCase(HttpTestCase): class Https11TestCase(Http11TestCase): scheme = 'https' - tls_log_message = 'SSL connection certificate: issuer "/C=IE/O=Scrapy/CN=localhost", subject "/C=IE/O=Scrapy/CN=localhost"' + tls_log_message = ( + 'SSL connection certificate: issuer "/C=IE/O=Scrapy/CN=localhost", ' + 'subject "/C=IE/O=Scrapy/CN=localhost"' + ) @defer.inlineCallbacks def test_tls_logging(self): @@ -542,7 +545,10 @@ class Https11InvalidDNSPattern(Https11TestCase): from service_identity.exceptions import CertificateError # noqa: F401 except ImportError: raise unittest.SkipTest("cryptography lib is too old") - self.tls_log_message = 'SSL connection certificate: issuer "/C=IE/O=Scrapy/CN=127.0.0.1", subject "/C=IE/O=Scrapy/CN=127.0.0.1"' + self.tls_log_message = ( + 'SSL connection certificate: issuer "/C=IE/O=Scrapy/CN=127.0.0.1", ' + 'subject "/C=IE/O=Scrapy/CN=127.0.0.1"' + ) super(Https11InvalidDNSPattern, self).setUp() diff --git a/tests/test_downloadermiddleware_httpcompression.py b/tests/test_downloadermiddleware_httpcompression.py index e86568bfb..87304d76c 100644 --- a/tests/test_downloadermiddleware_httpcompression.py +++ b/tests/test_downloadermiddleware_httpcompression.py @@ -124,7 +124,8 @@ class HttpCompressionTest(TestCase): 'Content-Encoding': 'gzip', } f = BytesIO() - plainbody = b"""
"""
+ html = (
+ b''
+ b'sample 2
'
+ )
response = HtmlResponse("http://example.com/index.html", body=html)
lx = self.extractor_cls(tags=None)
@@ -419,8 +422,10 @@ class Base:
[
Link(url='http://example.com/about.html', text=u'About us', fragment='', nofollow=False),
Link(url='http://example.com/follow.html', text=u'Follow this link', fragment='', nofollow=False),
- Link(url='http://example.com/nofollow.html', text=u'Dont follow this one', fragment='', nofollow=True),
- Link(url='http://example.com/nofollow2.html', text=u'Choose to follow or not', fragment='', nofollow=False),
+ Link(url='http://example.com/nofollow.html', text=u'Dont follow this one',
+ fragment='', nofollow=True),
+ Link(url='http://example.com/nofollow2.html', text=u'Choose to follow or not',
+ fragment='', nofollow=False),
Link(url='http://google.com/something', text=u'External link not to follow', nofollow=True),
]
)
@@ -433,8 +438,10 @@ class Base:
[
Link(url='http://example.com/about.html', text=u'About us', fragment='', nofollow=False),
Link(url='http://example.com/follow.html', text=u'Follow this link', fragment='', nofollow=False),
- Link(url='http://example.com/nofollow.html', text=u'Dont follow this one', fragment='', nofollow=True),
- Link(url='http://example.com/nofollow2.html', text=u'Choose to follow or not', fragment='', nofollow=False),
+ Link(url='http://example.com/nofollow.html', text=u'Dont follow this one',
+ fragment='', nofollow=True),
+ Link(url='http://example.com/nofollow2.html', text=u'Choose to follow or not',
+ fragment='', nofollow=False),
Link(url='http://google.com/something', text=u'External link not to follow', nofollow=True),
]
)
diff --git a/tests/test_pipeline_files.py b/tests/test_pipeline_files.py
index f155db4ce..34fc8dcb6 100644
--- a/tests/test_pipeline_files.py
+++ b/tests/test_pipeline_files.py
@@ -38,27 +38,36 @@ class FilesPipelineTestCase(unittest.TestCase):
def test_file_path(self):
file_path = self.pipeline.file_path
- self.assertEqual(file_path(Request("https://dev.mydeco.com/mydeco.pdf")),
- 'full/c9b564df929f4bc635bdd19fde4f3d4847c757c5.pdf')
- self.assertEqual(file_path(Request("http://www.maddiebrown.co.uk///catalogue-items//image_54642_12175_95307.txt")),
- 'full/4ce274dd83db0368bafd7e406f382ae088e39219.txt')
- self.assertEqual(file_path(Request("https://dev.mydeco.com/two/dirs/with%20spaces%2Bsigns.doc")),
- 'full/94ccc495a17b9ac5d40e3eabf3afcb8c2c9b9e1a.doc')
- self.assertEqual(file_path(Request("http://www.dfsonline.co.uk/get_prod_image.php?img=status_0907_mdm.jpg")),
- 'full/4507be485f38b0da8a0be9eb2e1dfab8a19223f2.jpg')
- self.assertEqual(file_path(Request("http://www.dorma.co.uk/images/product_details/2532/")),
- 'full/97ee6f8a46cbbb418ea91502fd24176865cf39b2')
- self.assertEqual(file_path(Request("http://www.dorma.co.uk/images/product_details/2532")),
- 'full/244e0dd7d96a3b7b01f54eded250c9e272577aa1')
- self.assertEqual(file_path(Request("http://www.dorma.co.uk/images/product_details/2532"),
- response=Response("http://www.dorma.co.uk/images/product_details/2532"),
- info=object()),
- 'full/244e0dd7d96a3b7b01f54eded250c9e272577aa1')
- self.assertEqual(file_path(Request("http://www.dfsonline.co.uk/get_prod_image.php?img=status_0907_mdm.jpg.bohaha")),
- 'full/76c00cef2ef669ae65052661f68d451162829507')
- self.assertEqual(file_path(Request("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAR0AAACxCAMAAADOHZloAAACClBMVEX/\
+ self.assertEqual(
+ file_path(Request("https://dev.mydeco.com/mydeco.pdf")),
+ 'full/c9b564df929f4bc635bdd19fde4f3d4847c757c5.pdf')
+ self.assertEqual(
+ file_path(Request("http://www.maddiebrown.co.uk///catalogue-items//image_54642_12175_95307.txt")),
+ 'full/4ce274dd83db0368bafd7e406f382ae088e39219.txt')
+ self.assertEqual(
+ file_path(Request("https://dev.mydeco.com/two/dirs/with%20spaces%2Bsigns.doc")),
+ 'full/94ccc495a17b9ac5d40e3eabf3afcb8c2c9b9e1a.doc')
+ self.assertEqual(
+ file_path(Request("http://www.dfsonline.co.uk/get_prod_image.php?img=status_0907_mdm.jpg")),
+ 'full/4507be485f38b0da8a0be9eb2e1dfab8a19223f2.jpg')
+ self.assertEqual(
+ file_path(Request("http://www.dorma.co.uk/images/product_details/2532/")),
+ 'full/97ee6f8a46cbbb418ea91502fd24176865cf39b2')
+ self.assertEqual(
+ file_path(Request("http://www.dorma.co.uk/images/product_details/2532")),
+ 'full/244e0dd7d96a3b7b01f54eded250c9e272577aa1')
+ self.assertEqual(
+ file_path(Request("http://www.dorma.co.uk/images/product_details/2532"),
+ response=Response("http://www.dorma.co.uk/images/product_details/2532"),
+ info=object()),
+ 'full/244e0dd7d96a3b7b01f54eded250c9e272577aa1')
+ self.assertEqual(
+ file_path(Request("http://www.dfsonline.co.uk/get_prod_image.php?img=status_0907_mdm.jpg.bohaha")),
+ 'full/76c00cef2ef669ae65052661f68d451162829507')
+ self.assertEqual(
+ file_path(Request("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAR0AAACxCAMAAADOHZloAAACClBMVEX/\
//+F0tzCwMK76ZKQ21AMqr7oAAC96JvD5aWM2kvZ78J0N7fmAAC46Y4Ap7y")),
- 'full/178059cbeba2e34120a67f2dc1afc3ecc09b61cb.png')
+ 'full/178059cbeba2e34120a67f2dc1afc3ecc09b61cb.png')
def test_fs_store(self):
assert isinstance(self.pipeline.store, FSFilesStore)
diff --git a/tests/test_pipeline_images.py b/tests/test_pipeline_images.py
index 76aea470f..8ef27fce7 100644
--- a/tests/test_pipeline_images.py
+++ b/tests/test_pipeline_images.py
@@ -41,22 +41,29 @@ class ImagesPipelineTestCase(unittest.TestCase):
def test_file_path(self):
file_path = self.pipeline.file_path
- self.assertEqual(file_path(Request("https://dev.mydeco.com/mydeco.gif")),
- 'full/3fd165099d8e71b8a48b2683946e64dbfad8b52d.jpg')
- self.assertEqual(file_path(Request("http://www.maddiebrown.co.uk///catalogue-items//image_54642_12175_95307.jpg")),
- 'full/0ffcd85d563bca45e2f90becd0ca737bc58a00b2.jpg')
- self.assertEqual(file_path(Request("https://dev.mydeco.com/two/dirs/with%20spaces%2Bsigns.gif")),
- 'full/b250e3a74fff2e4703e310048a5b13eba79379d2.jpg')
- self.assertEqual(file_path(Request("http://www.dfsonline.co.uk/get_prod_image.php?img=status_0907_mdm.jpg")),
- 'full/4507be485f38b0da8a0be9eb2e1dfab8a19223f2.jpg')
- self.assertEqual(file_path(Request("http://www.dorma.co.uk/images/product_details/2532/")),
- 'full/97ee6f8a46cbbb418ea91502fd24176865cf39b2.jpg')
- self.assertEqual(file_path(Request("http://www.dorma.co.uk/images/product_details/2532")),
- 'full/244e0dd7d96a3b7b01f54eded250c9e272577aa1.jpg')
- self.assertEqual(file_path(Request("http://www.dorma.co.uk/images/product_details/2532"),
- response=Response("http://www.dorma.co.uk/images/product_details/2532"),
- info=object()),
- 'full/244e0dd7d96a3b7b01f54eded250c9e272577aa1.jpg')
+ self.assertEqual(
+ file_path(Request("https://dev.mydeco.com/mydeco.gif")),
+ 'full/3fd165099d8e71b8a48b2683946e64dbfad8b52d.jpg')
+ self.assertEqual(
+ file_path(Request("http://www.maddiebrown.co.uk///catalogue-items//image_54642_12175_95307.jpg")),
+ 'full/0ffcd85d563bca45e2f90becd0ca737bc58a00b2.jpg')
+ self.assertEqual(
+ file_path(Request("https://dev.mydeco.com/two/dirs/with%20spaces%2Bsigns.gif")),
+ 'full/b250e3a74fff2e4703e310048a5b13eba79379d2.jpg')
+ self.assertEqual(
+ file_path(Request("http://www.dfsonline.co.uk/get_prod_image.php?img=status_0907_mdm.jpg")),
+ 'full/4507be485f38b0da8a0be9eb2e1dfab8a19223f2.jpg')
+ self.assertEqual(
+ file_path(Request("http://www.dorma.co.uk/images/product_details/2532/")),
+ 'full/97ee6f8a46cbbb418ea91502fd24176865cf39b2.jpg')
+ self.assertEqual(
+ file_path(Request("http://www.dorma.co.uk/images/product_details/2532")),
+ 'full/244e0dd7d96a3b7b01f54eded250c9e272577aa1.jpg')
+ self.assertEqual(
+ file_path(Request("http://www.dorma.co.uk/images/product_details/2532"),
+ response=Response("http://www.dorma.co.uk/images/product_details/2532"),
+ info=object()),
+ 'full/244e0dd7d96a3b7b01f54eded250c9e272577aa1.jpg')
def test_thumbnail_name(self):
thumb_path = self.pipeline.thumb_path
diff --git a/tests/test_request_cb_kwargs.py b/tests/test_request_cb_kwargs.py
index a3ddd50f4..bd49179aa 100644
--- a/tests/test_request_cb_kwargs.py
+++ b/tests/test_request_cb_kwargs.py
@@ -158,6 +158,12 @@ class CallbackKeywordArgumentsTestCase(TestCase):
if key in line.getMessage():
exceptions[key] = line
self.assertEqual(exceptions['takes_less'].exc_info[0], TypeError)
- self.assertEqual(str(exceptions['takes_less'].exc_info[1]), "parse_takes_less() got an unexpected keyword argument 'number'")
+ self.assertEqual(
+ str(exceptions['takes_less'].exc_info[1]),
+ "parse_takes_less() got an unexpected keyword argument 'number'"
+ )
self.assertEqual(exceptions['takes_more'].exc_info[0], TypeError)
- self.assertEqual(str(exceptions['takes_more'].exc_info[1]), "parse_takes_more() missing 1 required positional argument: 'other'")
+ self.assertEqual(
+ str(exceptions['takes_more'].exc_info[1]),
+ "parse_takes_more() missing 1 required positional argument: 'other'"
+ )
diff --git a/tests/test_responsetypes.py b/tests/test_responsetypes.py
index 9e63ac924..dd19a69d5 100644
--- a/tests/test_responsetypes.py
+++ b/tests/test_responsetypes.py
@@ -63,8 +63,9 @@ class ResponseTypesTest(unittest.TestCase):
def test_from_headers(self):
mappings = [
({'Content-Type': ['text/html; charset=utf-8']}, HtmlResponse),
- ({'Content-Type': ['application/octet-stream'], 'Content-Disposition': ['attachment; filename=data.txt']}, TextResponse),
({'Content-Type': ['text/html; charset=utf-8'], 'Content-Encoding': ['gzip']}, Response),
+ ({'Content-Type': ['application/octet-stream'],
+ 'Content-Disposition': ['attachment; filename=data.txt']}, TextResponse),
]
for source, cls in mappings:
source = Headers(source)
@@ -76,8 +77,10 @@ class ResponseTypesTest(unittest.TestCase):
mappings = [
({'url': 'http://www.example.com/data.csv'}, TextResponse),
# headers takes precedence over url
- ({'headers': Headers({'Content-Type': ['text/html; charset=utf-8']}), 'url': 'http://www.example.com/item/'}, HtmlResponse),
- ({'headers': Headers({'Content-Disposition': ['attachment; filename="data.xml.gz"']}), 'url': 'http://www.example.com/page/'}, Response),
+ ({'headers': Headers({'Content-Type': ['text/html; charset=utf-8']}),
+ 'url': 'http://www.example.com/item/'}, HtmlResponse),
+ ({'headers': Headers({'Content-Disposition': ['attachment; filename="data.xml.gz"']}),
+ 'url': 'http://www.example.com/page/'}, Response),
]
diff --git a/tests/test_selector.py b/tests/test_selector.py
index 65b0f5860..bcf653444 100644
--- a/tests/test_selector.py
+++ b/tests/test_selector.py
@@ -19,18 +19,26 @@ class SelectorTestCase(unittest.TestCase):
for x in xl:
assert isinstance(x, Selector)
- self.assertEqual(sel.xpath('//input').getall(),
- [x.get() for x in sel.xpath('//input')])
-
- self.assertEqual([x.get() for x in sel.xpath("//input[@name='a']/@name")],
- [u'a'])
- self.assertEqual([x.get() for x in sel.xpath("number(concat(//input[@name='a']/@value, //input[@name='b']/@value))")],
- [u'12.0'])
-
- self.assertEqual(sel.xpath("concat('xpath', 'rules')").getall(),
- [u'xpathrules'])
- self.assertEqual([x.get() for x in sel.xpath("concat(//input[@name='a']/@value, //input[@name='b']/@value)")],
- [u'12'])
+ self.assertEqual(
+ sel.xpath('//input').getall(),
+ [x.get() for x in sel.xpath('//input')]
+ )
+ self.assertEqual(
+ [x.get() for x in sel.xpath("//input[@name='a']/@name")],
+ [u'a']
+ )
+ self.assertEqual(
+ [x.get() for x in sel.xpath("number(concat(//input[@name='a']/@value, //input[@name='b']/@value))")],
+ [u'12.0']
+ )
+ self.assertEqual(
+ sel.xpath("concat('xpath', 'rules')").getall(),
+ [u'xpathrules']
+ )
+ self.assertEqual(
+ [x.get() for x in sel.xpath("concat(//input[@name='a']/@value, //input[@name='b']/@value)")],
+ [u'12']
+ )
def test_root_base_url(self):
body = b''
diff --git a/tests/test_spider.py b/tests/test_spider.py
index bb00c8f42..805d70459 100644
--- a/tests/test_spider.py
+++ b/tests/test_spider.py
@@ -120,7 +120,9 @@ class XMLFeedSpiderTest(SpiderTest):
body = b"""