summaryrefslogtreecommitdiff
path: root/docutils
diff options
context:
space:
mode:
authormilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2022-05-30 21:09:18 +0000
committermilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2022-05-30 21:09:18 +0000
commite644ef8975c8aaebc7a852362cd1ee7cbf2bf997 (patch)
tree1bc95e13420a257a4e748a67b15803f1a04df071 /docutils
parent7ec76269f1450e79b2823e642dba4f68c9f0c434 (diff)
downloaddocutils-e644ef8975c8aaebc7a852362cd1ee7cbf2bf997.tar.gz
Test the generic command line interface.
git-svn-id: https://svn.code.sf.net/p/docutils/code/trunk@9063 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'docutils')
-rw-r--r--docutils/test/test_CLI.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/docutils/test/test_CLI.py b/docutils/test/test_CLI.py
new file mode 100644
index 000000000..2dd6a8370
--- /dev/null
+++ b/docutils/test/test_CLI.py
@@ -0,0 +1,73 @@
+#!/usr/bin/env python3
+# :Copyright: © 2022 Günter Milde.
+
+# :License: Released under the terms of the `2-Clause BSD license`_, in short:
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.
+# This file is offered as-is, without any warranty.
+#
+# .. _2-Clause BSD license: https://opensource.org/licenses/BSD-2-Clause
+
+# :Id: $Id: $
+
+"""
+Test module for the command line interface.
+"""
+
+import difflib
+from io import StringIO
+import locale
+import os
+import re
+import sys
+import unittest
+
+# import docutils
+from docutils import __main__
+
+
+def print_mismatch(expected, output):
+ diff = ''.join(difflib.unified_diff(
+ expected.splitlines(keepends=True),
+ output.splitlines(keepends=True),
+ 'expected', 'output'))
+ raise AssertionError('Unexpected output:\n'+diff)
+
+
+class CliTests(unittest.TestCase):
+
+ def setUp(self):
+ # save state
+ self.orig_argv = sys.argv
+ self.orig_stdout = sys.stdout
+ os.environ['DOCUTILSCONFIG'] = '' # don't read config files
+ sys.stdout = StringIO() # re-direct sys.stdout
+
+ def tearDown(self):
+ del(os.environ['DOCUTILSCONFIG'])
+ sys.stdout = self.orig_stdout
+ sys.argv = self.orig_argv
+ locale.setlocale(locale.LC_ALL, 'C') # restore default (C) locale
+
+ def test_main_help(self):
+ # collect help text
+ sys.argv = ['docutils', '--help']
+ try:
+ __main__.main()
+ except SystemExit:
+ pass
+ output = sys.stdout.getvalue()
+ # replace unpredictable paths (eventually wrapped)
+ output = re.sub(r'default:[^)]*/[^)]*\)', 'default: [...])',
+ output, flags=re.DOTALL)
+ # compare to stored version
+ with open('data/help/docutils.txt') as samplefile:
+ expected = samplefile.read()
+ if expected != output:
+ print_mismatch(expected, output)
+
+
+if __name__ == '__main__':
+ unittest.main()