Run spider with specified settings; return exported data.
(
self, spider_cls: type[Spider], settings: dict[str, Any]
)
| 300 | |
| 301 | class 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, |
nothing calls this directly
no test coverage detected