[Python-checkins] bpo-42199: Fix bytecode_helper assertNotInBytecode (#23031)

DinoV webhook-mailer at python.org
Thu Dec 17 19:30:40 EST 2020


https://github.com/python/cpython/commit/6e799be0a18d0bb5bbbdc77cd3c30a229d31dfb4
commit: 6e799be0a18d0bb5bbbdc77cd3c30a229d31dfb4
branch: master
author: Max Bernstein <tekknolagi at users.noreply.github.com>
committer: DinoV <dinoviehland at gmail.com>
date: 2020-12-17T16:30:29-08:00
summary:

bpo-42199: Fix bytecode_helper assertNotInBytecode (#23031)

* bpo-42199: Fix bytecode_helper assertNotInBytecode

Add tests.

* 📜🤖 Added by blurb_it.

Co-authored-by: Dino Viehland <dinoviehland at fb.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>

files:
A Misc/NEWS.d/next/Tests/2020-10-29-21-26-46.bpo-42199.KksGCV.rst
M Lib/test/support/bytecode_helper.py
M Lib/test/test_dis.py

diff --git a/Lib/test/support/bytecode_helper.py b/Lib/test/support/bytecode_helper.py
index 348e277c16588..471d4a68f915a 100644
--- a/Lib/test/support/bytecode_helper.py
+++ b/Lib/test/support/bytecode_helper.py
@@ -35,7 +35,8 @@ def assertNotInBytecode(self, x, opname, argval=_UNSPECIFIED):
                 disassembly = self.get_disassembly_as_string(x)
                 if argval is _UNSPECIFIED:
                     msg = '%s occurs in bytecode:\n%s' % (opname, disassembly)
+                    self.fail(msg)
                 elif instr.argval == argval:
                     msg = '(%s,%r) occurs in bytecode:\n%s'
                     msg = msg % (opname, argval, disassembly)
-                self.fail(msg)
+                    self.fail(msg)
diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index 786744923eb46..d5d815dc5dc55 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -1212,5 +1212,24 @@ def test_from_traceback_dis(self):
         b = dis.Bytecode.from_traceback(tb)
         self.assertEqual(b.dis(), dis_traceback)
 
+
+class TestBytecodeTestCase(BytecodeTestCase):
+    def test_assert_not_in_with_op_not_in_bytecode(self):
+        code = compile("a = 1", "<string>", "exec")
+        self.assertInBytecode(code, "LOAD_CONST", 1)
+        self.assertNotInBytecode(code, "LOAD_NAME")
+        self.assertNotInBytecode(code, "LOAD_NAME", "a")
+
+    def test_assert_not_in_with_arg_not_in_bytecode(self):
+        code = compile("a = 1", "<string>", "exec")
+        self.assertInBytecode(code, "LOAD_CONST")
+        self.assertInBytecode(code, "LOAD_CONST", 1)
+        self.assertNotInBytecode(code, "LOAD_CONST", 2)
+
+    def test_assert_not_in_with_arg_in_bytecode(self):
+        code = compile("a = 1", "<string>", "exec")
+        with self.assertRaises(AssertionError):
+            self.assertNotInBytecode(code, "LOAD_CONST", 1)
+
 if __name__ == "__main__":
     unittest.main()
diff --git a/Misc/NEWS.d/next/Tests/2020-10-29-21-26-46.bpo-42199.KksGCV.rst b/Misc/NEWS.d/next/Tests/2020-10-29-21-26-46.bpo-42199.KksGCV.rst
new file mode 100644
index 0000000000000..4426f336368bf
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2020-10-29-21-26-46.bpo-42199.KksGCV.rst
@@ -0,0 +1 @@
+Fix bytecode helper assertNotInBytecode.
\ No newline at end of file



More information about the Python-checkins mailing list