Replace custom_settings in the given spider file with the given text.
(
proj_mod_path: Path, spider_name: str, text: str
)
| 137 | |
| 138 | @staticmethod |
| 139 | def _replace_custom_settings( |
| 140 | proj_mod_path: Path, spider_name: str, text: str |
| 141 | ) -> None: |
| 142 | """Replace custom_settings in the given spider file with the given text.""" |
| 143 | spider_path = proj_mod_path / "spiders" / f"{spider_name}.py" |
| 144 | with spider_path.open("r+", encoding="utf-8") as f: |
| 145 | content = f.read() |
| 146 | content = content.replace( |
| 147 | "custom_settings = {}", f"custom_settings = {text}" |
| 148 | ) |
| 149 | f.seek(0) |
| 150 | f.write(content) |
| 151 | f.truncate() |
| 152 | |
| 153 | def _assert_spider_works(self, msg: str, proj_path: Path, *args: str) -> None: |
| 154 | """The command uses the expected *CrawlerProcess, the spider works.""" |
no test coverage detected