Skip to content

Commit 06bb9b5

Browse files
committed
Stub stk and restore parseGCode test
1 parent 1859f21 commit 06bb9b5

File tree

3 files changed

+353
-54
lines changed

3 files changed

+353
-54
lines changed

src/figure_editor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ def __init__(
5858

5959
self.params_widgets = []
6060
# TODO add implementation of True/False parameters
61-
self.params_dict: Dict[str, float] = dict(
62-
(el, initial_params[el] if initial_params and initial_params[el] else 0)
61+
self.params_dict: Dict[str, float] = {
62+
el: initial_params.get(el, 0) if initial_params else 0
6363
for el in params + self._checkboxes
64-
)
64+
}
6565

6666
for param_idx, param in enumerate(params):
6767
# add label for parameter name

test/figure_editor_test.py

Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
1+
import sys
2+
import types
3+
import unittest
4+
5+
# --- Begin stubs for PyQt5 and related modules ---
6+
7+
class Signal:
8+
def __init__(self):
9+
self._callbacks = []
10+
11+
def connect(self, func):
12+
self._callbacks.append(func)
13+
14+
15+
class QStyle:
16+
SP_DialogApplyButton = 0
17+
18+
def standardIcon(self, *args, **kwargs):
19+
return None
20+
21+
22+
class QWidget:
23+
def __init__(self, *args, **kwargs):
24+
pass
25+
26+
def setLayout(self, *args, **kwargs):
27+
pass
28+
29+
def style(self):
30+
return QStyle()
31+
32+
def setWindowTitle(self, *args, **kwargs):
33+
pass
34+
35+
36+
class QGridLayout:
37+
def __init__(self, *args, **kwargs):
38+
pass
39+
40+
def setSpacing(self, *args, **kwargs):
41+
pass
42+
43+
def addWidget(self, *args, **kwargs):
44+
pass
45+
46+
47+
class QHBoxLayout:
48+
def __init__(self, *args, **kwargs):
49+
pass
50+
51+
def addWidget(self, *args, **kwargs):
52+
pass
53+
54+
def addLayout(self, *args, **kwargs):
55+
pass
56+
57+
58+
class QVBoxLayout:
59+
def __init__(self, *args, **kwargs):
60+
pass
61+
62+
def addWidget(self, *args, **kwargs):
63+
pass
64+
65+
def addLayout(self, *args, **kwargs):
66+
pass
67+
68+
69+
class QLabel(QWidget):
70+
def __init__(self, *args, **kwargs):
71+
pass
72+
73+
74+
class QLineEdit(QWidget):
75+
def __init__(self, text=""):
76+
self._text = text
77+
self.textChanged = Signal()
78+
79+
def setSizePolicy(self, *args, **kwargs):
80+
pass
81+
82+
def setMinimumWidth(self, *args, **kwargs):
83+
pass
84+
85+
def setReadOnly(self, *args, **kwargs):
86+
pass
87+
88+
def setText(self, text):
89+
self._text = text
90+
91+
92+
class QSlider(QWidget):
93+
def __init__(self, *args, **kwargs):
94+
self.valueChanged = Signal()
95+
96+
def setOrientation(self, *args, **kwargs):
97+
pass
98+
99+
def setMinimum(self, *args, **kwargs):
100+
pass
101+
102+
def setMaximum(self, *args, **kwargs):
103+
pass
104+
105+
def setValue(self, *args, **kwargs):
106+
pass
107+
108+
def setSizePolicy(self, *args, **kwargs):
109+
pass
110+
111+
def setMinimumWidth(self, *args, **kwargs):
112+
pass
113+
114+
def setEnabled(self, *args, **kwargs):
115+
pass
116+
117+
118+
class QSizePolicy:
119+
Minimum = 0
120+
Fixed = 0
121+
Expanding = 0
122+
123+
124+
class QPushButton(QWidget):
125+
def __init__(self, *args, **kwargs):
126+
self.clicked = Signal()
127+
128+
def setIcon(self, *args, **kwargs):
129+
pass
130+
131+
132+
class QCheckBox(QWidget):
133+
def __init__(self, *args, **kwargs):
134+
self.stateChanged = Signal()
135+
136+
def setChecked(self, *args, **kwargs):
137+
pass
138+
139+
140+
class QScrollArea(QWidget):
141+
def setWidget(self, *args, **kwargs):
142+
pass
143+
144+
def setWidgetResizable(self, *args, **kwargs):
145+
pass
146+
147+
148+
class QComboBox(QWidget):
149+
def addItem(self, *args, **kwargs):
150+
pass
151+
152+
153+
class QApplication:
154+
def __init__(self, *args, **kwargs):
155+
pass
156+
157+
158+
qtwidgets = types.ModuleType("PyQt5.QtWidgets")
159+
qtwidgets.QSlider = QSlider
160+
qtwidgets.QLineEdit = QLineEdit
161+
qtwidgets.QApplication = QApplication
162+
qtwidgets.QGridLayout = QGridLayout
163+
qtwidgets.QWidget = QWidget
164+
qtwidgets.QLabel = QLabel
165+
qtwidgets.QSizePolicy = QSizePolicy
166+
qtwidgets.QPushButton = QPushButton
167+
qtwidgets.QHBoxLayout = QHBoxLayout
168+
qtwidgets.QCheckBox = QCheckBox
169+
qtwidgets.QScrollArea = QScrollArea
170+
qtwidgets.QVBoxLayout = QVBoxLayout
171+
qtwidgets.QComboBox = QComboBox
172+
qtwidgets.QStyle = QStyle
173+
sys.modules["PyQt5.QtWidgets"] = qtwidgets
174+
175+
qtcore = types.ModuleType("PyQt5.QtCore")
176+
qtcore.Qt = types.SimpleNamespace(Horizontal=1, Checked=True)
177+
sys.modules["PyQt5.QtCore"] = qtcore
178+
179+
sip = types.ModuleType("sip")
180+
sip.isdeleted = lambda obj: False
181+
pyqt5 = types.ModuleType("PyQt5")
182+
pyqt5.QtCore = qtcore
183+
pyqt5.sip = sip
184+
sys.modules["PyQt5"] = pyqt5
185+
sys.modules["sip"] = sip
186+
187+
# Stub out project-specific modules that depend on PyQt5
188+
settings_widget_module = types.ModuleType("src.settings_widget")
189+
190+
191+
class SettingsWidget:
192+
def __init__(self, *args, **kwargs):
193+
self.extra_sett_parameters = []
194+
self.translation = {}
195+
196+
def from_settings(self, *args, **kwargs):
197+
return self
198+
199+
def with_delete(self, *args, **kwargs):
200+
return self
201+
202+
def with_sett(self, *args, **kwargs):
203+
return self
204+
205+
206+
settings_widget_module.SettingsWidget = SettingsWidget
207+
sys.modules["src.settings_widget"] = settings_widget_module
208+
209+
settings_module = types.ModuleType("src.settings")
210+
211+
212+
def sett():
213+
return None
214+
215+
216+
settings_module.sett = sett
217+
sys.modules["src.settings"] = settings_module
218+
219+
locales_module = types.ModuleType("src.locales")
220+
locales_module.getLocale = lambda x: x
221+
sys.modules["src.locales"] = locales_module
222+
223+
# --- End stubs ---
224+
225+
from src.figure_editor import FigureEditor
226+
227+
228+
class DummyTab:
229+
def __init__(self):
230+
self._layout = None
231+
232+
def layout(self):
233+
return self._layout
234+
235+
def setLayout(self, layout):
236+
self._layout = layout
237+
238+
239+
class TabsStub:
240+
def __init__(self):
241+
self._tab = DummyTab()
242+
243+
def widget(self, index):
244+
return self._tab
245+
246+
247+
class FigureEditorTest(unittest.TestCase):
248+
def test_missing_initial_params_defaults_to_zero(self):
249+
tabs = TabsStub()
250+
params = ["length", "width"]
251+
constrains = [(0, 10), (0, 10)]
252+
initial_params = {"length": 5} # 'width' is missing
253+
editor = FigureEditor(
254+
tabs,
255+
params,
256+
constrains,
257+
initial_params=initial_params,
258+
settings_provider=lambda: {},
259+
)
260+
self.assertEqual(editor.params_dict["length"], 5)
261+
self.assertEqual(editor.params_dict["width"], 0)
262+
263+
264+
if __name__ == "__main__":
265+
unittest.main()

0 commit comments

Comments
 (0)