(self, args: list[str], opts: argparse.Namespace)
| 71 | ) |
| 72 | |
| 73 | def run(self, args: list[str], opts: argparse.Namespace) -> None: |
| 74 | # load contracts |
| 75 | assert self.settings is not None |
| 76 | contracts = build_component_list( |
| 77 | self.settings.get_component_priority_dict_with_base("SPIDER_CONTRACTS") |
| 78 | ) |
| 79 | conman = ContractsManager(load_object(c) for c in contracts) |
| 80 | runner = TextTestRunner(verbosity=2 if opts.verbose else 1) |
| 81 | result = TextTestResult(runner.stream, runner.descriptions, runner.verbosity) |
| 82 | |
| 83 | # contract requests |
| 84 | contract_reqs = defaultdict(list) |
| 85 | |
| 86 | assert self.crawler_process |
| 87 | spider_loader = self.crawler_process.spider_loader |
| 88 | |
| 89 | async def start(self: Spider) -> AsyncIterator[Any]: |
| 90 | for request in conman.from_spider(self, result): |
| 91 | yield request |
| 92 | |
| 93 | with set_environ(SCRAPY_CHECK="true"): |
| 94 | for spidername in args or spider_loader.list(): |
| 95 | spidercls = spider_loader.load(spidername) |
| 96 | spidercls.start = start # type: ignore[method-assign] |
| 97 | |
| 98 | tested_methods = conman.tested_methods_from_spidercls(spidercls) |
| 99 | if opts.list: |
| 100 | for method in tested_methods: |
| 101 | contract_reqs[spidercls.name].append(method) |
| 102 | elif tested_methods: |
| 103 | self.crawler_process.crawl(spidercls) |
| 104 | |
| 105 | # start checks |
| 106 | if opts.list: |
| 107 | print( |
| 108 | "\n".join( |
| 109 | f"{spider}\n" |
| 110 | + "\n".join(f" * {method}" for method in sorted(methods)) |
| 111 | for spider, methods in sorted(contract_reqs.items()) |
| 112 | if methods or opts.verbose |
| 113 | ) |
| 114 | ) |
| 115 | else: |
| 116 | start_time = time.monotonic() |
| 117 | self.crawler_process.start() |
| 118 | stop = time.monotonic() |
| 119 | |
| 120 | result.printErrors() |
| 121 | result.printSummary(start_time, stop) |
| 122 | self.exitcode = int(not result.wasSuccessful()) |
nothing calls this directly
no test coverage detected