Skip to content

Commit

Permalink
Update tests to accommodate the new calculateServoCycleTime function
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
JamesOHeaDLS committed Nov 29, 2024
1 parent bf01e1d commit 989dc35
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions tests/test_motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -304,13 +314,15 @@ def setUp(
mock_model,
mock_axes,
mock_geo,
mock_send,
mock_pixmap,
):
self.options = DummyTestOptionsTelnet()
self.obj = Controlform(self.options)
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()

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -880,13 +914,15 @@ def test_update_identity(
mock_model,
mock_axes,
mock_geo,
mock_send,
mock_short,
):
mock_short.return_value = "name"
# create connection
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)
Expand Down

0 comments on commit 989dc35

Please sign in to comment.