diff -r 1f4aed2c914c Doc/library/test.rst --- a/Doc/library/test.rst Sun Aug 11 20:13:36 2013 +0300 +++ b/Doc/library/test.rst Mon Aug 12 19:11:41 2013 +0200 @@ -594,3 +594,44 @@ Class used to record warnings for unit tests. See documentation of :func:`check_warnings` above for more details. + + +:mod:`test.support.bytecode_helper` +=================================== + +.. module:: test.support.bytecode_helper + :synopsis: Support tools for testing correct bytecode generation + + +This module defines the following class: + +.. class:: BytecodeTestCase() + + Class used to provide custom assertion methods for inspecting bytecode. + +.. method:: BytecodeTestCase.get_disassembly_as_string(co) + +.. method:: BytecodeTestCase.assertInstructionMatches(instr, expected, *, line_offset=0) + +.. method:: BytecodeTestCase.assertBytecodeExactlyMatches(x, expected, *, line_offset=0) + + Throws AssertionError if any discrepancy is found in bytecode + + *x* is the object to be introspected + *expected* is a list of dis.Instruction objects + + Set *line_offset* as appropriate to adjust for the location of the + object to be disassembled within the test file. If the expected list + assumes the first line is line 1, then an appropriate offset would be + ``1 - f.__code__.co_firstlineno``. + + + +.. method:: BytecodeTestCase.assertInBytecode(x, opname, argval=object()) + + Returns a dis.Instruction object if *opname* is found, otherwise throws AssertionError. + + +.. method:: BytecodeTestCase.assertNotInBytecode(x, opname, argval=object()) + + Throws AssertionError if *opname* is found. diff -r 1f4aed2c914c Lib/test/test_dis.py --- a/Lib/test/test_dis.py Sun Aug 11 20:13:36 2013 +0300 +++ b/Lib/test/test_dis.py Mon Aug 12 19:11:41 2013 +0200 @@ -1,7 +1,7 @@ # Minimal tests for dis module from test.support import run_unittest, captured_stdout -from test.bytecode_helper import BytecodeTestCase +from test.support.bytecode_helper import BytecodeTestCase import difflib import unittest import sys diff -r 1f4aed2c914c Lib/test/test_peepholer.py --- a/Lib/test/test_peepholer.py Sun Aug 11 20:13:36 2013 +0300 +++ b/Lib/test/test_peepholer.py Mon Aug 12 19:11:41 2013 +0200 @@ -5,7 +5,7 @@ import unittest from math import copysign -from test.bytecode_helper import BytecodeTestCase +from test.support.bytecode_helper import BytecodeTestCase class TestTranforms(BytecodeTestCase):