From 989dc350481f7f8aba85310caad56cfad1ddf7d9 Mon Sep 17 00:00:00 2001 From: James O'Hea Date: Fri, 29 Nov 2024 11:15:20 +0000 Subject: [PATCH] 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) --- tests/test_motor.py | 50 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/tests/test_motor.py b/tests/test_motor.py index d6264bb9..61dd0466 100644 --- a/tests/test_motor.py +++ b/tests/test_motor.py @@ -168,17 +168,26 @@ def test_remote_connect_auth_error(self, mock_params, mock_connect, mock_box): assert ret is None @patch("PyQt5.QtWidgets.QLabel.setPixmap") + @patch("dls_pmaclib.dls_pmacremote.PmacTelnetInterface.sendCommand") @patch("dls_pmaclib.dls_pmacremote.PmacTelnetInterface.isModelGeobrick") @patch("dls_pmaclib.dls_pmacremote.PmacTelnetInterface.getNumberOfAxes") @patch("dls_pmaclib.dls_pmacremote.PmacTelnetInterface.getPmacModel") @patch("dls_pmaclib.dls_pmacremote.PmacTelnetInterface.connect") @patch("dls_pmaclib.dls_pmacremote.PmacTelnetInterface.setConnectionParams") - def test_remote_connect( - self, mock_params, mock_connect, mock_model, mock_axes, mock_geo, mock_pixmap + def test_remote_connect_telnet_interface( + self, + mock_params, + mock_connect, + mock_model, + mock_axes, + mock_geo, + mock_send, + mock_pixmap, ): mock_model.return_value = "test" mock_axes.return_value = 8 mock_geo.return_value = True + mock_send.return_value = ("1677721.6", True) mock_connect.return_value = None ret = self.obj.remoteConnect() mock_params.assert_called_with("test", "123") @@ -260,6 +269,7 @@ def tearDown(self): class MotorTestTelnetConnectionRequired(unittest.TestCase): @patch("PyQt5.QtWidgets.QLabel.setPixmap") + @patch("dls_pmaclib.dls_pmacremote.PmacTelnetInterface.sendCommand") @patch("dls_pmaclib.dls_pmacremote.PmacTelnetInterface.isModelGeobrick") @patch("dls_pmaclib.dls_pmacremote.PmacTelnetInterface.getNumberOfAxes") @patch("dls_pmaclib.dls_pmacremote.PmacTelnetInterface.getPmacModel") @@ -304,6 +314,7 @@ def setUp( mock_model, mock_axes, mock_geo, + mock_send, mock_pixmap, ): self.options = DummyTestOptionsTelnet() @@ -311,6 +322,7 @@ def setUp( mock_model.return_value = "test" mock_axes.return_value = 8 mock_geo.return_value = True + mock_send.return_value = ("1677721.6", True) mock_connect.return_value = None self.obj.remoteConnect() @@ -461,17 +473,26 @@ def test_remote_connect_auth_error(self, mock_params, mock_connect, mock_box): assert ret is None @patch("PyQt5.QtWidgets.QLabel.setPixmap") + @patch("dls_pmaclib.dls_pmacremote.PmacEthernetInterface.sendCommand") @patch("dls_pmaclib.dls_pmacremote.PmacEthernetInterface.isModelGeobrick") @patch("dls_pmaclib.dls_pmacremote.PmacEthernetInterface.getNumberOfAxes") @patch("dls_pmaclib.dls_pmacremote.PmacEthernetInterface.getPmacModel") @patch("dls_pmaclib.dls_pmacremote.PmacEthernetInterface.connect") @patch("dls_pmaclib.dls_pmacremote.PmacEthernetInterface.setConnectionParams") - def test_remote_connect( - self, mock_params, mock_connect, mock_model, mock_axes, mock_geo, mock_pixmap + def test_remote_connect_ethernet_interface( + self, + mock_params, + mock_connect, + mock_model, + mock_axes, + mock_geo, + mock_send, + mock_pixmap, ): mock_model.return_value = "test" mock_axes.return_value = 8 mock_geo.return_value = True + mock_send.return_value = ("1677721.6", True) mock_connect.return_value = None ret = self.obj.remoteConnect() mock_params.assert_called_with("test", "123") @@ -617,17 +638,26 @@ def test_remote_connect_auth_error(self, mock_params, mock_connect, mock_box): assert ret is None @patch("PyQt5.QtWidgets.QLabel.setPixmap") + @patch("dls_pmaclib.dls_pmacremote.PmacSerialInterface.sendCommand") @patch("dls_pmaclib.dls_pmacremote.PmacSerialInterface.isModelGeobrick") @patch("dls_pmaclib.dls_pmacremote.PmacSerialInterface.getNumberOfAxes") @patch("dls_pmaclib.dls_pmacremote.PmacSerialInterface.getPmacModel") @patch("dls_pmaclib.dls_pmacremote.PmacSerialInterface.connect") @patch("dls_pmaclib.dls_pmacremote.PmacSerialInterface.setConnectionParams") - def test_remote_connect( - self, mock_params, mock_connect, mock_model, mock_axes, mock_geo, mock_pixmap + def test_remote_connect_serial_interface( + self, + mock_params, + mock_connect, + mock_model, + mock_axes, + mock_geo, + mock_send, + mock_pixmap, ): mock_model.return_value = "test" mock_axes.return_value = 8 mock_geo.return_value = True + mock_send.return_value = ("1677721.6", True) mock_connect.return_value = None ret = self.obj.remoteConnect() mock_params.assert_called_with("test", "123") @@ -796,24 +826,27 @@ def test_remote_connect_auth_error( @patch("PyQt5.QtWidgets.QLabel.setPixmap") @patch("dls_pmac_control.login.Loginform.exec") + @patch("dls_pmaclib.dls_pmacremote.PPmacSshInterface.sendCommand") @patch("dls_pmaclib.dls_pmacremote.PPmacSshInterface.isModelGeobrick") @patch("dls_pmaclib.dls_pmacremote.PPmacSshInterface.getNumberOfAxes") @patch("dls_pmaclib.dls_pmacremote.PPmacSshInterface.getPmacModel") @patch("dls_pmaclib.dls_pmacremote.PPmacSshInterface.connect") @patch("dls_pmaclib.dls_pmacremote.PPmacSshInterface.setConnectionParams") - def test_remote_connect( + def test_remote_connect_ssh_interface( self, mock_params, mock_connect, mock_model, mock_axes, mock_geo, + mock_send, mock_login, mock_pixmap, ): mock_model.return_value = "test" mock_axes.return_value = 8 mock_geo.return_value = True + mock_send.return_value = ("1677721.6", True) mock_connect.return_value = None ret = self.obj.remoteConnect() mock_params.assert_called_with("test", "123") @@ -866,6 +899,7 @@ def test_update_motors(self): assert float(self.obj.lblFolErr.text()) == 0.0 @patch("dls_pmaclib.dls_pmacremote.PPmacSshInterface.getShortModelName") + @patch("dls_pmaclib.dls_pmacremote.PPmacSshInterface.sendCommand") @patch("dls_pmaclib.dls_pmacremote.PPmacSshInterface.isModelGeobrick") @patch("dls_pmaclib.dls_pmacremote.PPmacSshInterface.getNumberOfAxes") @patch("dls_pmaclib.dls_pmacremote.PPmacSshInterface.getPmacModel") @@ -880,6 +914,7 @@ def test_update_identity( mock_model, mock_axes, mock_geo, + mock_send, mock_short, ): mock_short.return_value = "name" @@ -887,6 +922,7 @@ def test_update_identity( mock_model.return_value = "test" mock_axes.return_value = 8 mock_geo.return_value = True + mock_send.return_value = ("1677721.6", True) mock_connect.return_value = None self.obj.remoteConnect() self.obj.updateIdentity(1)