Skip to content

bpo-18578: Rename and document test.bytecode_helper as test.support.bytecode_helper #15168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Doc/library/test.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1400,3 +1400,33 @@ script execution tests.
containing the *source*. If *compiled* is ``True``, both source files will
be compiled and added to the zip package. Return a tuple of the full zip
path and the archive name for the zip file.


:mod:`test.support.bytecode_helper` --- Support tools for testing correct bytecode generation
=============================================================================================

.. module:: test.support.bytecode_helper
:synopsis: Support tools for testing correct bytecode generation.

The :mod:`test.support.bytecode_helper` module provides support for testing
and inspecting bytecode generation.

The module defines the follwing class:

.. class:: BytecodeTestCase(unittest.TestCase)

This class has custom assertion methods for inspecting bytecode.

.. method:: BytecodeTestCase.get_disassembly_as_string(co)

Return the disassembly of *co* as string.


.. method:: BytecodeTestCase.assertInBytecode(x, opname, argval=_UNSPECIFIED)

Return instr if *opname* is found, otherwise throws :exc:`AssertionError`.


.. method:: BytecodeTestCase.assertNotInBytecode(x, opname, argval=_UNSPECIFIED)

Throws :exc:`AssertionError` if *opname* is found.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def get_disassembly_as_string(self, co):
return s.getvalue()

def assertInBytecode(self, x, opname, argval=_UNSPECIFIED):
"""Returns instr if op is found, otherwise throws AssertionError"""
"""Returns instr if opname is found, otherwise throws AssertionError"""
for instr in dis.get_instructions(x):
if instr.opname == opname:
if argval is _UNSPECIFIED or instr.argval == argval:
Expand All @@ -29,7 +29,7 @@ def assertInBytecode(self, x, opname, argval=_UNSPECIFIED):
self.fail(msg)

def assertNotInBytecode(self, x, opname, argval=_UNSPECIFIED):
"""Throws AssertionError if op is found"""
"""Throws AssertionError if opname is found"""
for instr in dis.get_instructions(x):
if instr.opname == opname:
disassembly = self.get_disassembly_as_string(x)
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_dis.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Minimal tests for dis module

from test.support import captured_stdout
from test.bytecode_helper import BytecodeTestCase
from test.support.bytecode_helper import BytecodeTestCase
import unittest
import sys
import dis
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_peepholer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dis
import unittest

from test.bytecode_helper import BytecodeTestCase
from test.support.bytecode_helper import BytecodeTestCase

def count_instr_recursively(f, opname):
count = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Renamed and documented `test.bytecode_helper` as `test.support.bytecode_helper`.
Patch by Joannah Nanjekye.