MCPcopy
hub / github.com/scrapy/scrapy / test_overwrite_output

Method test_overwrite_output

tests/test_command_crawl.py:62–89  ·  view source on GitHub ↗
(self, proj_path: Path)

Source from the content-addressed store, hash-verified

60 assert "[myspider] DEBUG: FEEDS: {'example.json': {'format': 'json'}}" in log
61
62 def test_overwrite_output(self, proj_path: Path) -> None:
63 spider_code = """
64import json
65import scrapy
66
67class MySpider(scrapy.Spider):
68 name = 'myspider'
69
70 async def start(self):
71 self.logger.debug(
72 'FEEDS: {}'.format(
73 json.dumps(self.settings.getdict('FEEDS'), sort_keys=True)
74 )
75 )
76 return
77 yield
78"""
79 j = proj_path / "example.json"
80 j.write_text("not empty", encoding="utf-8")
81 args = ["-O", "example.json"]
82 log = self.get_log(spider_code, proj_path, args=args)
83 assert (
84 '[myspider] DEBUG: FEEDS: {"example.json": {"format": "json", "overwrite": true}}'
85 in log
86 )
87 with j.open(encoding="utf-8") as f2:
88 first_line = f2.readline()
89 assert first_line != "not empty"
90
91 def test_output_and_overwrite_output(self, proj_path: Path) -> None:
92 spider_code = """

Callers

nothing calls this directly

Calls 2

get_logMethod · 0.95
openMethod · 0.45

Tested by

no test coverage detected