def check_coverage(
        self,
        text: str,
        *,
        lines: Sequence[TLineNo] | Sequence[list[TLineNo]] | None = None,
        missing: str = "",
        report: str = "",
        excludes: Iterable[str] | None = None,
        partials: Iterable[str] = (),
        branchz: str | None = None,
        branchz_missing: str | None = None,
        branch: bool = True,
    ) -> Coverage:
        """Check the coverage measurement of `text`.

        The source `text` is run and measured.  `lines` are the line numbers
        that are executable, or a list of possible line numbers, any of which
        could match. `missing` are the lines not executed, `excludes` are
        regexes to match against for excluding lines, and `report` is the text
        of the measurement report.

        For branch measurement, `branchz` is a string that can be decoded into
        arcs in the code (see `arcz_to_arcs` for the encoding scheme).
        `branchz_missing` are the arcs that are not executed.

        Returns the Coverage object, in case you want to poke at it some more.

        """
        __tracebackhide__ = True    # pytest, please don't show me this function.

        # We write the code into a file so that we can import it.
        # Coverage.py wants to deal with things as modules with file names.
        modname = self.get_module_name()

        self.make_file(modname + ".py", text)

        branches = branches_missing = None
        if branchz is not None:
            branches = arcz_to_arcs(branchz)
        if branchz_missing is not None:
            branches_missing = arcz_to_arcs(branchz_missing)

        # Start up coverage.py.
        cov = coverage.Coverage(branch=branch)
        cov.erase()
        for exc in excludes or []:
            cov.exclude(exc)
        for par in partials or []:
            cov.exclude(par, which='partial')

        mod = self.start_import_stop(cov, modname)

        # Clean up our side effects
        del sys.modules[modname]

        # Get the analysis results, and check that they are right.
        analysis = cov._analyze(mod)
        statements = sorted(analysis.statements)
        if lines:
            if isinstance(lines[0], int):
                # lines is just a list of numbers, it must match the statements
                # found in the code.
                assert statements == lines, f"lines: {statements!r} != {lines!r}"
            else:
                # lines is a list of possible line number lists, one of them
                # must match.
                for i, line_list in enumerate(lines):   # pylint: disable=unused-variable
                    if statements == line_list:
                        # PYVERSIONS: we might be able to trim down multiple
                        # lines passed into this function.
                        # Uncomment this code, run the whole test suite, then
                        # sort /tmp/check_coverage_multi_line.out to group the
                        # tests together and see if any of the `lines` elements
                        # haven't been used.
                        # One of the calls in test_successful_coverage passes
                        # three `lines` elements, only one of which is right.
                        # We need to keep that test until we can delete the
                        # multi-lines option entirely.
                        #
                        # import inspect, platform
                        # frinfo = inspect.getframeinfo(inspect.currentframe().f_back)
                        # version = "{} {}.{}".format(
                        #     platform.python_implementation(),
                        #     *sys.version_info[:2],
                        # )
                        # with open("/tmp/check_coverage_multi_line.out", "a") as f:
                        #     print(
                        #         f"{frinfo.filename}@{frinfo.lineno}: "
                        #         + f"lines {i + 1}/{len(lines)}: {version}",
                        #         file=f,
                        #     )
                        break
                else:
                    assert False, f"None of the lines choices matched {statements!r}"

            missing_formatted = analysis.missing_formatted()
            msg = f"missing: {missing_formatted!r} != {missing!r}"
            assert missing_formatted == missing, msg

        if branches is not None:
            trimmed_arcs = branches_to_arcs(arcs_to_branches(analysis.arc_possibilities))
            assert branches == trimmed_arcs, (
                f"Wrong possible branches: {branches} != {trimmed_arcs}"
            )
            if branches_missing is not None:
                assert set(branches_missing) <= set(branches), (
                    f"{branches_missing = }, has non-branches in it."
                )
                analysis_missing = branches_to_arcs(analysis.missing_branch_arcs())
                assert branches_missing == analysis_missing, (
                    f"Wrong missing branches: {branches_missing} != {analysis_missing}"
                )

        if report:
            frep = io.StringIO()
            cov.report(mod, file=frep, show_missing=True)
            rep = " ".join(frep.getvalue().split("\n")[2].split()[1:])
            assert report == rep, f"{report!r} != {rep!r}"

        return cov
Check the coverage measurement of `text`.

        The source `text` is run and measured.  `lines` are the line numbers
        that are executable, or a list of possible line numbers, any of which
        could match. `missing` are the lines not executed, `excludes` are
        regexes to match against for excluding lines, and `report` is the text
        of the measurement report.

        For branch measurement, `branchz` is a string that can be decoded into
        arcs in the code (see `arcz_to_arcs` for the encoding scheme).
        `branchz_missing` are the arcs that are not executed.

        Returns the Coverage object, in case you want to poke at it some more.

        
tests/coveragetest.py