summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJonas Haag <jonas@lophus.org>2015-12-10 15:15:57 +0100
committerJonas Haag <jonas@lophus.org>2015-12-10 15:15:57 +0100
commitbcb14fd34b198fdb01af647e7e4fa64172f3aba7 (patch)
treec40470226c223df8447d65f23de61701cf9295e9 /tests
parent7533709dbacc9b46e547c23c178009af7341368d (diff)
Add unit test for manpage
Diffstat (limited to 'tests')
l---------tests/klaus_cli.py1
-rw-r--r--tests/test_manpage.py28
2 files changed, 29 insertions, 0 deletions
diff --git a/tests/klaus_cli.py b/tests/klaus_cli.py
new file mode 120000
index 0000000..35d44e9
--- /dev/null
+++ b/tests/klaus_cli.py
@@ -0,0 +1 @@
+../bin/klaus \ No newline at end of file
diff --git a/tests/test_manpage.py b/tests/test_manpage.py
new file mode 100644
index 0000000..21acfd1
--- /dev/null
+++ b/tests/test_manpage.py
@@ -0,0 +1,28 @@
+import klaus_cli
+import mock
+import subprocess
+import re
+
+
+def test_covers_all_cli_options():
+ manpage = subprocess.check_output(["man", "./klaus.1"])
+
+ def assert_in_manpage(s):
+ clean = lambda x: re.sub('(.\\x08)|\s', '', x)
+ assert clean(s) in clean(manpage), "%r not found in manpage" % s
+
+ mock_parser = mock.Mock()
+ with mock.patch('argparse.ArgumentParser') as mock_cls:
+ mock_cls.return_value = mock_parser
+ klaus_cli.make_parser()
+
+ for args, kwargs in mock_parser.add_argument.call_args_list:
+ if kwargs.get('metavar') == 'DIR':
+ continue
+ for string in args:
+ assert_in_manpage(string)
+ if 'help' in kwargs:
+ assert_in_manpage(kwargs['help'])
+ if 'choices' in kwargs:
+ for choice in kwargs['choices']:
+ assert_in_manpage(choice)