MCPcopy
hub / github.com/pytest-dev/pytest / _match_lines

Method _match_lines

src/_pytest/pytester.py:1679–1744  ·  view source on GitHub ↗

Underlying implementation of ``fnmatch_lines`` and ``re_match_lines``. :param Sequence[str] lines2: List of string patterns to match. The actual format depends on ``match_func``. :param match_func: A callable ``match_func(line, pattern)`` where li

(
        self,
        lines2: Sequence[str],
        match_func: Callable[[str, str], bool],
        match_nickname: str,
        *,
        consecutive: bool = False,
    )

Source from the content-addressed store, hash-verified

1677 )
1678
1679 def _match_lines(
1680 self,
1681 lines2: Sequence[str],
1682 match_func: Callable[[str, str], bool],
1683 match_nickname: str,
1684 *,
1685 consecutive: bool = False,
1686 ) -> None:
1687 """Underlying implementation of ``fnmatch_lines`` and ``re_match_lines``.
1688
1689 :param Sequence[str] lines2:
1690 List of string patterns to match. The actual format depends on
1691 ``match_func``.
1692 :param match_func:
1693 A callable ``match_func(line, pattern)`` where line is the
1694 captured line from stdout/stderr and pattern is the matching
1695 pattern.
1696 :param str match_nickname:
1697 The nickname for the match function that will be logged to stdout
1698 when a match occurs.
1699 :param consecutive:
1700 Match lines consecutively?
1701 """
1702 if not isinstance(lines2, collections.abc.Sequence):
1703 raise TypeError(f"invalid type for lines2: {type(lines2).__name__}")
1704 lines2 = self._getlines(lines2)
1705 lines1 = self.lines[:]
1706 extralines = []
1707 __tracebackhide__ = True
1708 wnick = len(match_nickname) + 1
1709 started = False
1710 for line in lines2:
1711 nomatchprinted = False
1712 while lines1:
1713 nextline = lines1.pop(0)
1714 if line == nextline:
1715 self._log("exact match:", repr(line))
1716 started = True
1717 break
1718 elif match_func(nextline, line):
1719 self._log(f"{match_nickname}:", repr(line))
1720 self._log(
1721 "{:>{width}}".format("with:", width=wnick), repr(nextline)
1722 )
1723 started = True
1724 break
1725 else:
1726 if consecutive and started:
1727 msg = f"no consecutive match: {line!r}"
1728 self._log(msg)
1729 self._log(
1730 "{:>{width}}".format("with:", width=wnick), repr(nextline)
1731 )
1732 self._fail(msg)
1733 if not nomatchprinted:
1734 self._log(
1735 "{:>{width}}".format("nomatch:", width=wnick), repr(line)
1736 )

Callers 2

fnmatch_linesMethod · 0.95
re_match_linesMethod · 0.95

Calls 6

_getlinesMethod · 0.95
_logMethod · 0.95
_failMethod · 0.95
popMethod · 0.80
appendMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected