(self)
| 2652 | |
| 2653 | @support.cpython_only |
| 2654 | def test_load_const(self): |
| 2655 | consts = [None, |
| 2656 | True, False, |
| 2657 | 1000, |
| 2658 | 2.0, |
| 2659 | 3j, |
| 2660 | "unicode", |
| 2661 | b'bytes', |
| 2662 | (1, 2, 3)] |
| 2663 | |
| 2664 | code = '\n'.join(['x={!r}'.format(const) for const in consts]) |
| 2665 | code += '\nx = ...' |
| 2666 | consts.extend((Ellipsis, None)) |
| 2667 | |
| 2668 | tree = ast.parse(code) |
| 2669 | self.assertEqual(self.get_load_const(tree), |
| 2670 | consts) |
| 2671 | |
| 2672 | # Replace expression nodes with constants |
| 2673 | for assign, const in zip(tree.body, consts): |
| 2674 | assert isinstance(assign, ast.Assign), ast.dump(assign) |
| 2675 | new_node = ast.Constant(value=const) |
| 2676 | ast.copy_location(new_node, assign.value) |
| 2677 | assign.value = new_node |
| 2678 | |
| 2679 | self.assertEqual(self.get_load_const(tree), |
| 2680 | consts) |
| 2681 | |
| 2682 | def test_literal_eval(self): |
| 2683 | tree = ast.parse("1 + 2") |
nothing calls this directly
no test coverage detected