From 83fc1743fcdeb23eba5a7e571533a9b7da0dd114 Mon Sep 17 00:00:00 2001 From: Romain Dorgueil Date: Sat, 4 Nov 2017 13:20:53 +0100 Subject: [PATCH] Small changes in events, and associated tests. --- bonobo/execution/events.py | 4 ++-- bonobo/plugins/console.py | 8 ++++---- tests/execution/{ => contexts}/test_node.py | 0 tests/execution/test_events.py | 17 +++++++++++++++++ 4 files changed, 23 insertions(+), 6 deletions(-) rename tests/execution/{ => contexts}/test_node.py (100%) create mode 100644 tests/execution/test_events.py diff --git a/bonobo/execution/events.py b/bonobo/execution/events.py index 036e879..3bf3986 100644 --- a/bonobo/execution/events.py +++ b/bonobo/execution/events.py @@ -9,5 +9,5 @@ KILL = 'execution.kill' class ExecutionEvent(Event): - def __init__(self, graph_context): - self.graph_context = graph_context + def __init__(self, context): + self.context = context diff --git a/bonobo/plugins/console.py b/bonobo/plugins/console.py index d5f9914..584244c 100644 --- a/bonobo/plugins/console.py +++ b/bonobo/plugins/console.py @@ -68,12 +68,12 @@ class ConsoleOutputPlugin(Plugin): def tick(self, event): if self.isatty and not self.iswindows: - self._write(event.graph_context, rewind=True) + self._write(event.context, rewind=True) else: pass # not a tty, or windows, so we'll ignore stats output def teardown(self, event): - self._write(event.graph_context, rewind=False) + self._write(event.context, rewind=False) self.redirect_stderr.__exit__(None, None, None) self.redirect_stdout.__exit__(None, None, None) @@ -127,7 +127,7 @@ class ConsoleOutputPlugin(Plugin): print(CLEAR_EOL, file=self._stderr) print(MOVE_CURSOR_UP(t_cnt + 2), file=self._stderr) - def _write(self, graph_context, rewind): + def _write(self, context, rewind): if settings.PROFILE.get(): if self.counter % 10 and self._append_cache: append = self._append_cache @@ -138,7 +138,7 @@ class ConsoleOutputPlugin(Plugin): ) else: append = () - self.write(graph_context, prefix=self.prefix, append=append, rewind=rewind) + self.write(context, prefix=self.prefix, append=append, rewind=rewind) self.counter += 1 diff --git a/tests/execution/test_node.py b/tests/execution/contexts/test_node.py similarity index 100% rename from tests/execution/test_node.py rename to tests/execution/contexts/test_node.py diff --git a/tests/execution/test_events.py b/tests/execution/test_events.py new file mode 100644 index 0000000..8abeb57 --- /dev/null +++ b/tests/execution/test_events.py @@ -0,0 +1,17 @@ +from unittest.mock import Mock + +from bonobo.execution import events + + +def test_names(): + # This test looks useless, but as it's becoming the pliugin API, I want to make sure that nothing changes here, or + # notice it otherwise. + for name in 'start', 'started', 'tick', 'stop', 'stopped', 'kill': + event_name = getattr(events, name.upper()) + assert event_name == '.'.join(('execution', name)) + +def test_event_object(): + # Same logic as above. + c = Mock() + e = events.ExecutionEvent(c) + assert e.context is c