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

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 1662 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 diff = difflib.context_diff(want_lines, got_lines, n=2) 1673 diff = difflib.context_diff(want_lines, got_lines, n=2)
1674 diff = list(diff)[2:] # strip the diff header 1674 diff = list(diff)[2:] # strip the diff header
1675 kind = 'context diff with expected followed by actual' 1675 kind = 'context diff with expected followed by actual'
1676 elif optionflags & REPORT_NDIFF: 1676 elif optionflags & REPORT_NDIFF:
1677 engine = difflib.Differ(charjunk=difflib.IS_CHARACTER_JUNK) 1677 engine = difflib.Differ(charjunk=difflib.IS_CHARACTER_JUNK)
1678 diff = list(engine.compare(want_lines, got_lines)) 1678 diff = list(engine.compare(want_lines, got_lines))
1679 kind = 'ndiff with -expected +actual' 1679 kind = 'ndiff with -expected +actual'
1680 else: 1680 else:
1681 assert 0, 'Bad diff option' 1681 assert 0, 'Bad diff option'
1682 # Remove trailing whitespace on diff output. 1682 # Remove trailing whitespace on diff output.
1683 diff = [line.rstrip() + '\n' for line in diff]
1684 return 'Differences (%s):\n' % kind + _indent(''.join(diff)) 1683 return 'Differences (%s):\n' % kind + _indent(''.join(diff))
1685 1684
1686 # If we're not using diff, then simply list the expected 1685 # If we're not using diff, then simply list the expected
1687 # output followed by the actual output. 1686 # output followed by the actual output.
1688 if want and got: 1687 if want and got:
1689 return 'Expected:\n%sGot:\n%s' % (_indent(want), _indent(got)) 1688 return 'Expected:\n%sGot:\n%s' % (_indent(want), _indent(got))
1690 elif want: 1689 elif want:
1691 return 'Expected:\n%sGot nothing\n' % _indent(want) 1690 return 'Expected:\n%sGot nothing\n' % _indent(want)
1692 elif got: 1691 elif got:
1693 return 'Expected nothing\nGot:\n%s' % _indent(got) 1692 return 'Expected nothing\nGot:\n%s' % _indent(got)
(...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after
2775 else: 2774 else:
2776 failures, _ = testfile(filename, module_relative=False, 2775 failures, _ = testfile(filename, module_relative=False,
2777 verbose=verbose, optionflags=options) 2776 verbose=verbose, optionflags=options)
2778 if failures: 2777 if failures:
2779 return 1 2778 return 1
2780 return 0 2779 return 0
2781 2780
2782 2781
2783 if __name__ == "__main__": 2782 if __name__ == "__main__":
2784 sys.exit(_test()) 2783 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+