Skip to content

Commit 92777d5

Browse files
nanjekyejoannahmatrixise
authored andcommitted
bpo-18578: Rename and document test.bytecode_helper as test.support.bytecode_helper (GH-15168)
Rename and document test.bytecode_helper as test.support.bytecode_helper
1 parent a06d683 commit 92777d5

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

Doc/library/test.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,3 +1503,33 @@ script execution tests.
15031503
containing the *source*. If *compiled* is ``True``, both source files will
15041504
be compiled and added to the zip package. Return a tuple of the full zip
15051505
path and the archive name for the zip file.
1506+
1507+
1508+
:mod:`test.support.bytecode_helper` --- Support tools for testing correct bytecode generation
1509+
=============================================================================================
1510+
1511+
.. module:: test.support.bytecode_helper
1512+
:synopsis: Support tools for testing correct bytecode generation.
1513+
1514+
The :mod:`test.support.bytecode_helper` module provides support for testing
1515+
and inspecting bytecode generation.
1516+
1517+
The module defines the follwing class:
1518+
1519+
.. class:: BytecodeTestCase(unittest.TestCase)
1520+
1521+
This class has custom assertion methods for inspecting bytecode.
1522+
1523+
.. method:: BytecodeTestCase.get_disassembly_as_string(co)
1524+
1525+
Return the disassembly of *co* as string.
1526+
1527+
1528+
.. method:: BytecodeTestCase.assertInBytecode(x, opname, argval=_UNSPECIFIED)
1529+
1530+
Return instr if *opname* is found, otherwise throws :exc:`AssertionError`.
1531+
1532+
1533+
.. method:: BytecodeTestCase.assertNotInBytecode(x, opname, argval=_UNSPECIFIED)
1534+
1535+
Throws :exc:`AssertionError` if *opname* is found.

Lib/test/bytecode_helper.py renamed to Lib/test/support/bytecode_helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def get_disassembly_as_string(self, co):
1515
return s.getvalue()
1616

1717
def assertInBytecode(self, x, opname, argval=_UNSPECIFIED):
18-
"""Returns instr if op is found, otherwise throws AssertionError"""
18+
"""Returns instr if opname is found, otherwise throws AssertionError"""
1919
for instr in dis.get_instructions(x):
2020
if instr.opname == opname:
2121
if argval is _UNSPECIFIED or instr.argval == argval:
@@ -29,7 +29,7 @@ def assertInBytecode(self, x, opname, argval=_UNSPECIFIED):
2929
self.fail(msg)
3030

3131
def assertNotInBytecode(self, x, opname, argval=_UNSPECIFIED):
32-
"""Throws AssertionError if op is found"""
32+
"""Throws AssertionError if opname is found"""
3333
for instr in dis.get_instructions(x):
3434
if instr.opname == opname:
3535
disassembly = self.get_disassembly_as_string(x)

Lib/test/test_dis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Minimal tests for dis module
22

33
from test.support import captured_stdout
4-
from test.bytecode_helper import BytecodeTestCase
4+
from test.support.bytecode_helper import BytecodeTestCase
55
import unittest
66
import sys
77
import dis

Lib/test/test_peepholer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import dis
22
import unittest
33

4-
from test.bytecode_helper import BytecodeTestCase
4+
from test.support.bytecode_helper import BytecodeTestCase
55

66

77
def count_instr_recursively(f, opname):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Renamed and documented `test.bytecode_helper` as `test.support.bytecode_helper`.
2+
Patch by Joannah Nanjekye.

0 commit comments

Comments
 (0)