|
1 | 1 | import os |
2 | 2 | import sys |
3 | 3 | from test.support import TESTFN, rmtree, unlink, captured_stdout |
| 4 | +from test.support.script_helper import assert_python_ok, assert_python_failure |
4 | 5 | import unittest |
5 | 6 |
|
6 | 7 | import trace |
@@ -364,6 +365,27 @@ def test_ignored(self): |
364 | 365 | # Matched before. |
365 | 366 | self.assertTrue(ignore.names(jn('bar', 'baz.py'), 'baz')) |
366 | 367 |
|
| 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) |
367 | 389 |
|
368 | 390 | if __name__ == '__main__': |
369 | 391 | unittest.main() |
0 commit comments