Skip to content

Commit 1a86c1b

Browse files
committed
Fix tests
1 parent 3ec314d commit 1a86c1b

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

Lib/test/test_profiling/test_sampling_profiler.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,9 @@ def test_collapsed_stack_collector_with_empty_and_deep_stacks(self):
278278
test_frames = [MockInterpreterInfo(0, [MockThreadInfo(1, [("file.py", 10, "func")])])]
279279
collector.collect(test_frames)
280280
self.assertEqual(len(collector.stack_counter), 1)
281-
((path,), count), = collector.stack_counter.items()
282-
self.assertEqual(path, ("file.py", 10, "func"))
281+
((path, thread_id), count), = collector.stack_counter.items()
282+
self.assertEqual(path, (("file.py", 10, "func"),))
283+
self.assertEqual(thread_id, 1)
283284
self.assertEqual(count, 1)
284285

285286
# Test with very deep stack
@@ -288,10 +289,11 @@ def test_collapsed_stack_collector_with_empty_and_deep_stacks(self):
288289
collector = CollapsedStackCollector()
289290
collector.collect(test_frames)
290291
# One aggregated path with 100 frames (reversed)
291-
(path_tuple,), = (collector.stack_counter.keys(),)
292+
((path_tuple, thread_id),), = (collector.stack_counter.keys(),)
292293
self.assertEqual(len(path_tuple), 100)
293294
self.assertEqual(path_tuple[0], ("file99.py", 99, "func99"))
294295
self.assertEqual(path_tuple[-1], ("file0.py", 0, "func0"))
296+
self.assertEqual(thread_id, 1)
295297

296298
def test_pstats_collector_basic(self):
297299
"""Test basic PstatsCollector functionality."""
@@ -393,9 +395,10 @@ def test_collapsed_stack_collector_basic(self):
393395

394396
# Should store one reversed path
395397
self.assertEqual(len(collector.stack_counter), 1)
396-
(path, count), = collector.stack_counter.items()
398+
((path, thread_id), count), = collector.stack_counter.items()
397399
expected_tree = (("file.py", 20, "func2"), ("file.py", 10, "func1"))
398400
self.assertEqual(path, expected_tree)
401+
self.assertEqual(thread_id, 1)
399402
self.assertEqual(count, 1)
400403

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

427-
# Check collapsed format: file:func:line;file:func:line count
428-
stack1_expected = "file.py:func2:20;file.py:func1:10 2"
429-
stack2_expected = "other.py:other_func:5 1"
430+
# Check collapsed format: tid:X;file:func:line;file:func:line count
431+
stack1_expected = "tid:1;file.py:func2:20;file.py:func1:10 2"
432+
stack2_expected = "tid:1;other.py:other_func:5 1"
430433

431434
self.assertIn(stack1_expected, lines)
432435
self.assertIn(stack2_expected, lines)
@@ -1514,7 +1517,8 @@ def test_collapsed_stack_with_recursion(self):
15141517
self.assertEqual(len(collector.stack_counter), 2)
15151518

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

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

15281532
def total_occurrences(func):
15291533
total = 0
1530-
for path, count in collector.stack_counter.items():
1534+
for (path, thread_id), count in collector.stack_counter.items():
15311535
total += sum(1 for f in path if f == func) * count
15321536
return total
15331537

0 commit comments

Comments
 (0)