@@ -208,3 +208,64 @@ def test_term_cleanup(app_pidfile_env):
208
208
# File should not exist anymore so no error to create one
209
209
# File must exist to be cleaned by tempfile
210
210
open (tmpfile .name , 'x' )
211
+
212
+
213
+ class CtrlMock1 (riotctrl .ctrl .RIOTCtrl ):
214
+ """Mock to test RIOTCtrlFactoryBase descendents"""
215
+
216
+
217
+ class CtrlMock2 (riotctrl .ctrl .RIOTCtrl ):
218
+ """Another mock to test RIOTCtrlFactoryBase descendents"""
219
+
220
+
221
+ def test_board_factory_wo_board ():
222
+ """Tests if riotctrl.ctrl.RIOTCtrlBoardFactory defaults to
223
+ riotctrl.ctrl.RIOTCtrl if no mapping exists for a device"""
224
+ factory = riotctrl .ctrl .RIOTCtrlBoardFactory ()
225
+ assert factory .DEFAULT_CLS is riotctrl .ctrl .RIOTCtrl
226
+ ctrl = factory .get_ctrl ()
227
+ # pylint: disable=unidiomatic-typecheck
228
+ # in this case we want to know the exact type
229
+ assert type (ctrl ) is riotctrl .ctrl .RIOTCtrl
230
+
231
+
232
+ def test_w_board_in_default_board_cls ():
233
+ """Tests if riotctrl.ctrl.RIOTCtrlBoardFactory returns a class in the
234
+ static mapping of the factory exists"""
235
+ env = {'BOARD' : 'mock' }
236
+ riotctrl .ctrl .RIOTCtrlBoardFactory .BOARD_CLS = {'mock' : CtrlMock1 }
237
+ factory = riotctrl .ctrl .RIOTCtrlBoardFactory ()
238
+ assert 'mock' in factory .board_cls
239
+ ctrl = factory .get_ctrl (env = env )
240
+ # pylint: disable=unidiomatic-typecheck
241
+ # in this case we want to know the exact type
242
+ assert type (ctrl ) is CtrlMock1
243
+
244
+
245
+ def test_w_board_in_not_default_board_cls ():
246
+ """Tests if riotctrl.ctrl.RIOTCtrlBoardFactory defaults to
247
+ riotctrl.ctrl.RIOTCtrl if no mapping exists for a device with an existing
248
+ mapping"""
249
+ env = {'BOARD' : 'foobar' }
250
+ riotctrl .ctrl .RIOTCtrlBoardFactory .BOARD_CLS = {'mock' : CtrlMock1 }
251
+ factory = riotctrl .ctrl .RIOTCtrlBoardFactory ()
252
+ assert 'mock' in factory .board_cls
253
+ ctrl = factory .get_ctrl (env = env )
254
+ # pylint: disable=unidiomatic-typecheck
255
+ # in this case we want to know the exact type
256
+ assert type (ctrl ) is riotctrl .ctrl .RIOTCtrl
257
+
258
+
259
+ def test_w_board_custom_board_cls ():
260
+ """Tests if riotctrl.ctrl.RIOTCtrlBoardFactory returns a class in the
261
+ dynamic mapping of the factory exists"""
262
+ env = {'BOARD' : 'mock' }
263
+ riotctrl .ctrl .RIOTCtrlBoardFactory .BOARD_CLS = {'mock' : CtrlMock1 }
264
+ factory = riotctrl .ctrl .RIOTCtrlBoardFactory (
265
+ board_cls = {'mock' : CtrlMock2 }
266
+ )
267
+ assert 'mock' in factory .board_cls
268
+ ctrl = factory .get_ctrl (env = env )
269
+ # pylint: disable=unidiomatic-typecheck
270
+ # in this case we want to know the exact type
271
+ assert type (ctrl ) is CtrlMock2
0 commit comments