Commits

Anonymous committed 9ac6435

Example.__init__: this cannot use assert, because that fails to trigger
in a -O run, and so test_doctest was failing under -O. Simple cause,
simple cure.

Comments (0)

Files changed (2)

     """
     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

Lib/test/test_doctest.py

     >>> 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)
 """
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.