MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_load_const

Method test_load_const

Lib/test/test_ast/test_ast.py:2676–2702  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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")

Callers

nothing calls this directly

Calls 8

get_load_constMethod · 0.95
isinstanceFunction · 0.85
joinMethod · 0.45
formatMethod · 0.45
extendMethod · 0.45
parseMethod · 0.45
assertEqualMethod · 0.45
dumpMethod · 0.45

Tested by

no test coverage detected