(self)
| 2674 | |
| 2675 | @support.cpython_only |
| 2676 | def test_load_const(self): |
| 2677 | consts = [None, |
| 2678 | True, False, |
| 2679 | 1000, |
| 2680 | 2.0, |
| 2681 | 3j, |
| 2682 | "unicode", |
| 2683 | b'bytes', |
| 2684 | (1, 2, 3)] |
| 2685 | |
| 2686 | code = '\n'.join(['x={!r}'.format(const) for const in consts]) |
| 2687 | code += '\nx = ...' |
| 2688 | consts.extend((Ellipsis, None)) |
| 2689 | |
| 2690 | tree = ast.parse(code) |
| 2691 | self.assertEqual(self.get_load_const(tree), |
| 2692 | consts) |
| 2693 | |
| 2694 | # Replace expression nodes with constants |
| 2695 | for assign, const in zip(tree.body, consts): |
| 2696 | assert isinstance(assign, ast.Assign), ast.dump(assign) |
| 2697 | new_node = ast.Constant(value=const) |
| 2698 | ast.copy_location(new_node, assign.value) |
| 2699 | assign.value = new_node |
| 2700 | |
| 2701 | self.assertEqual(self.get_load_const(tree), |
| 2702 | consts) |
| 2703 | |
| 2704 | def test_literal_eval(self): |
| 2705 | tree = ast.parse("1 + 2") |
nothing calls this directly
no test coverage detected