Debian Codegraph @

tests/test_coverup_17.py

raw symbols SCIP
1 # file scalene/scalene_sigqueue.py:8-48
2 # lines [10, 11, 12, 13, 17, 21, 26, 27, 28, 32, 33, 36, 37, 43, 44, 45, 46, 47, 48]
3 # branches ['26->exit', '26->27', '32->exit', '32->33', '43->44', '45->46', '45->47']
4
5 import pytest
6 import threading
7 from typing import Optional, Any, Generic, TypeVar
8 from scalene.scalene_sigqueue import ScaleneSigQueue
9 import queue
10
11 T = TypeVar("T")
12
13
14 class TestScaleneSigQueue(Generic[T]):
15 # Prevent pytest from considering this class as a test
16 __test__ = False
17
18 def test_scalene_sigqueue(self):
19 # Define a process function that will be called by the queue
20 def process_function(*args):
21 assert args == (
22 1,
23 2,
24 3,
25 ), "The process function did not receive the expected arguments."
26
27 # Create an instance of ScaleneSigQueue
28 sigqueue = ScaleneSigQueue(process_function)
29
30 # Start the queue processing
31 sigqueue.start()
32 assert (
33 sigqueue.thread is not None and sigqueue.thread.is_alive()
34 ), "The thread should be started and alive."
35
36 # Put an item into the queue
37 sigqueue.put((1, 2, 3))
38 # Allow some time for the thread to process the item
39 threading.Event().wait(0.1)
40
41 # Stop the queue processing
42 sigqueue.stop()
43 assert sigqueue.thread is None, "The thread should be stopped and set to None."
44
45 # Test get method
46 sigqueue.put(None)
47 item = sigqueue.get()
48 assert item is None, "The get method should return None."
49
50 # Test put method
51 sigqueue.put((1, 2, 3))
52 item = sigqueue.get()
53 assert item == (1, 2, 3), "The put method should add the item to the queue."
54
55 # Clean up
56 sigqueue.stop()
57
58
59 @pytest.fixture(autouse=True)
60 def run_around_tests():
61 # Before each test
62 yield
63 # After each test
64 # No cleanup needed as the test_scalene_sigqueue function handles its own cleanup