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 type
(self, want, got, optionflags)
| 1616 | return str(s.encode('ASCII', 'backslashreplace'), "ASCII") |
| 1617 | |
| 1618 | def check_output(self, want, got, optionflags): |
| 1619 | """ |
| 1620 | Return True iff the actual output from an example (`got`) |
| 1621 | matches the expected output (`want`). These strings are |
| 1622 | always considered to match if they are identical; but |
| 1623 | depending on what option flags the test runner is using, |
| 1624 | several non-exact match types are also possible. See the |
| 1625 | documentation for `TestRunner` for more information about |
| 1626 | option flags. |
| 1627 | """ |
| 1628 | |
| 1629 | # If `want` contains hex-escaped character such as "\u1234", |
| 1630 | # then `want` is a string of six characters(e.g. [\,u,1,2,3,4]). |
| 1631 | # On the other hand, `got` could be another sequence of |
| 1632 | # characters such as [\u1234], so `want` and `got` should |
| 1633 | # be folded to hex-escaped ASCII string to compare. |
| 1634 | got = self._toAscii(got) |
| 1635 | want = self._toAscii(want) |
| 1636 | |
| 1637 | # Handle the common case first, for efficiency: |
| 1638 | # if they're string-identical, always return true. |
| 1639 | if got == want: |
| 1640 | return True |
| 1641 | |
| 1642 | # The values True and False replaced 1 and 0 as the return |
| 1643 | # value for boolean comparisons in Python 2.3. |
| 1644 | if not (optionflags & DONT_ACCEPT_TRUE_FOR_1): |
| 1645 | if (got,want) == ("True\n", "1\n"): |
| 1646 | return True |
| 1647 | if (got,want) == ("False\n", "0\n"): |
| 1648 | return True |
| 1649 | |
| 1650 | # <BLANKLINE> can be used as a special sequence to signify a |
| 1651 | # blank line, unless the DONT_ACCEPT_BLANKLINE flag is used. |
| 1652 | if not (optionflags & DONT_ACCEPT_BLANKLINE): |
| 1653 | # Replace <BLANKLINE> in want with a blank line. |
| 1654 | want = re.sub(r'(?m)^%s\s*?$' % re.escape(BLANKLINE_MARKER), |
| 1655 | '', want) |
| 1656 | # If a line in got contains only spaces, then remove the |
| 1657 | # spaces. |
| 1658 | got = re.sub(r'(?m)^[^\S\n]+$', '', got) |
| 1659 | if got == want: |
| 1660 | return True |
| 1661 | |
| 1662 | # This flag causes doctest to ignore any differences in the |
| 1663 | # contents of whitespace strings. Note that this can be used |
| 1664 | # in conjunction with the ELLIPSIS flag. |
| 1665 | if optionflags & NORMALIZE_WHITESPACE: |
| 1666 | got = ' '.join(got.split()) |
| 1667 | want = ' '.join(want.split()) |
| 1668 | if got == want: |
| 1669 | return True |
| 1670 | |
| 1671 | # The ELLIPSIS flag says to let the sequence "..." in `want` |
| 1672 | # match any substring in `got`. |
| 1673 | if optionflags & ELLIPSIS: |
| 1674 | if _ellipsis_match(want, got): |
| 1675 | return True |
no test coverage detected