MCPcopy Index your code
hub / github.com/RustPython/RustPython / check_output

Method check_output

Lib/doctest.py:1704–1764  ·  view source on GitHub ↗

Return True iff the actual output from an example (`got`) matches the expected output (`want`). These strings are always considered to match if they are identical; but depending on what option flags the test runner is using, several non-exact match types are

(self, want, got, optionflags)

Source from the content-addressed store, hash-verified

1702 return str(s.encode('ASCII', 'backslashreplace'), "ASCII")
1703
1704 def check_output(self, want, got, optionflags):
1705 """
1706 Return True iff the actual output from an example (`got`)
1707 matches the expected output (`want`). These strings are
1708 always considered to match if they are identical; but
1709 depending on what option flags the test runner is using,
1710 several non-exact match types are also possible. See the
1711 documentation for `TestRunner` for more information about
1712 option flags.
1713 """
1714
1715 # If `want` contains hex-escaped character such as "\u1234",
1716 # then `want` is a string of six characters(e.g. [\,u,1,2,3,4]).
1717 # On the other hand, `got` could be another sequence of
1718 # characters such as [\u1234], so `want` and `got` should
1719 # be folded to hex-escaped ASCII string to compare.
1720 got = self._toAscii(got)
1721 want = self._toAscii(want)
1722
1723 # Handle the common case first, for efficiency:
1724 # if they're string-identical, always return true.
1725 if got == want:
1726 return True
1727
1728 # The values True and False replaced 1 and 0 as the return
1729 # value for boolean comparisons in Python 2.3.
1730 if not (optionflags & DONT_ACCEPT_TRUE_FOR_1):
1731 if (got,want) == ("True\n", "1\n"):
1732 return True
1733 if (got,want) == ("False\n", "0\n"):
1734 return True
1735
1736 # <BLANKLINE> can be used as a special sequence to signify a
1737 # blank line, unless the DONT_ACCEPT_BLANKLINE flag is used.
1738 if not (optionflags & DONT_ACCEPT_BLANKLINE):
1739 # Replace <BLANKLINE> in want with a blank line.
1740 want = re.sub(r'(?m)^%s\s*?$' % re.escape(BLANKLINE_MARKER),
1741 '', want)
1742 # If a line in got contains only spaces, then remove the
1743 # spaces.
1744 got = re.sub(r'(?m)^[^\S\n]+$', '', got)
1745 if got == want:
1746 return True
1747
1748 # This flag causes doctest to ignore any differences in the
1749 # contents of whitespace strings. Note that this can be used
1750 # in conjunction with the ELLIPSIS flag.
1751 if optionflags & NORMALIZE_WHITESPACE:
1752 got = ' '.join(got.split())
1753 want = ' '.join(want.split())
1754 if got == want:
1755 return True
1756
1757 # The ELLIPSIS flag says to let the sequence "..." in `want`
1758 # match any substring in `got`.
1759 if optionflags & ELLIPSIS:
1760 if _ellipsis_match(want, got):
1761 return True

Callers 6

_aix_bos_rteFunction · 0.45
_syscmd_verFunction · 0.45
_syscmd_fileFunction · 0.45
from_subprocessMethod · 0.45
rustfmtFunction · 0.45

Calls 6

_toAsciiMethod · 0.95
_ellipsis_matchFunction · 0.85
escapeMethod · 0.80
subMethod · 0.45
joinMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected