MCPcopy Create free account
hub / github.com/pytest-dev/pytest / _match_lines

Method _match_lines

src/_pytest/pytester.py:1632–1697  ·  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

1630 )
1631
1632 def _match_lines(
1633 self,
1634 lines2: Sequence[str],
1635 match_func: Callable[[str, str], bool],
1636 match_nickname: str,
1637 *,
1638 consecutive: bool = False,
1639 ) -> None:
1640 """Underlying implementation of ``fnmatch_lines`` and ``re_match_lines``.
1641
1642 :param Sequence[str] lines2:
1643 List of string patterns to match. The actual format depends on
1644 ``match_func``.
1645 :param match_func:
1646 A callable ``match_func(line, pattern)`` where line is the
1647 captured line from stdout/stderr and pattern is the matching
1648 pattern.
1649 :param str match_nickname:
1650 The nickname for the match function that will be logged to stdout
1651 when a match occurs.
1652 :param consecutive:
1653 Match lines consecutively?
1654 """
1655 if not isinstance(lines2, collections.abc.Sequence):
1656 raise TypeError(f"invalid type for lines2: {type(lines2).__name__}")
1657 lines2 = self._getlines(lines2)
1658 lines1 = self.lines[:]
1659 extralines = []
1660 __tracebackhide__ = True
1661 wnick = len(match_nickname) + 1
1662 started = False
1663 for line in lines2:
1664 nomatchprinted = False
1665 while lines1:
1666 nextline = lines1.pop(0)
1667 if line == nextline:
1668 self._log("exact match:", repr(line))
1669 started = True
1670 break
1671 elif match_func(nextline, line):
1672 self._log("%s:" % match_nickname, repr(line))
1673 self._log(
1674 "{:>{width}}".format("with:", width=wnick), repr(nextline)
1675 )
1676 started = True
1677 break
1678 else:
1679 if consecutive and started:
1680 msg = f"no consecutive match: {line!r}"
1681 self._log(msg)
1682 self._log(
1683 "{:>{width}}".format("with:", width=wnick), repr(nextline)
1684 )
1685 self._fail(msg)
1686 if not nomatchprinted:
1687 self._log(
1688 "{:>{width}}".format("nomatch:", width=wnick), repr(line)
1689 )

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