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

Function split_test_cases

mypy/test/data.py:685–729  ·  view source on GitHub ↗

Iterate over raw test cases in file, at collection time, ignoring sub items. The collection phase is slow, so any heavy processing should be deferred to after uninteresting tests are filtered (when using -k PATTERN switch).

(
    parent: DataFileCollector, suite: DataSuite, file: str
)

Source from the content-addressed store, hash-verified

683
684
685def split_test_cases(
686 parent: DataFileCollector, suite: DataSuite, file: str
687) -> Iterator[DataDrivenTestCase]:
688 """Iterate over raw test cases in file, at collection time, ignoring sub items.
689
690 The collection phase is slow, so any heavy processing should be deferred to after
691 uninteresting tests are filtered (when using -k PATTERN switch).
692 """
693 with open(file, encoding="utf-8") as f:
694 data = f.read()
695 cases = re.split(r"^\[case ([^]+)]+)\][ \t]*$\n", data, flags=re.DOTALL | re.MULTILINE)
696 cases_iter = iter(cases)
697 line_no = next(cases_iter).count("\n") + 1
698 test_names = set()
699 for case_id in cases_iter:
700 data = next(cases_iter)
701
702 m = _case_name_pattern.fullmatch(case_id)
703 if not m:
704 raise RuntimeError(f"Invalid testcase id {case_id!r}")
705 name = m.group("name")
706 if name in test_names:
707 raise RuntimeError(
708 'Found a duplicate test name "{}" in {} on line {}'.format(
709 name, parent.name, line_no
710 )
711 )
712 yield DataDrivenTestCase.from_parent(
713 parent=parent,
714 suite=suite,
715 file=file,
716 name=add_test_name_suffix(name, suite.test_name_suffix),
717 writescache=bool(m.group("writescache")),
718 only_when=m.group("only_when"),
719 platform=m.group("platform"),
720 skip=bool(m.group("skip")),
721 xfail=bool(m.group("xfail")),
722 normalize_output=not m.group("skip_path_normalization"),
723 data=data,
724 line=line_no,
725 )
726 line_no += data.count("\n") + 1
727
728 # Record existing tests to prevent duplicates:
729 test_names.update({name})
730
731
732class DataSuiteCollector(pytest.Class):

Callers 1

collectMethod · 0.85

Calls 13

iterFunction · 0.85
nextFunction · 0.85
setClass · 0.85
RuntimeErrorClass · 0.85
add_test_name_suffixFunction · 0.85
boolClass · 0.85
splitMethod · 0.80
groupMethod · 0.80
from_parentMethod · 0.80
readMethod · 0.45
countMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…