[3.12] gh-127637: add tests for `dis` command-line interface (#127759) by picnixz · Pull Request #127780 · python/cpython · GitHub
Skip to content
Merged
4 changes: 2 additions & 2 deletions Lib/dis.py
20 changes: 17 additions & 3 deletions Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
import contextlib
import dis
import io
import opcode
import re
import sys
import tempfile
import types
import unittest
from test.support import (captured_stdout, requires_debug_ranges,
requires_specialization, cpython_only)
requires_specialization, cpython_only,
os_helper)
from test.support.bytecode_helper import BytecodeTestCase

import opcode


def get_tb():
def _error():
Expand Down Expand Up @@ -2069,5 +2070,18 @@ def get_disassembly(self, tb):
return output.getvalue()


class TestDisCLI(unittest.TestCase):

def setUp(self):
self.filename = tempfile.mktemp()
self.addCleanup(os_helper.unlink, self.filename)

def test_invocation(self):
with self.assertRaises(SystemExit):
# suppress argparse error message
with contextlib.redirect_stderr(io.StringIO()):
dis.main(args=['--unknown', self.filename])


if __name__ == "__main__":
unittest.main()