MCPcopy Index your code
hub / github.com/python/cpython / test_load_const

Method test_load_const

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected