Debian Codegraph @

tests/test_coverup_94.py

raw symbols SCIP
1 # file scalene/scalene_statistics.py:352-363
2 # lines [354, 355, 359, 360, 362, 363]
3 # branches []
4
5 import os
6 import pathlib
7 import pytest
8 from scalene.scalene_statistics import ScaleneStatistics
9 from unittest.mock import patch, PropertyMock
10
11
12 @pytest.fixture
13 def scalene_statistics():
14 return ScaleneStatistics()
15
16
17 @pytest.fixture
18 def temp_dir(tmp_path):
19 return tmp_path
20
21
22 def test_output_stats(scalene_statistics, temp_dir):
23 pid = 1234
24 with patch(
25 "scalene.scalene_statistics.ScaleneStatistics.payload_contents",
26 new_callable=PropertyMock,
27 ) as mock_payload:
28 mock_payload.return_value = ["cpu_samples_python"]
29 scalene_statistics.cpu_samples_python = 10
30 scalene_statistics.output_stats(pid, temp_dir)
31 out_filename = os.path.join(temp_dir, f"scalene{pid}-{str(os.getpid())}")
32 assert os.path.isfile(out_filename)
33 with open(out_filename, "rb") as out_file:
34 import cloudpickle
35
36 payload = cloudpickle.load(out_file)
37 assert payload == [10]
38 os.remove(out_filename)