Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def make_data(settings):
crawler = get_crawler(settings_dict=settings)
spider = Spider.from_crawler(crawler, "example.com")
return {
"stats": crawler.stats.get_stats(),
"crawler": crawler,
"spider": spider,
"runner": SpiderMonitorRunner(spider=spider),
"job": None,
}
from __future__ import absolute_import
from functools import partial
from unittest import TestCase
from scrapy.utils.test import get_crawler
from scrapy import Spider
from spidermon.contrib.scrapy.extensions import Spidermon
from spidermon.contrib.scrapy.runners import SpiderMonitorRunner
class TestSpiderMonitorRunner(SpiderMonitorRunner):
__test__ = False
def run_monitors(self):
self.result.next_step()
res = self.suite.run(self.result)
raise AssertionError((res.failures, res.errors))
def _test_run_suites(self, spider, suites):
data = self._generate_data_for_spider(spider)
for suite in suites:
runner = TestSpiderMonitorRunner(spider=spider)
runner.run(suite, **data)
class TestData(object):
def _make_data(settings=None):
crawler = Crawler(Spider, settings=settings)
spider = Spider("dummy")
return {
"stats": crawler.stats.get_stats(),
"crawler": crawler,
"spider": spider,
"runner": SpiderMonitorRunner(spider=spider),
"job": None,
}
def _run_suites(self, spider, suites):
data = self._generate_data_for_spider(spider)
for suite in suites:
runner = SpiderMonitorRunner(spider=spider)
runner.run(suite, **data)