Skip to content

Commit e2ff9fc

Browse files
committed
Fix tests
1 parent 9f12a5c commit e2ff9fc

1 file changed

Lines changed: 40 additions & 2 deletions

File tree

Lib/test/test_profiling/test_live_collector.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,44 @@ def test_cycle_sort_invalid_mode(self):
361361
collector._cycle_sort()
362362
self.assertEqual(collector.sort_by, "nsamples")
363363

364+
def test_cycle_sort_backward_from_nsamples(self):
365+
"""Test cycling backward from nsamples goes to cumtime."""
366+
collector = LiveStatsCollector(1000, sort_by="nsamples")
367+
collector._cycle_sort(reverse=True)
368+
self.assertEqual(collector.sort_by, "cumtime")
369+
370+
def test_cycle_sort_backward_from_cumtime(self):
371+
"""Test cycling backward from cumtime goes to cumul_pct."""
372+
collector = LiveStatsCollector(1000, sort_by="cumtime")
373+
collector._cycle_sort(reverse=True)
374+
self.assertEqual(collector.sort_by, "cumul_pct")
375+
376+
def test_cycle_sort_backward_from_sample_pct(self):
377+
"""Test cycling backward from sample_pct goes to nsamples."""
378+
collector = LiveStatsCollector(1000, sort_by="sample_pct")
379+
collector._cycle_sort(reverse=True)
380+
self.assertEqual(collector.sort_by, "nsamples")
381+
382+
def test_input_lowercase_s_cycles_forward(self):
383+
"""Test that lowercase 's' cycles forward."""
384+
display = MockDisplay()
385+
collector = LiveStatsCollector(1000, sort_by="nsamples", display=display)
386+
387+
display.simulate_input(ord("s"))
388+
collector._handle_input()
389+
390+
self.assertEqual(collector.sort_by, "sample_pct")
391+
392+
def test_input_uppercase_s_cycles_backward(self):
393+
"""Test that uppercase 'S' cycles backward."""
394+
display = MockDisplay()
395+
collector = LiveStatsCollector(1000, sort_by="nsamples", display=display)
396+
397+
display.simulate_input(ord("S"))
398+
collector._handle_input()
399+
400+
self.assertEqual(collector.sort_by, "cumtime")
401+
364402

365403
class TestLiveStatsCollectorFormatting(unittest.TestCase):
366404
"""Tests for formatting methods."""
@@ -780,15 +818,15 @@ def test_handle_input_cycle_sort(self):
780818
self.assertEqual(collector.sort_by, "sample_pct")
781819

782820
def test_handle_input_cycle_sort_uppercase(self):
783-
"""Test handling 'S' key to cycle sort."""
821+
"""Test handling 'S' key to cycle sort backward."""
784822
mock_display = MockDisplay()
785823
mock_display.simulate_input(ord("S"))
786824
collector = LiveStatsCollector(
787825
1000, sort_by="nsamples", display=mock_display
788826
)
789827

790828
collector._handle_input()
791-
self.assertEqual(collector.sort_by, "sample_pct")
829+
self.assertEqual(collector.sort_by, "cumtime")
792830

793831
def test_handle_input_no_key(self):
794832
"""Test handling when no key is pressed."""

0 commit comments

Comments
 (0)