Debian Codegraph @

tests/test_coverup_132.py

raw symbols SCIP
1 # file scalene/scalene_statistics.py:376-384
2 # lines [382, 383, 384]
3 # branches ['382->exit', '382->383', '383->382', '383->384']
4
5 import pytest
6 from scalene.scalene_statistics import ScaleneStatistics, RunningStats
7
8
9 class MockRunningStats(RunningStats):
10 def __init__(self):
11 super().__init__()
12 self.total = 0
13
14 def __iadd__(self, other):
15 self.total += other.total
16 return self
17
18
19 @pytest.fixture
20 def cleanup():
21 # Setup code
22 yield
23 # No teardown code needed for this test
24
25
26 def test_increment_cpu_utilization(cleanup):
27 dest = {
28 "file1.py": {1: MockRunningStats(), 2: MockRunningStats()},
29 "file2.py": {1: MockRunningStats()},
30 }
31 src = {
32 "file1.py": {1: MockRunningStats(), 2: MockRunningStats()},
33 "file2.py": {1: MockRunningStats()},
34 }
35
36 # Simulate some CPU utilization
37 src["file1.py"][1].total += 0.5
38 src["file1.py"][2].total += 0.3
39 src["file2.py"][1].total += 0.2
40
41 ScaleneStatistics.increment_cpu_utilization(dest, src)
42
43 # Assertions to check if the CPU utilization has been incremented correctly
44 assert dest["file1.py"][1].total == 0.5
45 assert dest["file1.py"][2].total == 0.3
46 assert dest["file2.py"][1].total == 0.2