def test_modbus_send_hex_invalid_string(self):
     with captured_output() as (out, err):
         with self.assertRaises(SystemExit) as cm:
             modbus.argument_parser([self._serial_port, 'send', '0xZZ'])
         self.assertEquals(cm.exception.code, 1)
         output = str(out.getvalue().strip())
         self.assertTrue(output.startswith('Incorrect send argument'))
 def test_modbus_send_hex_spaces(self):
     with captured_output() as (out, err):
         modbus.argument_parser(
             [self._serial_port, 'send', '01 06 00 01 03 00'])
         output = out.getvalue().strip()
         self.assertEqual(
             output, 'TX  8 Bytes:  01 06 00 01 03 00 D8 FA\n'
             'RX  8 Bytes:  01 06 00 01 03 00 D8 FA')
 def test_modbus_send_hex_comma(self):
     with captured_output() as (out, err):
         modbus.argument_parser([
             self._serial_port, 'send', '0x01, 0x06, 0x00, 0x01, 0x02, 0x00'
         ])
         output = out.getvalue().strip()
         self.assertEqual(
             output, 'TX  8 Bytes:  01 06 00 01 02 00 D9 6A\n'
             'RX  8 Bytes:  01 06 00 01 02 00 D9 6A')
 def test_modbus_send_ascii_no_append_crc(self):
     with captured_output() as (out, err):
         modbus.argument_parser([
             self._serial_port, 'send', ':010600010100D99a',
             '--no-append-crc'
         ])
         output = out.getvalue().strip()
         self.assertEqual(
             output, 'TX  8 Bytes:  01 06 00 01 01 00 D9 9A\n'
             'RX  8 Bytes:  01 06 00 01 01 00 D9 9A')
 def test_modbus_send_wrong_serial_port(self):
     with captured_output() as (out, err):
         serial_port = 'WRONG'
         with self.assertRaises(SystemExit) as cm:
             modbus.argument_parser([
                 serial_port, 'send', '0x01, 0x06, 0x00, 0x01, 0x02, 0x00'
             ])
         self.assertEquals(cm.exception.code, 1)
         output = out.getvalue().strip()
         self.assertEquals(output, '')
         output = err.getvalue().strip()
         self.assertEquals(
             output,
             'Error: Cannot open serial port: {}'.format(serial_port))