summaryrefslogtreecommitdiff
path: root/tests/conftest.py
diff options
context:
space:
mode:
authorFederico Ceratto <federico.ceratto@gmail.com>2016-02-23 23:55:58 +0000
committerFederico Ceratto <federico.ceratto@gmail.com>2016-02-23 23:55:58 +0000
commit24e841d5e002442115e3d7a045742fbd8a05477f (patch)
tree45e47959e46168def43e5eda4c83dd0a9da70071 /tests/conftest.py
parentd37d349a1a0319f9735af9ffdf6bd976f6f41ee9 (diff)
downloadcmd2-git-24e841d5e002442115e3d7a045742fbd8a05477f.tar.gz
Add unit tests
Diffstat (limited to 'tests/conftest.py')
-rw-r--r--tests/conftest.py45
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