@@ -1396,17 +1396,23 @@ def optionflags(): r"""
1396
1396
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
1397
1397
10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
1398
1398
1399
- The IGNORE_LINEBREAK flag causes all sequences of newlines to be removed:
1399
+ The IGNORE_LINEBREAK flag causes all sequences of newlines to be removed,
1400
+ but retains the leading whitespaces as they cannot be distinguished from
1401
+ real textual whitespaces:
1400
1402
1401
- >>> def f(x):
1402
- ... '\n>>> "foobar"\n\'foo\nbar\''
1403
+ >>> def f(x): pass
1404
+ >>> f.__doc__ = '''
1405
+ ... >>> "foobar"
1406
+ ... 'foo
1407
+ ... bar'
1408
+ ... '''.strip()
1403
1409
1404
1410
>>> # Without the flag:
1405
1411
>>> test = doctest.DocTestFinder().find(f)[0]
1406
1412
>>> doctest.DocTestRunner(verbose=False).run(test)
1407
1413
... # doctest: +ELLIPSIS
1408
1414
**********************************************************************
1409
- File ..., line 3 , in f
1415
+ File ..., line ? , in f
1410
1416
Failed example:
1411
1417
"foobar"
1412
1418
Expected:
@@ -1454,12 +1460,50 @@ def optionflags(): r"""
1454
1460
1455
1461
... mixing flags:
1456
1462
1457
- >>> import string
1458
- >>> print(list(string.ascii_letters)) # doctest: +IGNORE_LINEBREAK
1459
- ... # doctest: +ELLIPSIS
1460
- ... # doctest: +NORMALIZE_WHITESPACE
1461
- ['a', ..., 'z',
1462
- 'A', ..., 'Z']
1463
+ >>> print(list("abc123")) # doctest: +IGNORE_LINEBREAK
1464
+ ... # doctest: +ELLIPSIS
1465
+ ... # doctest: +NORMALIZE_WHITESPACE
1466
+ ['a', ..., 'c',
1467
+ '1', ..., '3']
1468
+
1469
+ >>> prelude = r'''
1470
+ ... >>> print(list("abc123")) # doctest: +IGNORE_LINEBREAK
1471
+ ... ... # doctest: +ELLIPSIS
1472
+ ... ... # doctest: +NORMALIZE_WHITESPACE
1473
+ ... '''.strip()
1474
+
1475
+ >>> def good(x): pass
1476
+ >>> good.__doc__ = '\n'.join([prelude, r'''
1477
+ ... ['a', ..., 'c',
1478
+ ... '1', ..., '3']
1479
+ ... '''.lstrip()]).lstrip()
1480
+ >>> test = doctest.DocTestFinder().find(good)[0]
1481
+ >>> doctest.DocTestRunner(verbose=False).run(test)
1482
+ TestResults(failed=0, attempted=1)
1483
+
1484
+ >>> def fail(x): pass
1485
+ >>> fail.__doc__ = '\n'.join([prelude, '''
1486
+ ... [
1487
+ ... 'a', ..., 'c',
1488
+ ... '1', ..., '3'
1489
+ ... ]\n'''.lstrip()])
1490
+ >>> test = doctest.DocTestFinder().find(fail)[0]
1491
+ >>> doctest.DocTestRunner(verbose=False).run(test)
1492
+ ... # doctest: +ELLIPSIS
1493
+ **********************************************************************
1494
+ File ..., line ?, in fail
1495
+ Failed example:
1496
+ print(list("abc123")) # doctest: +IGNORE_LINEBREAK
1497
+ # doctest: +ELLIPSIS
1498
+ # doctest: +NORMALIZE_WHITESPACE
1499
+ Expected:
1500
+ [
1501
+ 'a', ..., 'c',
1502
+ '1', ..., '3'
1503
+ ]
1504
+ Got:
1505
+ ['a', 'b', 'c', '1', '2', '3']
1506
+ TestResults(failed=1, attempted=1)
1463
1507
1464
1508
The ELLIPSIS flag causes ellipsis marker ("...") in the expected
1465
1509
output to match any substring in the actual output:
0 commit comments