🌐 AI搜索 & 代理 主页
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix tests
  • Loading branch information
pablogsal committed Sep 21, 2025
commit 1a86c1b620f557956f6d8316cfb57902e7be4057
22 changes: 13 additions & 9 deletions Lib/test/test_profiling/test_sampling_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,9 @@ def test_collapsed_stack_collector_with_empty_and_deep_stacks(self):
test_frames = [MockInterpreterInfo(0, [MockThreadInfo(1, [("file.py", 10, "func")])])]
collector.collect(test_frames)
self.assertEqual(len(collector.stack_counter), 1)
((path,), count), = collector.stack_counter.items()
self.assertEqual(path, ("file.py", 10, "func"))
((path, thread_id), count), = collector.stack_counter.items()
self.assertEqual(path, (("file.py", 10, "func"),))
self.assertEqual(thread_id, 1)
self.assertEqual(count, 1)

# Test with very deep stack
Expand All @@ -288,10 +289,11 @@ def test_collapsed_stack_collector_with_empty_and_deep_stacks(self):
collector = CollapsedStackCollector()
collector.collect(test_frames)
# One aggregated path with 100 frames (reversed)
(path_tuple,), = (collector.stack_counter.keys(),)
((path_tuple, thread_id),), = (collector.stack_counter.keys(),)
self.assertEqual(len(path_tuple), 100)
self.assertEqual(path_tuple[0], ("file99.py", 99, "func99"))
self.assertEqual(path_tuple[-1], ("file0.py", 0, "func0"))
self.assertEqual(thread_id, 1)

def test_pstats_collector_basic(self):
"""Test basic PstatsCollector functionality."""
Expand Down Expand Up @@ -393,9 +395,10 @@ def test_collapsed_stack_collector_basic(self):

# Should store one reversed path
self.assertEqual(len(collector.stack_counter), 1)
(path, count), = collector.stack_counter.items()
((path, thread_id), count), = collector.stack_counter.items()
expected_tree = (("file.py", 20, "func2"), ("file.py", 10, "func1"))
self.assertEqual(path, expected_tree)
self.assertEqual(thread_id, 1)
self.assertEqual(count, 1)

def test_collapsed_stack_collector_export(self):
Expand Down Expand Up @@ -424,9 +427,9 @@ def test_collapsed_stack_collector_export(self):
lines = content.strip().split("\n")
self.assertEqual(len(lines), 2) # Two unique stacks

# Check collapsed format: file:func:line;file:func:line count
stack1_expected = "file.py:func2:20;file.py:func1:10 2"
stack2_expected = "other.py:other_func:5 1"
# Check collapsed format: tid:X;file:func:line;file:func:line count
stack1_expected = "tid:1;file.py:func2:20;file.py:func1:10 2"
stack2_expected = "tid:1;other.py:other_func:5 1"

self.assertIn(stack1_expected, lines)
self.assertIn(stack2_expected, lines)
Expand Down Expand Up @@ -1514,7 +1517,8 @@ def test_collapsed_stack_with_recursion(self):
self.assertEqual(len(collector.stack_counter), 2)

# First path should be longer (deeper recursion) than the second
paths = list(collector.stack_counter.keys())
path_tuples = list(collector.stack_counter.keys())
paths = [p[0] for p in path_tuples] # Extract just the call paths
lengths = [len(p) for p in paths]
self.assertNotEqual(lengths[0], lengths[1])

Expand All @@ -1527,7 +1531,7 @@ def test_collapsed_stack_with_recursion(self):

def total_occurrences(func):
total = 0
for path, count in collector.stack_counter.items():
for (path, thread_id), count in collector.stack_counter.items():
total += sum(1 for f in path if f == func) * count
return total

Expand Down
Loading