Debian Codegraph @

tests/test_coverup_22.py

raw symbols SCIP
1 # file scalene/time_info.py:16-29
2 # lines [16, 17, 20, 22, 23, 24, 26, 27, 28, 29]
3 # branches ['17->20', '17->26']
4
5 import os
6 import sys
7 import pytest
8 from unittest.mock import patch, MagicMock
9
10 # Assuming the function get_times is in the module scalene.time_info
11 from scalene.time_info import get_times
12
13
14 class MockResourceUsage:
15 def __init__(self, stime, utime):
16 self.ru_stime = stime
17 self.ru_utime = utime
18
19
20 @pytest.fixture
21 def mock_resource_module():
22 with patch(
23 "resource.getrusage", return_value=MockResourceUsage(1.23, 4.56)
24 ) as mock_resource:
25 yield mock_resource
26
27
28 def test_get_times_linux_mac(mock_resource_module):
29 if sys.platform == "win32":
30 pytest.skip("This test is for Linux/Mac platforms only.")
31 now_sys, now_user = get_times()
32 assert now_sys == 1.23
33 assert now_user == 4.56
34
35
36 @pytest.fixture
37 def mock_os_times():
38 with patch(
39 "os.times", return_value=MagicMock(system=2.34, user=5.67)
40 ) as mock_times:
41 yield mock_times
42
43
44 def test_get_times_win32(mock_os_times):
45 with patch("sys.platform", "win32"):
46 now_sys, now_user = get_times()
47 assert now_sys == 2.34
48 assert now_user == 5.67