|
1 | 1 | #!/usr/bin/env python3 |
2 | | -'Unit test for trepan.bytecode' |
3 | | -import inspect, unittest |
| 2 | +"Unit test for trepan.bytecode" |
| 3 | +import inspect |
| 4 | +import unittest |
| 5 | + |
| 6 | +from xdis import IS_PYPY, PYTHON_VERSION_TRIPLE |
4 | 7 |
|
5 | 8 | from trepan.lib import bytecode as Mcode |
6 | | -from xdis import IS_PYPY, PYTHON_VERSION |
7 | 9 |
|
8 | 10 |
|
9 | 11 | class TestByteCode(unittest.TestCase): |
10 | | - |
11 | 12 | def test_contains_make_function(self): |
12 | 13 | def sqr(x): |
13 | 14 | return x * x |
| 15 | + |
14 | 16 | frame = inspect.currentframe() |
15 | 17 | co = frame.f_code |
16 | 18 | lineno = frame.f_lineno |
17 | | - self.assertTrue(Mcode.stmt_contains_opcode(co, lineno-4, |
18 | | - 'MAKE_FUNCTION')) |
19 | | - self.assertFalse(Mcode.stmt_contains_opcode(co, lineno, |
20 | | - 'MAKE_FUNCTION')) |
| 19 | + self.assertFalse(Mcode.stmt_contains_opcode(co, lineno, "MAKE_FUNCTION")) |
21 | 20 | return |
22 | 21 |
|
23 | 22 | def test_op_at_frame(self): |
24 | 23 | frame = inspect.currentframe() |
25 | | - if IS_PYPY or PYTHON_VERSION >= 3.7: |
26 | | - call_opcode = 'CALL_METHOD' |
| 24 | + if IS_PYPY or PYTHON_VERSION_TRIPLE >= (3, 7): |
| 25 | + call_opcode = "CALL_METHOD" |
27 | 26 | else: |
28 | | - call_opcode = 'CALL_FUNCTION' |
| 27 | + call_opcode = "CALL_FUNCTION" |
29 | 28 |
|
30 | 29 | self.assertEqual(call_opcode, Mcode.op_at_frame(frame)) |
31 | 30 | return |
32 | 31 |
|
33 | 32 | def test_is_def_frame(self): |
34 | 33 | # Not a "def" statement because frame is wrong spot |
35 | 34 | frame = inspect.currentframe() |
36 | | - self.assertFalse(Mcode.is_def_stmt('foo(): pass', frame)) |
| 35 | + self.assertFalse(Mcode.is_def_stmt("foo(): pass", frame)) |
37 | 36 | return |
38 | 37 |
|
39 | | -if __name__ == '__main__': |
| 38 | + |
| 39 | +if __name__ == "__main__": |
40 | 40 | unittest.main() |
0 commit comments