From 2e9b7726d4e1769bd973fe669273dae5048b0a45 Mon Sep 17 00:00:00 2001 From: Andrew Kay Date: Sat, 6 Jul 2019 09:04:57 -0500 Subject: [PATCH] Fix issue where keyword arguments were not passed to interface --- pycoax/coax/protocol.py | 6 +++--- pycoax/tests/test_protocol.py | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/pycoax/coax/protocol.py b/pycoax/coax/protocol.py index 66f4d9f..c488027 100644 --- a/pycoax/coax/protocol.py +++ b/pycoax/coax/protocol.py @@ -196,7 +196,7 @@ def _execute_read_command(interface, command, response_length=1, """Execute a standard read command.""" command_word = _pack_command_word(command) - response = interface.execute(command_word, response_length=response_length) + response = interface.execute(command_word, response_length=response_length, **kwargs) if allow_trta_response and len(response) == 1 and response[0] == 0: return trta_value @@ -206,11 +206,11 @@ def _execute_read_command(interface, command, response_length=1, return _unpack_data_words(response) if unpack_data_words else response -def _execute_write_command(interface, command, data=None): +def _execute_write_command(interface, command, data=None, **kwargs): """Execute a standard write command.""" command_word = _pack_command_word(command) - response = interface.execute(command_word, data) + response = interface.execute(command_word, data, **kwargs) if len(response) != 1: raise ProtocolError(f'Expected 1 word {command.name} response') diff --git a/pycoax/tests/test_protocol.py b/pycoax/tests/test_protocol.py index 7e6557f..b15d72a 100644 --- a/pycoax/tests/test_protocol.py +++ b/pycoax/tests/test_protocol.py @@ -58,6 +58,16 @@ class ExecuteReadCommandTestCase(unittest.TestCase): with self.assertRaisesRegex(ProtocolError, 'Expected 1 word READ_TERMINAL_ID response'): _execute_read_command(self.interface, Command.READ_TERMINAL_ID) + def test_timeout_is_passed_to_interface(self): + # Arrange + self.interface.execute = Mock(return_value=[0b0000000010]) + + # Act + _execute_read_command(self.interface, Command.READ_TERMINAL_ID, timeout=10) + + # Assert + self.assertEqual(self.interface.execute.call_args[1].get('timeout'), 10) + class ExecuteWriteCommandTestCase(unittest.TestCase): def setUp(self): self.interface = Mock() @@ -85,6 +95,16 @@ class ExecuteWriteCommandTestCase(unittest.TestCase): with self.assertRaisesRegex(ProtocolError, 'Expected TR/TA response'): _execute_write_command(self.interface, Command.WRITE_DATA, bytes.fromhex('de ad be ef')) + def test_timeout_is_passed_to_interface(self): + # Arrange + self.interface.execute = Mock(return_value=[0b0000000000]) + + # Assert + _execute_write_command(self.interface, Command.WRITE_DATA, bytes.fromhex('de ad be ef'), timeout=10) + + # Assert + self.assertEqual(self.interface.execute.call_args[1].get('timeout'), 10) + class PackCommandWordTestCase(unittest.TestCase): def test_without_address(self): self.assertEqual(_pack_command_word(Command.POLL_ACK), 0b001000101)