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

Method test_global_as_constant

Lib/test/test_peepholer.py:108–133  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

106 self.check_lnotab(code)
107
108 def test_global_as_constant(self):
109 # LOAD_GLOBAL None/True/False --> LOAD_CONST None/True/False
110 def f():
111 x = None
112 x = None
113 return x
114 def g():
115 x = True
116 return x
117 def h():
118 x = False
119 return x
120
121 for func, elem in ((f, None), (g, True), (h, False)):
122 with self.subTest(func=func):
123 self.assertNotInBytecode(func, 'LOAD_GLOBAL')
124 self.assertInBytecode(func, 'LOAD_CONST', elem)
125 self.check_lnotab(func)
126
127 def f():
128 'Adding a docstring made this test fail in Py2.5.0'
129 return None
130
131 self.assertNotInBytecode(f, 'LOAD_GLOBAL')
132 self.assertInBytecode(f, 'LOAD_CONST', None)
133 self.check_lnotab(f)
134
135 def test_while_one(self):
136 # Skip over: LOAD_CONST trueconst POP_JUMP_IF_FALSE xx

Callers

nothing calls this directly

Calls 4

check_lnotabMethod · 0.95
subTestMethod · 0.80
assertNotInBytecodeMethod · 0.80
assertInBytecodeMethod · 0.80

Tested by

no test coverage detected