Debian Codegraph @

tests/test_coverup_53.py

raw symbols SCIP
1 # file scalene/scalene_profiler.py:1808-1826
2 # lines [1808, 1809, 1811, 1812, 1813, 1815, 1816, 1817, 1818, 1820, 1822, 1824, 1825, 1826]
3 # branches ['1816->1817', '1816->1820', '1824->exit', '1824->1825']
4
5 import argparse
6 import os
7 import pytest
8 import time
9 from unittest.mock import patch
10 from scalene.scalene_profiler import Scalene, ScaleneArguments
11
12
13 # Define a fixture to clean up state after each test
14 @pytest.fixture
15 def cleanup_scalene():
16 # Setup: None needed for this test
17 yield
18 # Teardown: Reset class variables to initial state
19 # Assuming that Scalene has a method to clean up its state, which is not the case
20 # We need to manually reset the state if there are no such methods
21 # The following is a placeholder for the actual reset logic
22 # Replace with the actual reset logic if available
23 if hasattr(Scalene, "_Scalene__args"):
24 del Scalene._Scalene__args
25 if hasattr(Scalene, "_Scalene__next_output_time"):
26 del Scalene._Scalene__next_output_time
27 if hasattr(Scalene, "_Scalene__output"):
28 del Scalene._Scalene__output
29 if hasattr(Scalene, "_Scalene__is_child"):
30 del Scalene._Scalene__is_child
31 if hasattr(Scalene, "_Scalene__parent_pid"):
32 del Scalene._Scalene__parent_pid
33 if hasattr(Scalene, "_Scalene__json"):
34 del Scalene._Scalene__json
35
36
37 def test_process_args(cleanup_scalene):
38 # Create a Namespace object with the necessary attributes
39 args = argparse.Namespace(
40 profile_interval=1, html=False, outfile="test_output.txt", pid=12345, gpu=False
41 )
42
43 # Mock time.perf_counter to return a known value
44 with patch("time.perf_counter", return_value=100):
45 # Call the method under test
46 Scalene.process_args(args)
47
48 # Assertions to verify postconditions
49 # Accessing the private attributes directly for testing purposes
50 assert Scalene._Scalene__next_output_time == 101 # 100 + 1
51 assert Scalene._Scalene__output.html == args.html
52 assert Scalene._Scalene__output.output_file == os.path.abspath(
53 os.path.expanduser(args.outfile)
54 )
55 assert Scalene._Scalene__is_child == True
56 assert Scalene._Scalene__parent_pid == args.pid
57 assert not Scalene._Scalene__output.gpu
58 assert not Scalene._Scalene__json.gpu
59
60 # Clean up by removing the test output file if it was created
61 if os.path.exists(args.outfile):
62 os.remove(args.outfile)