Skip to content

Commit 2203021

Browse files
committed
Fix tests
1 parent ff983d8 commit 2203021

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

Lib/profiling/sampling/cli.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,13 +390,17 @@ def _validate_args(args, parser):
390390
"Live mode requires the curses module, which is not available."
391391
)
392392

393-
# Async-aware mode is incompatible with --native and --gc/--no-gc
393+
# Async-aware mode is incompatible with --native, --no-gc, --mode, and --all-threads
394394
if args.async_aware is not None:
395395
issues = []
396396
if args.native:
397397
issues.append("--native")
398398
if not args.gc:
399399
issues.append("--no-gc")
400+
if hasattr(args, 'mode') and args.mode != "wall":
401+
issues.append(f"--mode={args.mode}")
402+
if hasattr(args, 'all_threads') and args.all_threads:
403+
issues.append("--all-threads")
400404
if issues:
401405
parser.error(
402406
f"Options {', '.join(issues)} are incompatible with --async-aware. "

Lib/test/test_profiling/test_sampling_profiler/test_cli.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,3 +659,37 @@ def test_async_aware_incompatible_with_both_native_and_no_gc(self):
659659
self.assertIn("--native", error_msg)
660660
self.assertIn("--no-gc", error_msg)
661661
self.assertIn("incompatible with --async-aware", error_msg)
662+
663+
def test_async_aware_incompatible_with_mode(self):
664+
"""Test --async-aware is incompatible with --mode (non-wall)."""
665+
test_args = ["profiling.sampling.cli", "attach", "12345", "--async-aware", "all", "--mode", "cpu"]
666+
667+
with (
668+
mock.patch("sys.argv", test_args),
669+
mock.patch("sys.stderr", io.StringIO()) as mock_stderr,
670+
self.assertRaises(SystemExit) as cm,
671+
):
672+
from profiling.sampling.cli import main
673+
main()
674+
675+
self.assertEqual(cm.exception.code, 2) # argparse error
676+
error_msg = mock_stderr.getvalue()
677+
self.assertIn("--mode=cpu", error_msg)
678+
self.assertIn("incompatible with --async-aware", error_msg)
679+
680+
def test_async_aware_incompatible_with_all_threads(self):
681+
"""Test --async-aware is incompatible with --all-threads."""
682+
test_args = ["profiling.sampling.cli", "attach", "12345", "--async-aware", "running", "--all-threads"]
683+
684+
with (
685+
mock.patch("sys.argv", test_args),
686+
mock.patch("sys.stderr", io.StringIO()) as mock_stderr,
687+
self.assertRaises(SystemExit) as cm,
688+
):
689+
from profiling.sampling.cli import main
690+
main()
691+
692+
self.assertEqual(cm.exception.code, 2) # argparse error
693+
error_msg = mock_stderr.getvalue()
694+
self.assertIn("--all-threads", error_msg)
695+
self.assertIn("incompatible with --async-aware", error_msg)

Lib/test/test_profiling/test_sampling_profiler/test_integration.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,4 +909,6 @@ def test_async_aware_running_sees_only_cpu_task(self):
909909
# Should see the tree structure (supervisor in the parent chain)
910910
self.assertIn("supervisor", output)
911911
# Should see task boundary markers
912-
self.assertIn("<task>", output)
912+
self.assertIn("<task>", output)
913+
# async_aware="running" should NOT see sleeping tasks
914+
self.assertNotIn("sleeping_leaf", output)

0 commit comments

Comments
 (0)