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)
| 1729 | return str(s.encode('ASCII', 'backslashreplace'), "ASCII") |
| 1730 | |
| 1731 | def check_output(self, want, got, optionflags): |
| 1732 | """ |
| 1733 | Return True iff the actual output from an example (`got`) |
| 1734 | matches the expected output (`want`). These strings are |
| 1735 | always considered to match if they are identical; but |
| 1736 | depending on what option flags the test runner is using, |
| 1737 | several non-exact match types are also possible. See the |
| 1738 | documentation for `TestRunner` for more information about |
| 1739 | option flags. |
| 1740 | """ |
| 1741 | |
| 1742 | # If `want` contains hex-escaped character such as "\u1234", |
| 1743 | # then `want` is a string of six characters(e.g. [\,u,1,2,3,4]). |
| 1744 | # On the other hand, `got` could be another sequence of |
| 1745 | # characters such as [\u1234], so `want` and `got` should |
| 1746 | # be folded to hex-escaped ASCII string to compare. |
| 1747 | got = self._toAscii(got) |
| 1748 | want = self._toAscii(want) |
| 1749 | |
| 1750 | # Handle the common case first, for efficiency: |
| 1751 | # if they're string-identical, always return true. |
| 1752 | if got == want: |
| 1753 | return True |
| 1754 | |
| 1755 | # The values True and False replaced 1 and 0 as the return |
| 1756 | # value for boolean comparisons in Python 2.3. |
| 1757 | if not (optionflags & DONT_ACCEPT_TRUE_FOR_1): |
| 1758 | if (got,want) == ("True\n", "1\n"): |
| 1759 | return True |
| 1760 | if (got,want) == ("False\n", "0\n"): |
| 1761 | return True |
| 1762 | |
| 1763 | # <BLANKLINE> can be used as a special sequence to signify a |
| 1764 | # blank line, unless the DONT_ACCEPT_BLANKLINE flag is used. |
| 1765 | if not (optionflags & DONT_ACCEPT_BLANKLINE): |
| 1766 | # Replace <BLANKLINE> in want with a blank line. |
| 1767 | want = re.sub(r'(?m)^%s\s*?$' % re.escape(BLANKLINE_MARKER), |
| 1768 | '', want) |
| 1769 | # If a line in got contains only spaces, then remove the |
| 1770 | # spaces. |
| 1771 | got = re.sub(r'(?m)^[^\S\n]+$', '', got) |
| 1772 | if got == want: |
| 1773 | return True |
| 1774 | |
| 1775 | # This flag causes doctest to ignore any differences in the |
| 1776 | # contents of whitespace strings. Note that this can be used |
| 1777 | # in conjunction with the ELLIPSIS flag. |
| 1778 | if optionflags & NORMALIZE_WHITESPACE: |
| 1779 | got = ' '.join(got.split()) |
| 1780 | want = ' '.join(want.split()) |
| 1781 | if got == want: |
| 1782 | return True |
| 1783 | |
| 1784 | # The ELLIPSIS flag says to let the sequence "..." in `want` |
| 1785 | # match any substring in `got`. |
| 1786 | if optionflags & ELLIPSIS: |
| 1787 | if _ellipsis_match(want, got): |
| 1788 | return True |
no test coverage detected