Parse comments like '# flags: --foo' in a test case.
(
program_text: str, testcase: DataDrivenTestCase, incremental_step: int
)
| 384 | |
| 385 | |
| 386 | def parse_options( |
| 387 | program_text: str, testcase: DataDrivenTestCase, incremental_step: int |
| 388 | ) -> Options: |
| 389 | """Parse comments like '# flags: --foo' in a test case.""" |
| 390 | options = Options() |
| 391 | flags = re.search("# flags: (.*)$", program_text, flags=re.MULTILINE) |
| 392 | if incremental_step > 1: |
| 393 | flags2 = re.search(f"# flags{incremental_step}: (.*)$", program_text, flags=re.MULTILINE) |
| 394 | if flags2: |
| 395 | flags = flags2 |
| 396 | |
| 397 | if flags: |
| 398 | flag_list = flags.group(1).split() |
| 399 | flag_list.append("--no-site-packages") # the tests shouldn't need an installed Python |
| 400 | targets, options = process_options(flag_list, require_targets=False) |
| 401 | if targets: |
| 402 | # TODO: support specifying targets via the flags pragma |
| 403 | raise RuntimeError("Specifying targets via the flags pragma is not supported.") |
| 404 | if "--show-error-codes" not in flag_list: |
| 405 | options.hide_error_codes = True |
| 406 | else: |
| 407 | flag_list = [] |
| 408 | options = Options() |
| 409 | options.error_summary = False |
| 410 | options.hide_error_codes = True |
| 411 | |
| 412 | # Allow custom python version to override testfile_pyversion. |
| 413 | if all(flag.split("=")[0] != "--python-version" for flag in flag_list): |
| 414 | options.python_version = testfile_pyversion(testcase.file) |
| 415 | |
| 416 | if testcase.config.getoption("--mypy-verbose"): |
| 417 | options.verbosity = testcase.config.getoption("--mypy-verbose") |
| 418 | if testcase.config.getoption("--mypy-num-workers"): |
| 419 | options.num_workers = testcase.config.getoption("--mypy-num-workers") |
| 420 | |
| 421 | return options |
| 422 | |
| 423 | |
| 424 | def split_lines(*streams: bytes) -> list[str]: |
searching dependent graphs…