| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -790,12 +790,12 @@ def dis(self): | |||
| 790 | 790 | return output.getvalue() | |
| 791 | 791 | ||
| 792 | 792 | ||
| 793 | - def main(): | ||
| 793 | + def main(args=None): | ||
| 794 | 794 | import argparse | |
| 795 | 795 | ||
| 796 | 796 | parser = argparse.ArgumentParser() | |
| 797 | 797 | parser.add_argument('infile', type=argparse.FileType('rb'), nargs='?', default='-') | |
| 798 | - args = parser.parse_args() | ||
| 798 | + args = parser.parse_args(args=args) | ||
| 799 | 799 | with args.infile as infile: | |
| 800 | 800 | source = infile.read() | |
| 801 | 801 | code = compile(source, args.infile.name, "exec") | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,16 +3,17 @@ | |||
| 3 | 3 | import contextlib | |
| 4 | 4 | import dis | |
| 5 | 5 | import io | |
| 6 | + import opcode | ||
| 6 | 7 | import re | |
| 7 | 8 | import sys | |
| 9 | + import tempfile | ||
| 8 | 10 | import types | |
| 9 | 11 | import unittest | |
| 10 | 12 | from test.support import (captured_stdout, requires_debug_ranges, | |
| 11 | - requires_specialization, cpython_only) | ||
| 13 | + requires_specialization, cpython_only, | ||
| 14 | + os_helper) | ||
| 12 | 15 | from test.support.bytecode_helper import BytecodeTestCase | |
| 13 | 16 | ||
| 14 | - import opcode | ||
| 15 | - | ||
| 16 | 17 | ||
| 17 | 18 | def get_tb(): | |
| 18 | 19 | def _error(): | |
@@ -2069,5 +2070,18 @@ def get_disassembly(self, tb): | |||
| 2069 | 2070 | return output.getvalue() | |
| 2070 | 2071 | ||
| 2071 | 2072 | ||
| 2073 | + class TestDisCLI(unittest.TestCase): | ||
| 2074 | + | ||
| 2075 | + def setUp(self): | ||
| 2076 | + self.filename = tempfile.mktemp() | ||
| 2077 | + self.addCleanup(os_helper.unlink, self.filename) | ||
| 2078 | + | ||
| 2079 | + def test_invocation(self): | ||
| 2080 | + with self.assertRaises(SystemExit): | ||
| 2081 | + # suppress argparse error message | ||
| 2082 | + with contextlib.redirect_stderr(io.StringIO()): | ||
| 2083 | + dis.main(args=['--unknown', self.filename]) | ||
| 2084 | + | ||
| 2085 | + | ||
| 2072 | 2086 | if __name__ == "__main__": | |
| 2073 | 2087 | unittest.main() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + Add tests for the :mod:`dis` command-line interface. Patch by Bénédikt Tran. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments