| 1 |
class TestOptimizeO: |
| 2 |
"""Test interaction of -O flag and optimize parameter of compile.""" |
| 3 |
|
| 4 |
def setup_method(self, method): |
| 5 |
space = self.space |
| 6 |
self._w_flags = space.sys.get('flags') |
| 7 |
|
| 8 |
space.appexec([], """(): |
| 9 |
import sys |
| 10 |
flags = list(sys.flags) |
| 11 |
flags[3] = 1 |
| 12 |
sys.flags = type(sys.flags)(flags) |
| 13 |
""") |
| 14 |
|
| 15 |
def teardown_method(self, method): |
| 16 |
space = self.space |
| 17 |
space.setitem(space.sys.w_dict, space.newtext('flags'), self._w_flags) |
| 18 |
|
| 19 |
def test_O_optmize_0(self): |
| 20 |
"""Test that assert is not ignored if -O flag is set but optimize=0.""" |
| 21 |
space = self.space |
| 22 |
w_res = space.appexec([], """(): |
| 23 |
assert False # check that our -O imitation hack works |
| 24 |
try: |
| 25 |
exec(compile('assert False', '', 'exec', optimize=0)) |
| 26 |
except AssertionError: |
| 27 |
return True |
| 28 |
else: |
| 29 |
return False |
| 30 |
""") |
| 31 |
assert space.unwrap(w_res) |
| 32 |
|
| 33 |
def test_O_optimize__1(self): |
| 34 |
"""Test that assert is ignored with -O and optimize=-1.""" |
| 35 |
space = self.space |
| 36 |
space.appexec([], """(): |
| 37 |
exec(compile('assert False', '', 'exec', optimize=-1)) |
| 38 |
""") |