Refactor base interface for easier testing

This commit is contained in:
Andrew Kay
2021-10-20 11:04:27 -05:00
parent bda08de83b
commit b4d3ec9d51

View File

@@ -16,11 +16,7 @@ class Interface:
"""Execute one or more commands."""
(normalized_commands, has_multiple_commands) = _normalize_commands(commands)
(outbound_frames, response_lengths) = _pack_outbound_frames(normalized_commands)
inbound_frames = self._transmit_receive(outbound_frames, response_lengths, timeout)
responses = _unpack_inbound_frames(inbound_frames, normalized_commands)
responses = self._execute(normalized_commands, timeout)
if has_multiple_commands:
return responses
@@ -32,6 +28,15 @@ class Interface:
return response
def _execute(self, commands, timeout):
(outbound_frames, response_lengths) = _pack_outbound_frames(commands)
inbound_frames = self._transmit_receive(outbound_frames, response_lengths, timeout)
responses = _unpack_inbound_frames(inbound_frames, commands)
return responses
def _transmit_receive(self, outbound_frames, response_lengths, timeout):
raise NotImplementedError