diff options
Diffstat (limited to 'tests/conftest.py')
-rw-r--r-- | tests/conftest.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..55700914 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,45 @@ +# +# Cmd2 unit/functional testing +# +# Copyright 2016 Federico Ceratto <federico.ceratto@gmail.com> +# Released under MIT license, see LICENSE file + +from pytest import fixture + +import cmd2 + + +class StdOut(object): + def __init__(self): + self.clear() + + def write(self, s): + self.buffer += s + + def read(self): + raise NotImplementedError + + def clear(self): + self.buffer = '' + + +def _normalize(block): + # normalize a block of text to perform comparison + assert isinstance(block, str) + block = block.strip('\n') + return [line.rstrip() for line in block.splitlines()] + + +def run_cmd(app, cmd): + app.stdout.clear() + app.onecmd_plus_hooks(cmd) + out = app.stdout.buffer + app.stdout.clear() + return _normalize(out) + + +@fixture +def base_app(): + c = cmd2.Cmd() + c.stdout = StdOut() + return c |