improve command repr

This commit is contained in:
Maximilian Hils 2017-06-28 17:26:20 +02:00
parent c4824f941d
commit 2a68029b21
3 changed files with 8 additions and 8 deletions

View File

@ -26,7 +26,9 @@ class Command:
"""
def __repr__(self):
return f"{type(self).__name__}({repr(self.__dict__)})"
x = self.__dict__.copy()
x.pop("blocking", None)
return f"{type(self).__name__}({repr(x)})"
class ConnectionCommand(Command):

View File

@ -27,8 +27,8 @@ class Layer(metaclass=ABCMeta):
self._paused = None
self._paused_event_queue: typing.Deque[events.Event] = collections.deque()
def _debug(self, x):
pass # print(x)
def _debug(self, *args):
pass # print(*args)
@abstractmethod
def _handle_event(self, event: Event) -> commands.TCommandGenerator:

View File

@ -100,8 +100,8 @@ class playbook:
pass
else:
if isinstance(x, events.CommandReply):
if isinstance(x.command, int) and 0 <= i + x.command < len(self.actual):
x.command = self.actual[i + x.command]
if isinstance(x.command, int) and abs(x.command) < len(self.actual):
x.command = self.actual[x.command]
self.actual.append(x)
self.actual.extend(
@ -116,9 +116,7 @@ class playbook:
if not success:
def _str(x):
# add arrows to diff
ret = f"{'>' if isinstance(x, events.Event) else '<'} {x}"
# remove "blocking" attr which is also ignored during equality checks.
return re.sub(r", 'blocking': <.+?>", "", ret)
return f"{'>' if isinstance(x, events.Event) else '<'} {x}"
diff = difflib.ndiff(
[_str(x) for x in self.playbook],