summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_dis.py63
-rw-r--r--Misc/NEWS3
2 files changed, 33 insertions, 33 deletions
diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index 9edf602..b86cc86 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -6,6 +6,7 @@ import unittest
import sys
import dis
import io
+import re
class _C:
def __init__(self, x):
@@ -89,26 +90,25 @@ def bug1333982(x=[]):
dis_bug1333982 = """\
%-4d 0 LOAD_CONST 1 (0)
- 3 JUMP_IF_TRUE 33 (to 39)
- 6 POP_TOP
- 7 LOAD_GLOBAL 0 (AssertionError)
- 10 BUILD_LIST 0
- 13 LOAD_FAST 0 (x)
- 16 GET_ITER
- >> 17 FOR_ITER 12 (to 32)
- 20 STORE_FAST 1 (s)
- 23 LOAD_FAST 1 (s)
- 26 LIST_APPEND 2
- 29 JUMP_ABSOLUTE 17
-
- %-4d >> 32 LOAD_CONST 2 (1)
- 35 BINARY_ADD
- 36 RAISE_VARARGS 2
- >> 39 POP_TOP
-
- %-4d 40 LOAD_CONST 0 (None)
- 43 RETURN_VALUE
+ 3 POP_JUMP_IF_TRUE 35
+ 6 LOAD_GLOBAL 0 (AssertionError)
+ 9 LOAD_CONST 2 (<code object <listcomp> at 0x..., file "%s", line %d>)
+ 12 LOAD_CONST 3 ('bug1333982.<locals>.<listcomp>')
+ 15 MAKE_FUNCTION 0
+ 18 LOAD_FAST 0 (x)
+ 21 GET_ITER
+ 22 CALL_FUNCTION 1 (1 positional, 0 keyword pair)
+
+ %-4d 25 LOAD_CONST 4 (1)
+ 28 BINARY_ADD
+ 29 CALL_FUNCTION 1 (1 positional, 0 keyword pair)
+ 32 RAISE_VARARGS 1
+
+ %-4d >> 35 LOAD_CONST 0 (None)
+ 38 RETURN_VALUE
""" % (bug1333982.__code__.co_firstlineno + 1,
+ __file__,
+ bug1333982.__code__.co_firstlineno + 1,
bug1333982.__code__.co_firstlineno + 2,
bug1333982.__code__.co_firstlineno + 3)
@@ -193,8 +193,13 @@ class DisTests(unittest.TestCase):
def do_disassembly_test(self, func, expected):
lines = self.get_disassembly(func)
expected = expected.splitlines()
- if expected != lines:
- self.fail(
+ if expected == lines:
+ return
+ else:
+ lines = [re.sub('0x[0-9A-Fa-f]+', '0x...', l) for l in lines]
+ if expected == lines:
+ return
+ self.fail(
"events did not match expectation:\n" +
"\n".join(difflib.ndiff(expected,
lines)))
@@ -217,18 +222,13 @@ class DisTests(unittest.TestCase):
def test_bug_708901(self):
self.do_disassembly_test(bug708901, dis_bug708901)
- # Test has been disabled due to change in the way
- # list comps are handled. The byte code now includes
- # a memory address and a file location, so they change from
- # run to run.
- @unittest.skip('disabled due to a change in the way list comps are handled')
def test_bug_1333982(self):
- # XXX: re-enable this test!
# This one is checking bytecodes generated for an `assert` statement,
# so fails if the tests are run with -O. Skip this test then.
+ if not __debug__:
+ self.skipTest('need asserts, run without -O')
- if __debug__:
- self.do_disassembly_test(bug1333982, dis_bug1333982)
+ self.do_disassembly_test(bug1333982, dis_bug1333982)
def test_big_linenos(self):
def func(count):
@@ -451,8 +451,5 @@ class CodeInfoTests(unittest.TestCase):
self.assertEqual(dis.pretty_flags(0), '0x0')
-def test_main():
- run_unittest(DisTests, CodeInfoTests)
-
if __name__ == "__main__":
- test_main()
+ unittest.main()
diff --git a/Misc/NEWS b/Misc/NEWS
index 334b8f7..547f108 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -182,6 +182,9 @@ IDLE
Tests
-----
+- Issue #19938: Re-enabled test_bug_1333982 in test_dis, which had been
+ disabled since 3.0 due to the changes in listcomp handling.
+
- Issue #19320: test_tcl no longer fails when wantobjects is false.
- Issue #19683: Removed empty tests from test_minidom. Patch by Ajitesh Gupta.