| 1 |
|
| 2 |
|
| 3 |
|
| 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 |
|
| 16 |
__test__ = False |
| 17 |
|
| 18 |
def test_scalene_sigqueue(self): |
| 19 |
|
| 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 |
|
| 28 |
sigqueue = ScaleneSigQueue(process_function) |
| 29 |
|
| 30 |
|
| 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 |
|
| 37 |
sigqueue.put((1, 2, 3)) |
| 38 |
|
| 39 |
threading.Event().wait(0.1) |
| 40 |
|
| 41 |
|
| 42 |
sigqueue.stop() |
| 43 |
assert sigqueue.thread is None, "The thread should be stopped and set to None." |
| 44 |
|
| 45 |
|
| 46 |
sigqueue.put(None) |
| 47 |
item = sigqueue.get() |
| 48 |
assert item is None, "The get method should return None." |
| 49 |
|
| 50 |
|
| 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 |
|
| 56 |
sigqueue.stop() |
| 57 |
|
| 58 |
|
| 59 |
@pytest.fixture(autouse=True) |
| 60 |
def run_around_tests(): |
| 61 |
|
| 62 |
yield |
| 63 |
|
| 64 |
|