def test_relay_all(self): for cmd in self._commands: with captured_output() as (out, err): relay.argument_parser( [self._serial_port, self._address, cmd, '*']) output = out.getvalue().strip() self.assertEqual(output, 'All relays {}...'.format(cmd))
def test_invalid_address(self): for cmd in self._commands: with captured_output() as (out, err): with self.assertRaises(SystemExit): relay.argument_parser([self._serial_port, '65', cmd, '1']) output_stdout = out.getvalue().strip() output_stderr = err.getvalue().strip() self.assertEqual(output_stdout, '') self.assertGreaterEqual(len(output_stderr), 1)
def test_valid_address(self): for address in ['0', '63']: if address != str(self._address): for cmd in self._commands: with captured_output() as (out, err): relay.argument_parser( [self._serial_port, address, cmd, '1']) output_stdout = out.getvalue().strip() output_stderr = err.getvalue().strip() self.assertEqual(output_stdout, 'Relay 1 {}...'.format(cmd)) self.assertEqual(output_stderr, 'RX error: Receive timeout')
def test_relay_status(self): relay.argument_parser([self._serial_port, self._address, 'off', '*']) with captured_output() as (out, err): relay.argument_parser( [self._serial_port, self._address, 'status', '*']) output = out.getvalue().strip() expected = \ 'Status relays:\n' \ ' Relay 1: OFF\n' \ ' Relay 2: OFF\n' \ ' Relay 3: OFF\n' \ ' Relay 4: OFF\n' \ ' Relay 5: OFF\n' \ ' Relay 6: OFF\n' \ ' Relay 7: OFF\n' \ ' Relay 8: OFF' self.assertEqual(output, expected)
def tearDownClass(cls): with captured_output() as (out, err): relay.argument_parser([cls._serial_port, cls._address, 'off', '*'])