Author: Vasily Kuznetsov <[email protected]>
Branch: py3.3
Changeset: r72570:fbd2b376181f
Date: 2014-07-27 14:14 +0200
http://bitbucket.org/pypy/pypy/changeset/fbd2b376181f/

Log:    Add a test for interaction between -O and optimize=0.

diff --git a/pypy/module/__builtin__/test/test_compile.py 
b/pypy/module/__builtin__/test/test_compile.py
--- a/pypy/module/__builtin__/test/test_compile.py
+++ b/pypy/module/__builtin__/test/test_compile.py
@@ -81,9 +81,36 @@
             assert 'class_doc' not in marshalled
 
 
+class TestOptimizeO:
+    """Test interaction of -O flag and optimize parameter of compile."""
+
+    def test_O_optmize_0(self):
+        """Test that assert is not ignored if -O flag is set but optimize=0."""
+        space = self.space
+        space.sys.debug = False  # imitate -O
+
+        w_res = space.appexec([], """():
+            assert False  # check that our -O imitation hack works
+            try:
+                exec(compile('assert False', '', 'exec', optimize=0))
+            except AssertionError:
+                return True
+            else:
+                return False
+        """)
+        assert space.unwrap(w_res)
+
+    def test_O_optimize__1(self):
+        """Test that assert is ignored with -O and optimize=-1."""
+        space = self.space
+        space.sys.debug = False  # imitate -O
+
+        space.appexec([], """():
+            exec(compile('assert False', '', 'exec', optimize=-1))
+        """)
+
+
 # TODO: Check the value of __debug__ inside of the compiled block!
 #       According to the documentation, it should follow the optimize flag.
 #       However, cpython3.5.0a0 behaves the same way as PyPy (__debug__ follows
 #       -O, -OO flags of the interpreter).
-# TODO: It would also be good to test that the assert is not removed and is
-#       executed when -O flag is set but optimize=0.
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to