Skip to content

Commit 989dc35

Browse files
committed
Update tests to accommodate the new calculateServoCycleTime function
Updated the names of tests to clearly identify which interface they are testing under Mocked the sendCommand to return a numerical string (the default is non-numerical which would fail the float conversion within calculateServoCycleTime)
1 parent bf01e1d commit 989dc35

File tree

1 file changed

+43
-7
lines changed

1 file changed

+43
-7
lines changed

tests/test_motor.py

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,26 @@ def test_remote_connect_auth_error(self, mock_params, mock_connect, mock_box):
168168
assert ret is None
169169

170170
@patch("PyQt5.QtWidgets.QLabel.setPixmap")
171+
@patch("dls_pmaclib.dls_pmacremote.PmacTelnetInterface.sendCommand")
171172
@patch("dls_pmaclib.dls_pmacremote.PmacTelnetInterface.isModelGeobrick")
172173
@patch("dls_pmaclib.dls_pmacremote.PmacTelnetInterface.getNumberOfAxes")
173174
@patch("dls_pmaclib.dls_pmacremote.PmacTelnetInterface.getPmacModel")
174175
@patch("dls_pmaclib.dls_pmacremote.PmacTelnetInterface.connect")
175176
@patch("dls_pmaclib.dls_pmacremote.PmacTelnetInterface.setConnectionParams")
176-
def test_remote_connect(
177-
self, mock_params, mock_connect, mock_model, mock_axes, mock_geo, mock_pixmap
177+
def test_remote_connect_telnet_interface(
178+
self,
179+
mock_params,
180+
mock_connect,
181+
mock_model,
182+
mock_axes,
183+
mock_geo,
184+
mock_send,
185+
mock_pixmap,
178186
):
179187
mock_model.return_value = "test"
180188
mock_axes.return_value = 8
181189
mock_geo.return_value = True
190+
mock_send.return_value = ("1677721.6", True)
182191
mock_connect.return_value = None
183192
ret = self.obj.remoteConnect()
184193
mock_params.assert_called_with("test", "123")
@@ -260,6 +269,7 @@ def tearDown(self):
260269

261270
class MotorTestTelnetConnectionRequired(unittest.TestCase):
262271
@patch("PyQt5.QtWidgets.QLabel.setPixmap")
272+
@patch("dls_pmaclib.dls_pmacremote.PmacTelnetInterface.sendCommand")
263273
@patch("dls_pmaclib.dls_pmacremote.PmacTelnetInterface.isModelGeobrick")
264274
@patch("dls_pmaclib.dls_pmacremote.PmacTelnetInterface.getNumberOfAxes")
265275
@patch("dls_pmaclib.dls_pmacremote.PmacTelnetInterface.getPmacModel")
@@ -304,13 +314,15 @@ def setUp(
304314
mock_model,
305315
mock_axes,
306316
mock_geo,
317+
mock_send,
307318
mock_pixmap,
308319
):
309320
self.options = DummyTestOptionsTelnet()
310321
self.obj = Controlform(self.options)
311322
mock_model.return_value = "test"
312323
mock_axes.return_value = 8
313324
mock_geo.return_value = True
325+
mock_send.return_value = ("1677721.6", True)
314326
mock_connect.return_value = None
315327
self.obj.remoteConnect()
316328

@@ -461,17 +473,26 @@ def test_remote_connect_auth_error(self, mock_params, mock_connect, mock_box):
461473
assert ret is None
462474

463475
@patch("PyQt5.QtWidgets.QLabel.setPixmap")
476+
@patch("dls_pmaclib.dls_pmacremote.PmacEthernetInterface.sendCommand")
464477
@patch("dls_pmaclib.dls_pmacremote.PmacEthernetInterface.isModelGeobrick")
465478
@patch("dls_pmaclib.dls_pmacremote.PmacEthernetInterface.getNumberOfAxes")
466479
@patch("dls_pmaclib.dls_pmacremote.PmacEthernetInterface.getPmacModel")
467480
@patch("dls_pmaclib.dls_pmacremote.PmacEthernetInterface.connect")
468481
@patch("dls_pmaclib.dls_pmacremote.PmacEthernetInterface.setConnectionParams")
469-
def test_remote_connect(
470-
self, mock_params, mock_connect, mock_model, mock_axes, mock_geo, mock_pixmap
482+
def test_remote_connect_ethernet_interface(
483+
self,
484+
mock_params,
485+
mock_connect,
486+
mock_model,
487+
mock_axes,
488+
mock_geo,
489+
mock_send,
490+
mock_pixmap,
471491
):
472492
mock_model.return_value = "test"
473493
mock_axes.return_value = 8
474494
mock_geo.return_value = True
495+
mock_send.return_value = ("1677721.6", True)
475496
mock_connect.return_value = None
476497
ret = self.obj.remoteConnect()
477498
mock_params.assert_called_with("test", "123")
@@ -617,17 +638,26 @@ def test_remote_connect_auth_error(self, mock_params, mock_connect, mock_box):
617638
assert ret is None
618639

619640
@patch("PyQt5.QtWidgets.QLabel.setPixmap")
641+
@patch("dls_pmaclib.dls_pmacremote.PmacSerialInterface.sendCommand")
620642
@patch("dls_pmaclib.dls_pmacremote.PmacSerialInterface.isModelGeobrick")
621643
@patch("dls_pmaclib.dls_pmacremote.PmacSerialInterface.getNumberOfAxes")
622644
@patch("dls_pmaclib.dls_pmacremote.PmacSerialInterface.getPmacModel")
623645
@patch("dls_pmaclib.dls_pmacremote.PmacSerialInterface.connect")
624646
@patch("dls_pmaclib.dls_pmacremote.PmacSerialInterface.setConnectionParams")
625-
def test_remote_connect(
626-
self, mock_params, mock_connect, mock_model, mock_axes, mock_geo, mock_pixmap
647+
def test_remote_connect_serial_interface(
648+
self,
649+
mock_params,
650+
mock_connect,
651+
mock_model,
652+
mock_axes,
653+
mock_geo,
654+
mock_send,
655+
mock_pixmap,
627656
):
628657
mock_model.return_value = "test"
629658
mock_axes.return_value = 8
630659
mock_geo.return_value = True
660+
mock_send.return_value = ("1677721.6", True)
631661
mock_connect.return_value = None
632662
ret = self.obj.remoteConnect()
633663
mock_params.assert_called_with("test", "123")
@@ -796,24 +826,27 @@ def test_remote_connect_auth_error(
796826

797827
@patch("PyQt5.QtWidgets.QLabel.setPixmap")
798828
@patch("dls_pmac_control.login.Loginform.exec")
829+
@patch("dls_pmaclib.dls_pmacremote.PPmacSshInterface.sendCommand")
799830
@patch("dls_pmaclib.dls_pmacremote.PPmacSshInterface.isModelGeobrick")
800831
@patch("dls_pmaclib.dls_pmacremote.PPmacSshInterface.getNumberOfAxes")
801832
@patch("dls_pmaclib.dls_pmacremote.PPmacSshInterface.getPmacModel")
802833
@patch("dls_pmaclib.dls_pmacremote.PPmacSshInterface.connect")
803834
@patch("dls_pmaclib.dls_pmacremote.PPmacSshInterface.setConnectionParams")
804-
def test_remote_connect(
835+
def test_remote_connect_ssh_interface(
805836
self,
806837
mock_params,
807838
mock_connect,
808839
mock_model,
809840
mock_axes,
810841
mock_geo,
842+
mock_send,
811843
mock_login,
812844
mock_pixmap,
813845
):
814846
mock_model.return_value = "test"
815847
mock_axes.return_value = 8
816848
mock_geo.return_value = True
849+
mock_send.return_value = ("1677721.6", True)
817850
mock_connect.return_value = None
818851
ret = self.obj.remoteConnect()
819852
mock_params.assert_called_with("test", "123")
@@ -866,6 +899,7 @@ def test_update_motors(self):
866899
assert float(self.obj.lblFolErr.text()) == 0.0
867900

868901
@patch("dls_pmaclib.dls_pmacremote.PPmacSshInterface.getShortModelName")
902+
@patch("dls_pmaclib.dls_pmacremote.PPmacSshInterface.sendCommand")
869903
@patch("dls_pmaclib.dls_pmacremote.PPmacSshInterface.isModelGeobrick")
870904
@patch("dls_pmaclib.dls_pmacremote.PPmacSshInterface.getNumberOfAxes")
871905
@patch("dls_pmaclib.dls_pmacremote.PPmacSshInterface.getPmacModel")
@@ -880,13 +914,15 @@ def test_update_identity(
880914
mock_model,
881915
mock_axes,
882916
mock_geo,
917+
mock_send,
883918
mock_short,
884919
):
885920
mock_short.return_value = "name"
886921
# create connection
887922
mock_model.return_value = "test"
888923
mock_axes.return_value = 8
889924
mock_geo.return_value = True
925+
mock_send.return_value = ("1677721.6", True)
890926
mock_connect.return_value = None
891927
self.obj.remoteConnect()
892928
self.obj.updateIdentity(1)

0 commit comments

Comments
 (0)