8000 Relax SpiderLoader interface check by curita · Pull Request #1187 · scrapy/scrapy · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Relax SpiderLoader interface check #1187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions scrapy/crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import warnings

from twisted.internet import reactor, defer
from zope.interface.verify import verifyClass
from zope.interface.verify import verifyClass, DoesNotImplement

from scrapy.core.engine import ExecutionEngine
from scrapy.resolver import CachingThreadedResolver
Expand Down Expand Up @@ -195,5 +195,13 @@ def _get_spider_loader(settings):
cls_path = settings.get('SPIDER_MANAGER_CLASS',
settings.get('SPIDER_LOADER_CLASS'))
loader_cls = load_object(cls_path)
verifyClass(ISpiderLoader, loader_cls)
try:
verifyClass(ISpiderLoader, loader_cls)
except DoesNotImplement:
warnings.warn(
'SPIDER_LOADER_CLASS (previously named SPIDER_MANAGER_CLASS) does '
'not fully implement scrapy.interfaces.ISpiderLoader interface. '
'Please add all missing methods to avoid unexpected runtime errors.',
category=ScrapyDeprecationWarning, stacklevel=2
)
return loader_cls.from_settings(settings.frozencopy())
B07B
8 changes: 5 additions & 3 deletions tests/test_crawler.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import warnings
import unittest

from zope.interface.verify import DoesNotImplement

from scrapy.crawler import Crawler, CrawlerRunner
from scrapy.settings import Settings, default_settings
from scrapy.spiderloader import SpiderLoader
Expand Down Expand Up @@ -71,8 +69,12 @@ def test_spider_manager_verify_interface(self):
settings = Settings({
'SPIDER_LOADER_CLASS': 'tests.test_crawler.SpiderLoaderWithWrongInterface'
})
with self.assertRaises(DoesNotImplement):
with warnings.catch_warnings(record=True) as w, \
self.assertRaises(AttributeError):
CrawlerRunner(settings)
self.assertEqual(len(w), 1)
self.assertIn("SPIDER_LOADER_CLASS", str(w[0].message))
self.assertIn("scrapy.interfaces.ISpiderLoader", str(w[0].message))

def test_crawler_runner_accepts_dict(self):
runner = CrawlerRunner({'foo': 'bar'})
Expand Down
0