"""
def __init__(self, source, want, lineno):
# Check invariants.
- assert (source[-1:] == '\n') == ('\n' in source[:-1])
- assert want == '' or want[-1] == '\n'
+ if (source[-1:] == '\n') != ('\n' in source[:-1]):
+ raise AssertionError("source must end with newline iff "
+ "source contains more than one line")
+ if want and want[-1] != '\n':
+ raise AssertionError("non-empty want must end with newline")
# Store properties.
self.source = source
self.want = want
>>> e = doctest.Example('print 1', '1\n', 0)
>>> e = doctest.Example('print 1\n', '1\n', 0)
Traceback (most recent call last):
- AssertionError
+ AssertionError: source must end with newline iff source contains more than one line
>>> # Source spans multiple lines: require terminating newline.
>>> e = doctest.Example('print 1;\nprint 2\n', '1\n2\n', 0)
>>> e = doctest.Example('print 1;\nprint 2', '1\n2\n', 0)
Traceback (most recent call last):
- AssertionError
+ AssertionError: source must end with newline iff source contains more than one line
The `want` string should be terminated by a newline, unless it's the
empty string:
>>> e = doctest.Example('print 1', '1\n', 0)
>>> e = doctest.Example('print 1', '1', 0)
Traceback (most recent call last):
- AssertionError
+ AssertionError: non-empty want must end with newline
>>> e = doctest.Example('print', '', 0)
"""