]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
#8414: add more tests for "assert". Initial patch by Gregory Nofi.
authorEzio Melotti <ezio.melotti@gmail.com>
Fri, 2 Dec 2011 16:17:30 +0000 (18:17 +0200)
committerEzio Melotti <ezio.melotti@gmail.com>
Fri, 2 Dec 2011 16:17:30 +0000 (18:17 +0200)
Lib/test/test_grammar.py

index 137ac233fcf4e8c9b9e07cf6063a89914cd4359a..86cc0843eef4c8d218b1a75c2724f6395f7427f3 100644 (file)
@@ -551,13 +551,35 @@ hello world
         assert 1, 1
         assert lambda x:x
         assert 1, lambda x:x+1
+
+        try:
+            assert True
+        except AssertionError as e:
+            self.fail("'assert True' should not have raised an AssertionError")
+
+        try:
+            assert True, 'this should always pass'
+        except AssertionError as e:
+            self.fail("'assert True, msg' should not have "
+                      "raised an AssertionError")
+
+    # these tests fail if python is run with -O, so check __debug__
+    @unittest.skipUnless(__debug__, "Won't work if __debug__ is False")
+    def testAssert2(self):
         try:
             assert 0, "msg"
         except AssertionError, e:
             self.assertEqual(e.args[0], "msg")
         else:
-            if __debug__:
-                self.fail("AssertionError not raised by assert 0")
+            self.fail("AssertionError not raised by assert 0")
+
+        try:
+            assert False
+        except AssertionError as e:
+            self.assertEqual(len(e.args), 0)
+        else:
+            self.fail("AssertionError not raised by 'assert False'")
+
 
     ### compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef
     # Tested below