Return target BuildSources for a test case. Normally, the unit tests will check all files included in the test case. This differs from how testcheck works by default, as dmypy doesn't currently support following imports. You can override this behavior and instruct t
(
self, program_text: str, incremental_step: int, options: Options
)
| 255 | return a, triggered |
| 256 | |
| 257 | def parse_sources( |
| 258 | self, program_text: str, incremental_step: int, options: Options |
| 259 | ) -> list[BuildSource]: |
| 260 | """Return target BuildSources for a test case. |
| 261 | |
| 262 | Normally, the unit tests will check all files included in the test |
| 263 | case. This differs from how testcheck works by default, as dmypy |
| 264 | doesn't currently support following imports. |
| 265 | |
| 266 | You can override this behavior and instruct the tests to check |
| 267 | multiple modules by using a comment like this in the test case |
| 268 | input: |
| 269 | |
| 270 | # cmd: main a.py |
| 271 | |
| 272 | You can also use `# cmdN:` to have a different cmd for incremental |
| 273 | step N (2, 3, ...). |
| 274 | |
| 275 | """ |
| 276 | m = re.search("# cmd: mypy ([a-zA-Z0-9_./ ]+)$", program_text, flags=re.MULTILINE) |
| 277 | regex = f"# cmd{incremental_step}: mypy ([a-zA-Z0-9_./ ]+)$" |
| 278 | alt_m = re.search(regex, program_text, flags=re.MULTILINE) |
| 279 | if alt_m is not None: |
| 280 | # Optionally return a different command if in a later step |
| 281 | # of incremental mode, otherwise default to reusing the |
| 282 | # original cmd. |
| 283 | m = alt_m |
| 284 | |
| 285 | if m: |
| 286 | # The test case wants to use a non-default set of files. |
| 287 | paths = [os.path.join(test_temp_dir, path) for path in m.group(1).strip().split()] |
| 288 | return create_source_list(paths, options) |
| 289 | else: |
| 290 | base = BuildSource(os.path.join(test_temp_dir, "main"), "__main__", None) |
| 291 | # Use expand_dir instead of create_source_list to avoid complaints |
| 292 | # when there aren't any .py files in an increment |
| 293 | return [base] + create_source_list([test_temp_dir], options, allow_empty_dir=True) |
| 294 | |
| 295 | def maybe_suggest(self, step: int, server: Server, src: str, tmp_dir: str) -> list[str]: |
| 296 | output: list[str] = [] |
no test coverage detected