From cdde3ca18c21f8d563417bd13d784f84372417e3 Mon Sep 17 00:00:00 2001 From: jkchandalia Date: Wed, 26 Apr 2023 15:23:47 -0700 Subject: [PATCH 1/4] Add test for dis.disco --- Lib/test/test_dis.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py index bdb541eb3b5686..8164118b56fcd3 100644 --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -909,6 +909,14 @@ def test_widths(self): def test_dis(self): self.do_disassembly_test(_f, dis_f) + def test_disco(self): + func = _f + disassemble_output = self.get_disassembly(func.__code__, wrapper=False) + disco_output = io.StringIO() + with contextlib.redirect_stdout(disco_output): + dis.disco(func.__code__) + self.assertEqual(disassemble_output, disco_output.getvalue()) + def test_bug_708901(self): self.do_disassembly_test(bug708901, dis_bug708901) From 17e5212abcac6c53f18b48fcc75ebbd00e466cdc Mon Sep 17 00:00:00 2001 From: jkchandalia Date: Thu, 27 Apr 2023 12:26:30 -0700 Subject: [PATCH 2/4] Add dis.dicso checks within do_assembly_test --- Lib/test/test_dis.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py index 8164118b56fcd3..8029b6a22d89ff 100644 --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -881,6 +881,11 @@ def do_disassembly_test(self, func, expected, with_offsets=False): self.maxDiff = None got = self.get_disassembly(func, depth=0) self.do_disassembly_compare(got, expected, with_offsets) + # Add checks for dis.disco + got_disco = io.StringIO() + with contextlib.redirect_stdout(got_disco): + dis.disco(func.__code__) + self.do_disassembly_compare(got_disco.getvalue(), expected, with_offsets) def test_opmap(self): self.assertEqual(dis.opmap["NOP"], 9) From f7520629771e8f03ad986c3f532853386a8feba7 Mon Sep 17 00:00:00 2001 From: jkchandalia Date: Thu, 27 Apr 2023 12:57:59 -0700 Subject: [PATCH 3/4] Add check for __code__ attr --- Lib/test/test_dis.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py index 8029b6a22d89ff..8a6f8a1e92de1f 100644 --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -882,10 +882,12 @@ def do_disassembly_test(self, func, expected, with_offsets=False): got = self.get_disassembly(func, depth=0) self.do_disassembly_compare(got, expected, with_offsets) # Add checks for dis.disco - got_disco = io.StringIO() - with contextlib.redirect_stdout(got_disco): - dis.disco(func.__code__) - self.do_disassembly_compare(got_disco.getvalue(), expected, with_offsets) + if hasattr(func, '__code__'): + got_disco = io.StringIO() + with contextlib.redirect_stdout(got_disco): + dis.disco(func.__code__) + self.do_disassembly_compare(got_disco.getvalue(), expected, + with_offsets) def test_opmap(self): self.assertEqual(dis.opmap["NOP"], 9) @@ -914,14 +916,6 @@ def test_widths(self): def test_dis(self): self.do_disassembly_test(_f, dis_f) - def test_disco(self): - func = _f - disassemble_output = self.get_disassembly(func.__code__, wrapper=False) - disco_output = io.StringIO() - with contextlib.redirect_stdout(disco_output): - dis.disco(func.__code__) - self.assertEqual(disassemble_output, disco_output.getvalue()) - def test_bug_708901(self): self.do_disassembly_test(bug708901, dis_bug708901) From 48db7fc0dd4dfa95a7d2b629ac88c748f51ae575 Mon Sep 17 00:00:00 2001 From: jkchandalia Date: Thu, 27 Apr 2023 12:59:07 -0700 Subject: [PATCH 4/4] Format --- Lib/test/test_dis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py index 8a6f8a1e92de1f..5262c5c257cb89 100644 --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -882,7 +882,7 @@ def do_disassembly_test(self, func, expected, with_offsets=False): got = self.get_disassembly(func, depth=0) self.do_disassembly_compare(got, expected, with_offsets) # Add checks for dis.disco - if hasattr(func, '__code__'): + if hasattr(func, '__code__'): got_disco = io.StringIO() with contextlib.redirect_stdout(got_disco): dis.disco(func.__code__)