forked from stratosphereips/StratosphereLinuxIPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
59 lines (46 loc) · 1.59 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
This file will contain the fixtures that are commonly needed by all other test files
for example: setting up the database, input_queue, output_queue, etc..
"""
import pytest
import os, sys, inspect
from multiprocessing import Queue
from unittest.mock import patch
from slips_files.core.database.database_manager import DBManager
# add parent dir to path for imports to work
current_dir = os.path.dirname(
os.path.abspath(inspect.getfile(inspect.currentframe()))
)
parent_dir = os.path.dirname(current_dir)
sys.path.insert(0, parent_dir)
@pytest.fixture
def mock_db():
# Create a mock version of the database object
with patch('slips_files.core.database.database_manager.DBManager') as mock:
yield mock.return_value
def do_nothing(*arg):
"""Used to override the print function because using the self.print causes broken pipes"""
pass
@pytest.fixture
def output_queue():
"""This output_queue will be passed to all module constructors that need it"""
output_queue = Queue()
output_queue.put = do_nothing
return Queue()
@pytest.fixture
def input_queue():
"""This input_queue will be passed to all module constructors that need it"""
input_queue = Queue()
input_queue.put = do_nothing
return input_queue
@pytest.fixture
def profiler_queue():
"""This profiler_queue will be passed to all module constructors that need it"""
profiler_queue = Queue()
profiler_queue.put = do_nothing
return profiler_queue
@pytest.fixture
def database(output_queue):
db = DBManager('output/', output_queue, 6379)
db.print = do_nothing
return db