summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgoodger <goodger@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2003-09-01 15:07:11 +0000
committergoodger <goodger@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2003-09-01 15:07:11 +0000
commitc540a4c9d7da712385a2477e1da83515d536fe31 (patch)
tree558f32c6730852bd8d9ae42c3c41c5841b072b7d
parent0966c6eb637aeb24e960a72878311b90e4741494 (diff)
downloaddocutils-c540a4c9d7da712385a2477e1da83515d536fe31.tar.gz
new tests & support files
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@1662 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
-rw-r--r--docutils/test/data/config_1.txt20
-rw-r--r--docutils/test/data/config_2.txt10
-rw-r--r--docutils/test/data/config_error_handler.txt2
-rw-r--r--docutils/test/data/config_list.txt8
-rw-r--r--docutils/test/data/config_old.txt14
-rwxr-xr-xdocutils/test/test_settings.py123
6 files changed, 177 insertions, 0 deletions
diff --git a/docutils/test/data/config_1.txt b/docutils/test/data/config_1.txt
new file mode 100644
index 000000000..9524dfb8c
--- /dev/null
+++ b/docutils/test/data/config_1.txt
@@ -0,0 +1,20 @@
+# Test config file (new format)
+
+[general]
+
+source-link: on
+datestamp: %Y-%m-%d %H:%M UTC
+generator: true
+
+
+[html4css1 writer]
+
+stylesheet-path: stylesheets/default.css
+
+
+[pep_html writer]
+
+template: pep-html-template
+stylesheet-path: stylesheets/pep.css
+python-home: http://www.python.org
+no-random: yes
diff --git a/docutils/test/data/config_2.txt b/docutils/test/data/config_2.txt
new file mode 100644
index 000000000..6f1d17008
--- /dev/null
+++ b/docutils/test/data/config_2.txt
@@ -0,0 +1,10 @@
+# Test config file (new format)
+
+[general]
+
+generator: no
+
+
+[html4css1 writer]
+
+stylesheet-path: test.css
diff --git a/docutils/test/data/config_error_handler.txt b/docutils/test/data/config_error_handler.txt
new file mode 100644
index 000000000..82e341649
--- /dev/null
+++ b/docutils/test/data/config_error_handler.txt
@@ -0,0 +1,2 @@
+[general]
+error_encoding: ascii:strict
diff --git a/docutils/test/data/config_list.txt b/docutils/test/data/config_list.txt
new file mode 100644
index 000000000..fde6793c9
--- /dev/null
+++ b/docutils/test/data/config_list.txt
@@ -0,0 +1,8 @@
+[general]
+expose_internals: a
+
+[html4css1 writer]
+expose_internals: b:c:d
+
+[pep_html writer]
+expose_internals: e
diff --git a/docutils/test/data/config_old.txt b/docutils/test/data/config_old.txt
new file mode 100644
index 000000000..fa07d6dab
--- /dev/null
+++ b/docutils/test/data/config_old.txt
@@ -0,0 +1,14 @@
+# Test config file (old format)
+
+[options]
+
+source-link: 1
+datestamp: %Y-%m-%d %H:%M UTC
+generator: 1
+
+stylesheet-path: stylesheets/default.css
+
+pep-template: pep-html-template
+pep-stylesheet-path: stylesheets/pep.css
+python-home: http://www.python.org
+no-random: 1
diff --git a/docutils/test/test_settings.py b/docutils/test/test_settings.py
new file mode 100755
index 000000000..d8788e449
--- /dev/null
+++ b/docutils/test/test_settings.py
@@ -0,0 +1,123 @@
+#!/usr/bin/env python
+
+# Author: David Goodger
+# Contact: goodger@python.org
+# Revision: $Revision$
+# Date: $Date$
+# Copyright: This module has been placed in the public domain.
+
+"""
+Tests of runtime settings.
+"""
+
+import sys
+import os
+import difflib
+import pprint
+import warnings
+import unittest
+from docutils import frontend
+from docutils.writers import html4css1
+from docutils.writers import pep_html
+
+
+warnings.filterwarnings(action='ignore',
+ category=frontend.ConfigDeprecationWarning)
+
+def fixpath(path):
+ return os.path.abspath(os.path.join(mydir, path))
+
+mydir = os.path.dirname(fixpath.func_code.co_filename)
+
+
+class ConfigFileTests(unittest.TestCase):
+
+ config_files = {'old': fixpath('data/config_old.txt'),
+ 'one': fixpath('data/config_1.txt'),
+ 'two': fixpath('data/config_2.txt'),
+ 'list': fixpath('data/config_list.txt'),
+ 'error': fixpath('data/config_error_handler.txt')}
+
+ settings = {
+ 'old': {'datestamp': '%Y-%m-%d %H:%M UTC',
+ 'generator': 1,
+ 'no_random': 1,
+ 'python_home': 'http://www.python.org',
+ 'source_link': 1,
+ 'stylesheet_path': fixpath('data/stylesheets/pep.css'),
+ 'template': fixpath('data/pep-html-template')},
+ 'one': {'datestamp': '%Y-%m-%d %H:%M UTC',
+ 'generator': 1,
+ 'no_random': 1,
+ 'python_home': 'http://www.python.org',
+ 'source_link': 1,
+ 'stylesheet_path': fixpath('data/stylesheets/pep.css'),
+ 'template': fixpath('data/pep-html-template')},
+ 'two': {'generator': 0,
+ 'stylesheet_path': fixpath('data/test.css')},
+ 'list': {'expose_internals': ['a', 'b', 'c', 'd', 'e']},
+ 'error': {'error_encoding': 'ascii',
+ 'error_encoding_error_handler': 'strict'},
+ }
+
+ compare = difflib.Differ().compare
+ """Comparison method shared by all tests."""
+
+ def setUp(self):
+ self.option_parser = frontend.OptionParser(
+ components=(pep_html.Writer,), read_config_files=None)
+
+ def compare_output(self, result, expected):
+ """`result` and `expected` should both be dicts."""
+ result = pprint.pformat(result)
+ expected = pprint.pformat(expected)
+ try:
+ self.assertEquals('\n' + result, '\n' + expected)
+ except AssertionError:
+ print >>sys.stderr, '\n%s\n' % (self,)
+ print >>sys.stderr, '-: expected\n+: result'
+ print >>sys.stderr, ''.join(self.compare(expected.splitlines(1),
+ result.splitlines(1)))
+ raise
+
+ def test_old(self):
+ settings = self.option_parser.get_config_file_settings(
+ self.config_files['old'])
+ self.compare_output(settings, self.settings['old'])
+
+ def test_one(self):
+ settings = self.option_parser.get_config_file_settings(
+ self.config_files['one'])
+ self.compare_output(settings, self.settings['one'])
+
+ def test_multiple(self):
+ settings = self.option_parser.get_config_file_settings(
+ self.config_files['one'])
+ settings.update(self.option_parser.get_config_file_settings(
+ self.config_files['two']))
+ expected = self.settings['one'].copy()
+ expected.update(self.settings['two'])
+ self.compare_output(settings, expected)
+
+ def test_old_and_new(self):
+ settings = self.option_parser.get_config_file_settings(
+ self.config_files['one'])
+ settings.update(self.option_parser.get_config_file_settings(
+ self.config_files['two']))
+ expected = self.settings['old'].copy()
+ expected.update(self.settings['two'])
+ self.compare_output(settings, expected)
+
+ def test_list(self):
+ settings = self.option_parser.get_config_file_settings(
+ self.config_files['list'])
+ self.compare_output(settings, self.settings['list'])
+
+ def test_error_handler(self):
+ settings = self.option_parser.get_config_file_settings(
+ self.config_files['error'])
+ self.compare_output(settings, self.settings['error'])
+
+
+if __name__ == '__main__':
+ unittest.main()