@@ -1396,17 +1396,23 @@ def optionflags(): r"""
13961396 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
13971397 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
13981398
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:
14001402
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()
14031409
14041410 >>> # Without the flag:
14051411 >>> test = doctest.DocTestFinder().find(f)[0]
14061412 >>> doctest.DocTestRunner(verbose=False).run(test)
14071413 ... # doctest: +ELLIPSIS
14081414 **********************************************************************
1409- File ..., line 3 , in f
1415+ File ..., line ? , in f
14101416 Failed example:
14111417 "foobar"
14121418 Expected:
@@ -1454,12 +1460,50 @@ def optionflags(): r"""
14541460
14551461 ... mixing flags:
14561462
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)
14631507
14641508The ELLIPSIS flag causes ellipsis marker ("...") in the expected
14651509output to match any substring in the actual output:
0 commit comments