Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(33729)

Side by Side Diff: Lib/doctest.py

Issue 24746: doctest 'fancy diff' formats incorrectly strip trailing whitespace
Patch Set: Created 4 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Lib/test/test_doctest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Module doctest. 1 # Module doctest.
2 # Released to the public domain 16-Jan-2001, by Tim Peters (tim@python.org). 2 # Released to the public domain 16-Jan-2001, by Tim Peters (tim@python.org).
3 # Major enhancements and refactoring by: 3 # Major enhancements and refactoring by:
4 # Jim Fulton 4 # Jim Fulton
5 # Edward Loper 5 # Edward Loper
6 6
7 # Provided as-is; use at your own risk; no warranty; no promises; enjoy! 7 # Provided as-is; use at your own risk; no warranty; no promises; enjoy!
8 8
9 r"""Module doctest -- a framework for running examples in docstrings. 9 r"""Module doctest -- a framework for running examples in docstrings.
10 10
(...skipping 1663 matching lines...) Expand 10 before | Expand all | Expand 10 after
1674 elif optionflags & REPORT_CDIFF: 1674 elif optionflags & REPORT_CDIFF:
1675 diff = difflib.context_diff(want_lines, got_lines, n=2) 1675 diff = difflib.context_diff(want_lines, got_lines, n=2)
1676 diff = list(diff)[2:] # strip the diff header 1676 diff = list(diff)[2:] # strip the diff header
1677 kind = 'context diff with expected followed by actual' 1677 kind = 'context diff with expected followed by actual'
1678 elif optionflags & REPORT_NDIFF: 1678 elif optionflags & REPORT_NDIFF:
1679 engine = difflib.Differ(charjunk=difflib.IS_CHARACTER_JUNK) 1679 engine = difflib.Differ(charjunk=difflib.IS_CHARACTER_JUNK)
1680 diff = list(engine.compare(want_lines, got_lines)) 1680 diff = list(engine.compare(want_lines, got_lines))
1681 kind = 'ndiff with -expected +actual' 1681 kind = 'ndiff with -expected +actual'
1682 else: 1682 else:
1683 assert 0, 'Bad diff option' 1683 assert 0, 'Bad diff option'
1684 # Remove trailing whitespace on diff output.
1685 diff = [line.rstrip() + '\n' for line in diff]
1686 return 'Differences (%s):\n' % kind + _indent(''.join(diff)) 1684 return 'Differences (%s):\n' % kind + _indent(''.join(diff))
1687 1685
1688 # If we're not using diff, then simply list the expected 1686 # If we're not using diff, then simply list the expected
1689 # output followed by the actual output. 1687 # output followed by the actual output.
1690 if want and got: 1688 if want and got:
1691 return 'Expected:\n%sGot:\n%s' % (_indent(want), _indent(got)) 1689 return 'Expected:\n%sGot:\n%s' % (_indent(want), _indent(got))
1692 elif want: 1690 elif want:
1693 return 'Expected:\n%sGot nothing\n' % _indent(want) 1691 return 'Expected:\n%sGot nothing\n' % _indent(want)
1694 elif got: 1692 elif got:
1695 return 'Expected nothing\nGot:\n%s' % _indent(got) 1693 return 'Expected nothing\nGot:\n%s' % _indent(got)
(...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after
2768 else: 2766 else:
2769 failures, _ = testfile(filename, module_relative=False, 2767 failures, _ = testfile(filename, module_relative=False,
2770 verbose=verbose, optionflags=options) 2768 verbose=verbose, optionflags=options)
2771 if failures: 2769 if failures:
2772 return 1 2770 return 1
2773 return 0 2771 return 0
2774 2772
2775 2773
2776 if __name__ == "__main__": 2774 if __name__ == "__main__":
2777 sys.exit(_test()) 2775 sys.exit(_test())
OLDNEW
« no previous file with comments | « no previous file | Lib/test/test_doctest.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+