-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathconftest.py
More file actions
108 lines (84 loc) · 2.59 KB
/
conftest.py
File metadata and controls
108 lines (84 loc) · 2.59 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import pytest
import tempfile
import shutil
from pathlib import Path
from unittest.mock import Mock, MagicMock
import numpy as np
@pytest.fixture
def temp_dir():
"""Provide a temporary directory for tests."""
temp_path = tempfile.mkdtemp()
yield Path(temp_path)
shutil.rmtree(temp_path)
@pytest.fixture
def sample_emg_data():
"""Provide sample EMG data for testing."""
return np.random.randint(-128, 128, size=(1000, 8))
@pytest.fixture
def mock_myo_device():
"""Mock Myo device for testing."""
mock_device = Mock()
mock_device.stream_emg = Mock()
return mock_device
@pytest.fixture
def mock_myo_hub():
"""Mock Myo Hub for testing."""
mock_hub = Mock()
mock_hub.run = Mock()
return mock_hub
@pytest.fixture
def mock_keras_model():
"""Mock Keras model for testing."""
mock_model = Mock()
mock_model.predict = Mock(return_value=np.array([[0.1, 0.8, 0.05, 0.03, 0.02]]))
mock_model.fit = Mock()
mock_model.save = Mock()
return mock_model
@pytest.fixture
def mock_serial_port():
"""Mock serial port for testing."""
mock_port = Mock()
mock_port.write = Mock()
mock_port.readline = Mock(return_value=b'0')
mock_port.close = Mock()
mock_port.in_waiting = 1
return mock_port
@pytest.fixture
def sample_training_labels():
"""Provide sample training labels."""
return np.array([0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4])
@pytest.fixture
def sample_concatenated_array():
"""Provide sample concatenated array for training."""
return np.random.rand(100, 8)
@pytest.fixture
def mock_matplotlib_plt():
"""Mock matplotlib pyplot for testing."""
mock_plt = Mock()
mock_plt.plot = Mock()
mock_plt.title = Mock()
mock_plt.xlabel = Mock()
mock_plt.ylabel = Mock()
mock_plt.legend = Mock()
mock_plt.show = Mock()
return mock_plt
@pytest.fixture(autouse=True)
def disable_user_input(monkeypatch):
"""Automatically disable user input for all tests."""
monkeypatch.setattr('builtins.input', lambda _: 'test_user')
@pytest.fixture
def mock_process_manager():
"""Mock process management utilities."""
mock_manager = Mock()
mock_manager.check_if_process_running = Mock(return_value=True)
mock_manager.restart_process = Mock(return_value=True)
return mock_manager
@pytest.fixture
def sample_model_history():
"""Provide sample training history for testing."""
return {
'acc': [0.1, 0.3, 0.5, 0.7, 0.9],
'val_acc': [0.15, 0.35, 0.45, 0.65, 0.85],
'loss': [2.0, 1.5, 1.0, 0.5, 0.2],
'val_loss': [1.9, 1.6, 1.2, 0.7, 0.3]
}