FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-45578: add tests for `dis.distb` by sobolevn · Pull Request #29332 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
40 changes: 40 additions & 0 deletions Lib/test/test_dis.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1359,5 +1359,45 @@ def test__find_store_names(self):
self.assertEqual(res, expected)


class TestDisTraceback(unittest.TestCase):
def setUp(self) -> None:
try: # We need to clean up existing tracebacks
del sys.last_traceback
except AttributeError:
pass
return super().setUp()

def get_disassembly(self, tb):
output = io.StringIO()
with contextlib.redirect_stdout(output):
dis.distb(tb)
return output.getvalue()

def test_distb_empty(self):
with self.assertRaises(RuntimeError):
dis.distb()

def test_distb_last_traceback(self):
# We need to have an existing last traceback in `sys`:
tb = get_tb()
sys.last_traceback = tb

self.assertEqual(self.get_disassembly(None), dis_traceback)

def test_distb_explicit_arg(self):
tb = get_tb()

self.assertEqual(self.get_disassembly(tb), dis_traceback)


class TestDisTracebackWithFile(TestDisTraceback):
# Run the `distb` tests again, using the file arg instead of print
def get_disassembly(self, tb):
output = io.StringIO()
with contextlib.redirect_stdout(output):
dis.distb(tb, file=output)
return output.getvalue()


if __name__ == "__main__":
unittest.main()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add tests for :func:`dis.distb`

Back | FazBrowse Home | New Git URL