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

Side by Side Diff: Lib/test/test_doctest.py

Issue 24746: doctest 'fancy diff' formats incorrectly strip trailing whitespace
Patch Set: Created 4 years, 1 month 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 | « Lib/doctest.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """ 1 """
2 Test script for doctest. 2 Test script for doctest.
3 """ 3 """
4 4
5 from test import support 5 from test import support
6 import doctest 6 import doctest
7 import functools 7 import functools
8 import os 8 import os
9 import sys 9 import sys
10 10
(...skipping 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 --- 1,7 ---- 1386 --- 1,7 ----
1387 a 1387 a
1388 ! b 1388 ! b
1389 c 1389 c
1390 d 1390 d
1391 + e 1391 + e
1392 f 1392 f
1393 g 1393 g
1394 TestResults(failed=1, attempted=1) 1394 TestResults(failed=1, attempted=1)
1395 1395
1396 The fancy reports had a bug for a long time where any trailing whitespace on
1397 the reported diff lines was stripped, making it impossible to see the
1398 differences in line reported as different that differed only in the amount of
1399 trailing whitespace. The whitespace still isn't particularly visible unless
1400 you use NDIFF, but at least it is now there to be found.
1401
1402 >>> def f(x):
1403 ... r'''
1404 ... >>> print('\n'.join(['a ', 'b']))
1405 ... a
1406 ... b
1407 ... '''
1408
1409 >>> test = doctest.DocTestFinder().find(f)[0]
1410 >>> flags = doctest.REPORT_NDIFF
1411 >>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test)
1412 ... # doctest: +ELLIPSIS
1413 **********************************************************************
1414 File ..., line 3, in f
1415 Failed example:
1416 print('\n'.join(['a ', 'b']))
1417 Differences (ndiff with -expected +actual):
1418 - a
1419 + a
1420 b
1421 TestResults(failed=1, attempted=1)
1396 1422
1397 The REPORT_NDIFF flag causes failures to use the difflib.Differ algorithm 1423 The REPORT_NDIFF flag causes failures to use the difflib.Differ algorithm
1398 used by the popular ndiff.py utility. This does intraline difference 1424 used by the popular ndiff.py utility. This does intraline difference
1399 marking, as well as interline differences. 1425 marking, as well as interline differences.
1400 1426
1401 >>> def f(x): 1427 >>> def f(x):
1402 ... r''' 1428 ... r'''
1403 ... >>> print("a b c d e f g h i j k l m") 1429 ... >>> print("a b c d e f g h i j k l m")
1404 ... a b c d e f g h i j k 1 m 1430 ... a b c d e f g h i j k 1 m
1405 ... ''' 1431 ... '''
(...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after
2438 favorite_color 2464 favorite_color
2439 ... 2465 ...
2440 Failed example: 2466 Failed example:
2441 if 1: 2467 if 1:
2442 print('a') 2468 print('a')
2443 print() 2469 print()
2444 print('b') 2470 print('b')
2445 Differences (ndiff with -expected +actual): 2471 Differences (ndiff with -expected +actual):
2446 a 2472 a
2447 - <BLANKLINE> 2473 - <BLANKLINE>
2448 + 2474 +
2449 b 2475 b
2450 <BLANKLINE> 2476 <BLANKLINE>
2451 <BLANKLINE> 2477 <BLANKLINE>
2452 2478
2453 2479
2454 Test runners can restore the formatting flags after they run: 2480 Test runners can restore the formatting flags after they run:
2455 2481
2456 >>> ignored = doctest.set_unittest_reportflags(old) 2482 >>> ignored = doctest.set_unittest_reportflags(old)
2457 2483
2458 """ 2484 """
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
2962 r = tracer.results() 2988 r = tracer.results()
2963 print('Writing coverage results...') 2989 print('Writing coverage results...')
2964 r.write_results(show_missing=True, summary=True, 2990 r.write_results(show_missing=True, summary=True,
2965 coverdir=coverdir) 2991 coverdir=coverdir)
2966 2992
2967 if __name__ == '__main__': 2993 if __name__ == '__main__':
2968 if '-c' in sys.argv: 2994 if '-c' in sys.argv:
2969 test_coverage('/tmp/doctest.cover') 2995 test_coverage('/tmp/doctest.cover')
2970 else: 2996 else:
2971 test_main() 2997 test_main()
OLDNEW
« no previous file with comments | « Lib/doctest.py ('k') | no next file » | no next file with comments »

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