Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 436831d

Browse files
committed
Issue22642 - Convert trace module's option handling mechanism from getopt to argparse.
Patch contributed by SilentGhost.
1 parent 121edbf commit 436831d

2 files changed

Lines changed: 156 additions & 205 deletions

File tree

Lib/test/test_trace.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import sys
33
from test.support import TESTFN, rmtree, unlink, captured_stdout
4+
from test.support.script_helper import assert_python_ok, assert_python_failure
45
import unittest
56

67
import trace
@@ -364,6 +365,27 @@ def test_ignored(self):
364365
# Matched before.
365366
self.assertTrue(ignore.names(jn('bar', 'baz.py'), 'baz'))
366367

368+
class TestCommandLine(unittest.TestCase):
369+
370+
def test_failures(self):
371+
_errors = (
372+
(b'filename is missing: required with the main options', '-l', '-T'),
373+
(b'cannot specify both --listfuncs and (--trace or --count)', '-lc'),
374+
(b'argument -R/--no-report: not allowed with argument -r/--report', '-rR'),
375+
(b'must specify one of --trace, --count, --report, --listfuncs, or --trackcalls', '-g'),
376+
(b'-r/--report requires -f/--file', '-r'),
377+
(b'--summary can only be used with --count or --report', '-sT'),
378+
(b'unrecognized arguments: -y', '-y'))
379+
for message, *args in _errors:
380+
*_, stderr = assert_python_failure('-m', 'trace', *args)
381+
self.assertIn(message, stderr)
382+
383+
def test_listfuncs_flag_success(self):
384+
with open(TESTFN, 'w') as fd:
385+
self.addCleanup(unlink, TESTFN)
386+
fd.write("a = 1\n")
387+
status, stdout, stderr = assert_python_ok('-m', 'trace', '-l', TESTFN)
388+
self.assertIn(b'functions called:', stdout)
367389

368390
if __name__ == '__main__':
369391
unittest.main()

0 commit comments

Comments
 (0)