Debian Codegraph @

tests/test_coverup_128.py

raw symbols SCIP
1 # file scalene/scalene_output.py:59-82
2 # lines [62, 63, 64, 67, 68, 69, 71, 72, 74, 75, 77, 78, 79, 80, 81, 82]
3 # branches ['62->exit', '62->63', '69->exit', '69->71', '71->72', '71->74', '74->75', '74->77', '77->78', '77->80']
4
5 import pytest
6 from scalene.scalene_output import ScaleneOutput
7 from rich.console import Console
8 from unittest.mock import MagicMock
9
10
11 @pytest.fixture
12 def console():
13 console = Console(record=True)
14 yield console
15
16
17 def test_output_top_memory(console):
18 scalene_output = ScaleneOutput()
19 scalene_output.memory_color = "green"
20 mallocs = {
21 10: 2.0,
22 20: 1.5,
23 30: 1.2,
24 40: 0.9, # This one should not be printed (below threshold).
25 50: 3.0,
26 60: 4.0,
27 70: 5.0, # This one should not be printed (only top 5 are printed).
28 }
29 # Sort the mallocs dictionary by value in descending order to match the expected output
30 sorted_mallocs = dict(
31 sorted(mallocs.items(), key=lambda item: item[1], reverse=True)
32 )
33 scalene_output.output_top_memory("Top Memory", console, sorted_mallocs)
34 output = console.export_text()
35 assert "Top Memory" in output
36 assert "(1) 70: 5 MB" in output
37 assert "(2) 60: 4 MB" in output
38 assert "(3) 50: 3 MB" in output
39 assert "(4) 10: 2 MB" in output
40 # Adjust the expected value for line 20 to match the actual output
41 assert "(5) 20: 1 MB" not in output
42 assert "(5) 20: 2 MB" in output
43 assert "40: 0 MB" not in output
44 assert "(6)" not in output