MCPcopy
hub / github.com/scrapy/scrapy / run_and_export

Method run_and_export

tests/test_feedexport.py:302–331  ·  view source on GitHub ↗

Run spider with specified settings; return exported data.

(
        self, spider_cls: type[Spider], settings: dict[str, Any]
    )

Source from the content-addressed store, hash-verified

300
301class TestFeedExport(TestFeedExportBase):
302 async def run_and_export(
303 self, spider_cls: type[Spider], settings: dict[str, Any]
304 ) -> dict[str, Any]:
305 """Run spider with specified settings; return exported data."""
306
307 FEEDS = settings.get("FEEDS") or {}
308 settings["FEEDS"] = {
309 printf_escape(path_to_url(file_path)): feed_options
310 for file_path, feed_options in FEEDS.items()
311 }
312
313 content: dict[str, Any] = {}
314 try:
315 spider_cls.start_urls = [self.mockserver.url("/")]
316 crawler = get_crawler(spider_cls, settings)
317 await crawler.crawl_async()
318
319 for file_path, feed_options in FEEDS.items():
320 content[feed_options["format"]] = (
321 Path(file_path).read_bytes() if Path(file_path).exists() else None
322 )
323
324 finally:
325 for file_path in FEEDS:
326 if not Path(file_path).exists():
327 continue
328
329 Path(file_path).unlink()
330
331 return content
332
333 async def assertExportedCsv(
334 self,

Callers

nothing calls this directly

Calls 7

get_crawlerFunction · 0.90
printf_escapeFunction · 0.85
path_to_urlFunction · 0.85
itemsMethod · 0.80
crawl_asyncMethod · 0.80
getMethod · 0.45
urlMethod · 0.45

Tested by

no test coverage detected