Skip to content

Commit 77de151

Browse files
tests: add test for CONVERT_VALUE/FORMAT_VALUE
1 parent cab273d commit 77de151

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

tests/test_bytecode.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import unittest
88

99
from bytecode import Bytecode, ConcreteInstr, FreeVar, Instr, Label, SetLineno
10-
from bytecode.instr import BinaryOp, InstrLocation
10+
from bytecode.instr import BinaryOp, FormatValue, InstrLocation
1111
from bytecode.utils import PY310, PY311, PY312, PY313, PY314
1212

1313
from . import TestCase, get_code
@@ -356,6 +356,41 @@ def func():
356356
),
357357
)
358358

359+
def test_from_code_str_format(self):
360+
code = get_code(
361+
"""
362+
def func(a):
363+
return f"{a!r}"
364+
""",
365+
function=True,
366+
)
367+
code = Bytecode.from_code(code)
368+
self.assertInstructionListEqual(
369+
code,
370+
(
371+
[
372+
Instr("RESUME", 0, lineno=1),
373+
]
374+
if PY311
375+
else []
376+
)
377+
+ (
378+
[
379+
Instr("LOAD_FAST_BORROW", "a", lineno=2)
380+
if PY314
381+
else Instr("LOAD_FAST", "a", lineno=2),
382+
Instr("CONVERT_VALUE", FormatValue.REPR, lineno=2),
383+
Instr("RETURN_VALUE", lineno=2),
384+
]
385+
if PY313
386+
else [
387+
Instr("LOAD_FAST", "a", lineno=2),
388+
Instr("FORMAT_VALUE", 2, lineno=2),
389+
Instr("RETURN_VALUE", lineno=2),
390+
]
391+
),
392+
)
393+
359394
def test_setlineno(self):
360395
# x = 7
361396
# y = 8

0 commit comments

Comments
 (0)