]> granicus.if.org Git - python/commitdiff
bpo-18578: Rename and document test.bytecode_helper as test.support.bytecode_helper...
authorJoannah Nanjekye <33177550+nanjekyejoannah@users.noreply.github.com>
Thu, 12 Sep 2019 09:02:59 +0000 (10:02 +0100)
committerStéphane Wirtel <stephane@wirtel.be>
Thu, 12 Sep 2019 09:02:59 +0000 (10:02 +0100)
Rename and document test.bytecode_helper as test.support.bytecode_helper

Doc/library/test.rst
Lib/test/support/bytecode_helper.py [moved from Lib/test/bytecode_helper.py with 91% similarity]
Lib/test/test_dis.py
Lib/test/test_peepholer.py
Misc/NEWS.d/next/Library/2019-08-07-19-34-07.bpo-18578.xfvdb_.rst [new file with mode: 0644]

index 6eef5c65499a8440b88bc38ed631352d4b8e98aa..5dde55cdf951a898b6824a4a57a9ceab9c11ec88 100644 (file)
@@ -1503,3 +1503,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.
similarity index 91%
rename from Lib/test/bytecode_helper.py
rename to Lib/test/support/bytecode_helper.py
index 347d60337d763b5fe1da073eef269a52d5f55b6e..348e277c1658823bb55ed94cbbdd716f6c200a1f 100644 (file)
@@ -15,7 +15,7 @@ class BytecodeTestCase(unittest.TestCase):
         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:
@@ -29,7 +29,7 @@ class BytecodeTestCase(unittest.TestCase):
         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)
index 11f97e6c083834a45b31d94e38dee092afe6cbe0..fecf203cc9b5f76a3703442e5969d7dee7cb73f0 100644 (file)
@@ -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
index c90a53210a93162e4e86306a5a9d5236677d881f..47dee33076c5348fd5b71ff0981d8cb10dc5cbd4 100644 (file)
@@ -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):
diff --git a/Misc/NEWS.d/next/Library/2019-08-07-19-34-07.bpo-18578.xfvdb_.rst b/Misc/NEWS.d/next/Library/2019-08-07-19-34-07.bpo-18578.xfvdb_.rst
new file mode 100644 (file)
index 0000000..cc0e02f
--- /dev/null
@@ -0,0 +1,2 @@
+Renamed and documented `test.bytecode_helper` as `test.support.bytecode_helper`.\r
+Patch by Joannah Nanjekye.
\ No newline at end of file