]> granicus.if.org Git - python/commitdiff
Example.__init__: this cannot use assert, because that fails to trigger
authorTim Peters <tim.peters@gmail.com>
Wed, 4 Aug 2004 20:04:32 +0000 (20:04 +0000)
committerTim Peters <tim.peters@gmail.com>
Wed, 4 Aug 2004 20:04:32 +0000 (20:04 +0000)
in a -O run, and so test_doctest was failing under -O.  Simple cause,
simple cure.

Lib/doctest.py
Lib/test/test_doctest.py

index ecf0e1ac6deca124e444b1fba2fc25831bff26a7..86d1782021cbed87abd841131405405a4d2ad2e3 100644 (file)
@@ -478,8 +478,11 @@ class Example:
     """
     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
index 68ac44c6e6f793a8185405ea5ff0b5136b4fd8ae..1062942ca2969fd5571c4fe1617fd8bf873bd851 100644 (file)
@@ -132,13 +132,13 @@ than one line:
     >>> 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:
@@ -146,7 +146,7 @@ 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)
 """