From 017bb4a9a6e0fda84da5980db1b548479b6aa2cf Mon Sep 17 00:00:00 2001 From: Romain Dorgueil Date: Sat, 4 Nov 2017 12:24:30 +0100 Subject: [PATCH] Adds a test for default file init command. --- bonobo/examples/clock.py | 5 +++-- bonobo/execution/node.py | 6 +++--- bonobo/plugins/console.py | 2 +- bonobo/strategies/executor.py | 9 ++++++--- tests/test_commands.py | 11 +++++++++++ 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/bonobo/examples/clock.py b/bonobo/examples/clock.py index 765f077..1977cba 100644 --- a/bonobo/examples/clock.py +++ b/bonobo/examples/clock.py @@ -14,12 +14,13 @@ def extract(): def get_graph(): graph = bonobo.Graph() graph.add_chain( - extract, - print, + extract, + print, ) return graph + if __name__ == '__main__': parser = bonobo.get_argument_parser() with bonobo.parse_args(parser): diff --git a/bonobo/execution/node.py b/bonobo/execution/node.py index fdb0c9f..7771812 100644 --- a/bonobo/execution/node.py +++ b/bonobo/execution/node.py @@ -156,7 +156,7 @@ class NodeExecutionContext(WithStatistics, LoopingExecutionContext): def isflag(param): - return isinstance(param, Token) and param in (NOT_MODIFIED,) + return isinstance(param, Token) and param in (NOT_MODIFIED, ) def split_tokens(output): @@ -168,11 +168,11 @@ def split_tokens(output): """ if isinstance(output, Token): # just a flag - return (output,), () + return (output, ), () if not istuple(output): # no flag - return (), (output,) + return (), (output, ) i = 0 while isflag(output[i]): diff --git a/bonobo/plugins/console.py b/bonobo/plugins/console.py index 814894b..0548d68 100644 --- a/bonobo/plugins/console.py +++ b/bonobo/plugins/console.py @@ -185,4 +185,4 @@ class IOBuffer(): def memory_usage(): import os, psutil process = psutil.Process(os.getpid()) - return process.memory_info()[0] / float(2 ** 20) + return process.memory_info()[0] / float(2**20) diff --git a/bonobo/strategies/executor.py b/bonobo/strategies/executor.py index e5ffdc0..49c5d4a 100644 --- a/bonobo/strategies/executor.py +++ b/bonobo/strategies/executor.py @@ -34,7 +34,9 @@ class ExecutorStrategy(Strategy): try: context.tick() except KeyboardInterrupt: - logging.getLogger(__name__).warning('KeyboardInterrupt received. Trying to terminate the nodes gracefully.') + logging.getLogger(__name__).warning( + 'KeyboardInterrupt received. Trying to terminate the nodes gracefully.' + ) context.kill() break @@ -50,8 +52,9 @@ class ExecutorStrategy(Strategy): with node: node.loop() except BaseException as exc: - logging.getLogger(__name__).info('Got {} in {} runner.'.format(get_name(exc), node), - exc_info=sys.exc_info()) + logging.getLogger(__name__).info( + 'Got {} in {} runner.'.format(get_name(exc), node), exc_info=sys.exc_info() + ) futures.append(executor.submit(_runner)) diff --git a/tests/test_commands.py b/tests/test_commands.py index e7e3523..2877648 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -112,6 +112,17 @@ def test_install_requirements_for_file(runner): install_mock.assert_called_once_with(os.path.join(dirname, 'requirements.txt')) +@all_runners +def test_init_file(runner, tmpdir): + target = tmpdir.join('foo.py') + runner('init', str(target)) + assert os.path.exists(target) + + out, err = runner('run', str(target)) + assert out.replace('\n', ' ').strip() == 'Hello World' + assert not err + + @all_runners def test_version(runner): out, err = runner('version')