コード例 #1
0
 def test_init_tcp(self):
     remote_arm = RemoteArm(host="http://localhost.lan")
     self.assertIsInstance(remote_arm.pymc, ModbusTcpClient)
     self.assertEqual(remote_arm.unit, 1)
コード例 #2
0
 def setUp(self, mock_tcp, mock_rtu):
     mock_tcp.return_value = mock.MagicMock(spec=ModbusTcpClient)
     mock_rtu.return_value = mock.MagicMock(spec=ModbusSerialClient)
     self.remote_arm_tcp = RemoteArm(host="http://localhost.lan")
     self.remote_arm_rtu = RemoteArm(host="/home")
コード例 #3
0
 def test_init_serial(self):
     remote_arm = RemoteArm(host="/serial")
     self.assertIsInstance(remote_arm.pymc, ModbusSerialClient)
     self.assertEqual(remote_arm.unit, 1)
コード例 #4
0
class TestRemoteArm(unittest.TestCase):
    @mock.patch("dali.driver.unipi.pyRtu")
    @mock.patch("dali.driver.unipi.pySerial")
    def setUp(self, mock_tcp, mock_rtu):
        mock_tcp.return_value = mock.MagicMock(spec=ModbusTcpClient)
        mock_rtu.return_value = mock.MagicMock(spec=ModbusSerialClient)
        self.remote_arm_tcp = RemoteArm(host="http://localhost.lan")
        self.remote_arm_rtu = RemoteArm(host="/home")

    def test_init_serial(self):
        remote_arm = RemoteArm(host="/serial")
        self.assertIsInstance(remote_arm.pymc, ModbusSerialClient)
        self.assertEqual(remote_arm.unit, 1)

    def test_init_tcp(self):
        remote_arm = RemoteArm(host="http://localhost.lan")
        self.assertIsInstance(remote_arm.pymc, ModbusTcpClient)
        self.assertEqual(remote_arm.unit, 1)

    def test_close(self):
        self.remote_arm_tcp.close()
        self.assertEqual(self.remote_arm_tcp.pymc.close.called, True)

    def test_read_regs(self):
        self.remote_arm_tcp.read_regs(10, 5)
        self.remote_arm_tcp.pymc.read_holding_registers.assert_called_with(
            10, 5, unit=1)

    def test_read_regs_unit(self):
        self.remote_arm_tcp.read_regs(10, 5, unit=5)
        self.remote_arm_tcp.pymc.read_holding_registers.assert_called_with(
            10, 5, unit=5)

    def test_write_regs_list(self):
        self.remote_arm_tcp.write_regs(10, [1, 2], unit=10)
        self.remote_arm_tcp.pymc.write_registers.assert_called_with(10, [1, 2],
                                                                    unit=10)

    def test_write_regs_single(self):
        self.remote_arm_tcp.write_regs(10, 1)
        self.remote_arm_tcp.pymc.write_register.assert_called_with(10,
                                                                   1,
                                                                   unit=1)

    def test_write_coil(self):
        self.remote_arm_tcp.write_coil(10, 1, unit=42)
        self.remote_arm_tcp.pymc.write_coil.assert_called_with(10, 1, unit=42)

    def test_reboot(self):
        self.remote_arm_tcp.reboot()
        self.remote_arm_tcp.pymc.write_coil.assert_called_with(1002, 1, unit=1)

    @mock.patch("dali.driver.unipi.RemoteArm.read_regs", return_value=[4])
    def test_vref(self, mock_read_regs):
        self.assertEqual(self.remote_arm_tcp.Vref(), 3.3)