MCPcopy Index your code
hub / github.com/python/mypy / parse_test_data

Function parse_test_data

mypy/test/data.py:459–501  ·  view source on GitHub ↗

Parse a list of lines that represent a sequence of test items.

(raw_data: str, name: str)

Source from the content-addressed store, hash-verified

457
458
459def parse_test_data(raw_data: str, name: str) -> list[TestItem]:
460 """Parse a list of lines that represent a sequence of test items."""
461
462 lines = ["", "[case " + name + "]"] + raw_data.split("\n")
463 ret: list[TestItem] = []
464 data: list[str] = []
465
466 id: str | None = None
467 arg: str | None = None
468
469 i = 0
470 i0 = 0
471 while i < len(lines):
472 s = lines[i].strip()
473
474 if lines[i].startswith("[") and s.endswith("]"):
475 if id:
476 data = collapse_line_continuation(data)
477 data = strip_list(data)
478 ret.append(TestItem(id, arg, data, i0 + 1, i))
479
480 i0 = i
481 id = s[1:-1]
482 arg = None
483 if " " in id:
484 arg = id[id.index(" ") + 1 :]
485 id = id[: id.index(" ")]
486 data = []
487 elif lines[i].startswith("\\["):
488 data.append(lines[i][1:])
489 elif not lines[i].startswith("--"):
490 data.append(lines[i])
491 elif lines[i].startswith("----"):
492 data.append(lines[i][2:])
493 i += 1
494
495 # Process the last item.
496 if id:
497 data = collapse_line_continuation(data)
498 data = strip_list(data)
499 ret.append(TestItem(id, arg, data, i0 + 1, i - 1))
500
501 return ret
502
503
504def strip_list(l: list[str]) -> list[str]:

Callers 2

_iter_fixesFunction · 0.90
parse_test_caseFunction · 0.85

Calls 10

lenFunction · 0.85
strip_listFunction · 0.85
TestItemClass · 0.85
splitMethod · 0.80
stripMethod · 0.80
appendMethod · 0.80
indexMethod · 0.80
startswithMethod · 0.45
endswithMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…