From abf52cb4f7e5c519cc6c695fcc0908bdbe973b13 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sun, 16 Jan 2022 17:57:56 +0000 Subject: [PATCH 1/3] Add GHA scripts --- .github/workflows/linting.yml | 28 ++++++++++++++ .github/workflows/pages.yml | 71 +++++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 45 ++++++++++++++++++++++ 3 files changed, 144 insertions(+) create mode 100644 .github/workflows/linting.yml create mode 100644 .github/workflows/pages.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml new file mode 100644 index 000000000..7d11379ab --- /dev/null +++ b/.github/workflows/linting.yml @@ -0,0 +1,28 @@ +name: Lint + +on: [push, pull_request, workflow_dispatch] + +permissions: + contents: read + +jobs: + flake8: + name: Lint using flake8 + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: 3 + cache: pip + cache-dependency-path: .github/workflows/linting.yml + + - name: Install dependencies + run: pip install flake8 + + - name: Run flake8 + run: | + cd docutils + flake8 docutils diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml new file mode 100644 index 000000000..b3729d078 --- /dev/null +++ b/.github/workflows/pages.yml @@ -0,0 +1,71 @@ +name: Documentation + +on: [push, pull_request, workflow_dispatch] + +permissions: + contents: write + +jobs: + render: + name: Publish + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3 + uses: actions/setup-python@v3 + with: + python-version: 3 + cache: pip + cache-dependency-path: .github/workflows/pages.yml + + - name: Install dependencies + run: | + cd docutils + python -m pip install --upgrade pip + python -m pip install -e . + python -m pip install pygments + # for recommonmark + python -m pip install commonmark + python -m pip install recommonmark --no-deps + # for visual inspection + python -m pip list + + - name: Run tools/buildhtml + run: | + cd docutils + + # copy files from web/ + cp ../web/index.txt ./index.txt + cp ../web/rst.txt ./rst.txt + cp ../web/python.png ./python.png + cp ../web/rst.png ./rst.png + + # convert reStructuredText source to HTML + python tools/buildhtml.py --writer html5 --local . + python tools/buildhtml.py --writer html5 ./docs + + # Remove files under docutils/ except the CSS files + mkdir tmp_css + mv docutils/writers/html5_polyglot/* tmp_css/ + find tmp_css/ -type f ! -name '*.css' -delete + rm -r docutils/ + mkdir -p docutils/writers/html5_polyglot + mv tmp_css/* docutils/writers/html5_polyglot/ + + # Remove other files + rm -r docutils.egg-info/ licenses/ test/ tools/ + rm docutils.conf install.py MANIFEST.in setup.cfg setup.py tox.ini + + # Add files for GitHub Pages + touch .nojekyll + echo "www.docutils.org" > ./docs/CNAME + + - name: Deploy to GitHub pages + # This allows CI to build branches for testing + if: github.ref == 'refs/heads/master' + uses: JamesIves/github-pages-deploy-action@v4.3.0 + with: + branch: gh-pages + folder: docutils + single-commit: true # Delete existing files diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..3c2f59de0 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,45 @@ +name: Test + +on: [push, pull_request, workflow_dispatch] + +permissions: + contents: read + +jobs: + tests: + name: Python ${{ matrix.python-version }} + runs-on: ubuntu-latest + strategy: + matrix: + python-version: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11-dev" + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + cache: pip + cache-dependency-path: .github/workflows/test.yml + + - name: Install dependencies + run: | + cd docutils + python -m pip install --upgrade pip + python -m pip install -e . + python -m pip install pygments + # for recommonmark + python -m pip install commonmark + python -m pip install recommonmark --no-deps + # for visual inspection + python -m pip list + + - name: Run test suite + run: | + cd docutils + python test/alltests.py From 713f7307c939f35f2ffaa1dc15cb34296eca63f6 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Mon, 31 Jan 2022 16:34:54 +0000 Subject: [PATCH 2/3] Remove quicktest.py --- docutils/HISTORY.txt | 5 + docutils/README.txt | 6 +- docutils/docs/dev/hacking.txt | 19 ++- docutils/docs/dev/todo.txt | 4 +- docutils/docs/user/tools.txt | 27 ---- docutils/tools/quicktest.py | 224 ---------------------------------- 6 files changed, 23 insertions(+), 262 deletions(-) delete mode 100755 docutils/tools/quicktest.py diff --git a/docutils/HISTORY.txt b/docutils/HISTORY.txt index 168e6518a..07b371fcf 100644 --- a/docutils/HISTORY.txt +++ b/docutils/HISTORY.txt @@ -146,6 +146,11 @@ Release 0.19 (2022-07-05) - Options ``-h`` and ``--help`` print short usage message. +* tools/quicktest.py + + - Removed in favour of ``docutils-cli``. ``quicktest.py`` had not been + substantively changed since 2006. + Release 0.18.1 (2021-11-23) =========================== diff --git a/docutils/README.txt b/docutils/README.txt index fa912b6d6..1531f5156 100644 --- a/docutils/README.txt +++ b/docutils/README.txt @@ -154,9 +154,9 @@ Installation See also OS-specific installation instructions below. Optional steps: - + * `Running the test suite`_ - + * `Converting the documentation`_ * For installing "by hand" or in "development mode", see the @@ -357,7 +357,7 @@ If any of the tests fail, please `open a bug report`_ or `send an email`_ (see `Bugs `_). Please include all relevant output, information about your operating system, Python version, and Docutils version. To see the Docutils -version, look at the test output or use one of the `front-end scripts`_ +version, look at the test output or use one of the `front-end scripts`_ with the ``--version`` option, e.g.:: docutils --version diff --git a/docutils/docs/dev/hacking.txt b/docutils/docs/dev/hacking.txt index 45b0e8692..7be08509b 100644 --- a/docutils/docs/dev/hacking.txt +++ b/docutils/docs/dev/hacking.txt @@ -71,12 +71,19 @@ Parsing the Document The **Parser** analyzes the the input document and creates a **node tree** representation. In this case we are using the **reStructuredText parser** (``docutils/parsers/rst/__init__.py``). -To see what that node tree looks like, we call quicktest.py_ (which -can be found in the ``tools/`` directory of the Docutils distribution) -with our example file (``test.txt``) as first parameter (Windows users -might need to type ``python quicktest.py test.txt``):: - - $ quicktest.py test.txt +To see what that node tree looks like, the below code creates a Docutils +document and parser to parse our example file without applying any +tranforms or post-processing.:: + + $ python3 + >>> from docutils import frontend, utils + >>> from docutils.parsers.rst import Parser + >>> with open("test.txt", encoding="utf-8") as input_file: + ... settings = frontend.OptionParser((Parser,)).get_default_values() + ... document = utils.new_document(input_file.name, settings) + ... Parser().parse(input_file.read(), document) + ... + >>> print(document.pformat()) My diff --git a/docutils/docs/dev/todo.txt b/docutils/docs/dev/todo.txt index 5db8a331a..68294ba57 100644 --- a/docutils/docs/dev/todo.txt +++ b/docutils/docs/dev/todo.txt @@ -2284,8 +2284,8 @@ Unimplemented Transforms The advantage of the current way of doing things is that parse-time system messages don't require a transform; they're already in the - document. This is valuable for testing (unit tests, - tools/quicktest.py). So if we do decide to make a change, I think + document. This is valuable for testing (unit tests). + So if we do decide to make a change, I think the insertion of parse-time system messages ought to remain as-is and the Messages transform ought to move all parse-time system messages (remove from their originally inserted positions, insert in diff --git a/docutils/docs/user/tools.txt b/docutils/docs/user/tools.txt index b0831e3d9..f08e36280 100644 --- a/docutils/docs/user/tools.txt +++ b/docutils/docs/user/tools.txt @@ -524,33 +524,6 @@ External attributes for all elements are output, and internal attributes for any leftover "pending" elements are also given. -quicktest.py ------------- - -:Reader: N/A -:Parser: reStructuredText -:Writer: N/A - -The ``quicktest.py`` tool is used for testing the reStructuredText -parser. It does not use a Docutils Reader or Writer or the standard -Docutils command-line options. Rather, it does its own I/O and calls -the parser directly. No transforms are applied to the parsed -document. Possible output forms output include: - ---pretty Pretty-printed pseudo-XML (default) - ---test Test data (Python list of input and pseudo-XML output strings; - useful for creating new test cases) ---xml Pretty-printed native XML ---rawxml Raw native XML (with or without a stylesheet reference) ---help Usage hint and complete list of supported options. - -.. Caution:: ``quicktest.py`` uses Python's default encoding. - Input and output encoding depend on UTF-8 mode, - Python version, locale setting, and operating system - (cf. :PEP:`540`, :PEP:`538`, :PEP:`597`, and :PEP:`686`). - - --------------- Customization --------------- diff --git a/docutils/tools/quicktest.py b/docutils/tools/quicktest.py deleted file mode 100755 index ccc8139eb..000000000 --- a/docutils/tools/quicktest.py +++ /dev/null @@ -1,224 +0,0 @@ -#!/usr/bin/env python3 - -# $Id$ -# Authors: Garth Kidd ; -# David Goodger -# Copyright: This module has been placed in the public domain. - -try: - import locale - locale.setlocale(locale.LC_ALL, '') -except Exception: - pass - -import sys -import os -import getopt -import docutils -from docutils import frontend -from docutils.utils import new_document -from docutils.parsers.rst import Parser - - -usage_header = """\ -quicktest.py: Quickly test the reStructuredText parser. This is not an -interface to the full functionality of Docutils. Use one of the ``rst2*.py`` -front-end tools instead. - -Usage:: - - quicktest.py [options] [ []] - -``source`` is the name of the file to use as input (default is stdin). -``destination`` is the name of the file to create as output (default is -stdout). - -Options: -""" - -options = [('pretty', 'p', - 'output pretty pseudo-xml: no "&abc;" entities (default)'), - ('test', 't', 'output test-ready data (input & expected output, ' - 'ready to be copied to a parser test module)'), - ('rawxml', 'r', 'output raw XML'), - ('styledxml=', 's', 'output raw XML with XSL style sheet ' - 'reference (filename supplied in the option argument)'), - ('xml', 'x', 'output pretty XML (indented)'), - ('attributes', 'A', 'dump document attributes after processing'), - ('debug', 'd', 'debug mode (lots of output)'), - ('version', 'V', 'show Docutils version then exit'), - ('help', 'h', 'show help text then exit')] -"""See ``distutils.fancy_getopt.FancyGetopt.__init__`` for a description of -the data structure: (long option, short option, description).""" - - -def usage(): - print(usage_header) - for longopt, shortopt, description in options: - if longopt[-1:] == '=': - opts = '-%s arg, --%sarg' % (shortopt, longopt) - else: - opts = '-%s, --%s' % (shortopt, longopt) - sys.stdout.write('%-15s' % opts) - if len(opts) > 14: - sys.stdout.write('%-16s' % '\n') - while len(description) > 60: - limit = description.rindex(' ', 0, 60) - print(description[:limit].strip()) - description = description[limit + 1:] - sys.stdout.write('%-15s' % ' ') - print(description) - - -def _pretty(input, document, optargs): - return document.pformat() - - -def _rawxml(input, document, optargs): - return document.asdom().toxml() - - -def _styledxml(input, document, optargs): - docnode = document.asdom().childNodes[0] - return '\n'.join(('', - '' - % optargs['styledxml'], - docnode.toxml())) - - -def _prettyxml(input, document, optargs): - return document.asdom().toprettyxml(' ', '\n') - - -def _test(input, document, optargs): - tq = '"""' - output = document.pformat() # same as _pretty() - return """\ - totest['change_this_test_name'] = [ -[%s\\ -%s -%s, -%s\\ -%s -%s], -] -""" % (tq, escape(input.rstrip()), tq, tq, escape(output.rstrip()), tq) - - -def escape(text): - """ - Return `text` in triple-double-quoted Python string form. - """ - text = text.replace('\\', '\\\\') # escape backslashes - text = text.replace('"""', '""\\"') # break up triple-double-quotes - text = text.replace(' \n', ' \\n\\\n') # protect trailing whitespace - return text - - -_outputFormatters = { - 'rawxml': _rawxml, - 'styledxml': _styledxml, - 'xml': _prettyxml, - 'pretty': _pretty, - 'test': _test} - - -def format(outputFormat, input, document, optargs): - formatter = _outputFormatters[outputFormat] - return formatter(input, document, optargs) - - -def getArgs(): - if os.name == 'mac' and len(sys.argv) <= 1: - return macGetArgs() - else: - return posixGetArgs(sys.argv[1:]) - - -def posixGetArgs(argv): - outputFormat = 'pretty' - # convert fancy_getopt style option list to getopt.getopt() arguments - shortopts = ''.join(option[1] + ':' * (option[0][-1:] == '=') - for option in options if option[1]) - longopts = [option[0] for option in options if option[0]] - try: - opts, args = getopt.getopt(argv, shortopts, longopts) - except getopt.GetoptError: - usage() - sys.exit(2) - optargs = {'debug': 0, 'attributes': 0} - for o, a in opts: - if o in ['-h', '--help']: - usage() - sys.exit() - elif o in ['-V', '--version']: - sys.stderr.write('quicktest.py (Docutils %s%s)\n' % - (docutils.__version__, - docutils.__version_details__ - and ' [%s]'%docutils.__version_details__ or '')) - sys.exit() - elif o in ['-r', '--rawxml']: - outputFormat = 'rawxml' - elif o in ['-s', '--styledxml']: - outputFormat = 'styledxml' - optargs['styledxml'] = a - elif o in ['-x', '--xml']: - outputFormat = 'xml' - elif o in ['-p', '--pretty']: - outputFormat = 'pretty' - elif o in ['-t', '--test']: - outputFormat = 'test' - elif o in ['--attributes', '-A']: - optargs['attributes'] = 1 - elif o in ['-d', '--debug']: - optargs['debug'] = 1 - else: - raise getopt.GetoptError("getopt should have saved us!") - if len(args) > 2: - print('Maximum 2 arguments allowed.') - usage() - sys.exit(1) - inputFile = sys.stdin - outputFile = sys.stdout - if args: - inputFile = open(args.pop(0)) - if args: - outputFile = open(args.pop(0), 'w') - return inputFile, outputFile, outputFormat, optargs - - -def macGetArgs(): - import EasyDialogs - EasyDialogs.Message("""\ -Use the next dialog to build a command line: - -1. Choose an output format from the [Option] list -2. Click [Add] -3. Choose an input file: [Add existing file...] -4. Save the output: [Add new file...] -5. [OK]""") - optionlist = [(longopt, description) - for (longopt, shortopt, description) in options] - argv = EasyDialogs.GetArgv(optionlist=optionlist, addfolder=0) - return posixGetArgs(argv) - - -def main(): - # process cmdline arguments: - inputFile, outputFile, outputFormat, optargs = getArgs() - settings = frontend.get_default_settings(Parser) - settings.debug = optargs['debug'] - parser = Parser() - input = inputFile.read() - document = new_document(inputFile.name, settings) - parser.parse(input, document) - output = format(outputFormat, input, document, optargs) - outputFile.write(output) - if optargs['attributes']: - import pprint - pprint.pprint(document.__dict__) - - -if __name__ == '__main__': - sys.stderr = sys.stdout - main() From 804af86d407435baa9ed6e7ec4c321ceca65d90f Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Mon, 31 Jan 2022 16:45:05 +0000 Subject: [PATCH 3/3] Use subtests for the functional tests - Inline defaults - Simplify test_functional - Remove unused configurability --- docutils/docs/dev/testing.txt | 16 +- docutils/test/functional/tests/_default.py | 10 - .../tests/_standalone_rst_defaults.py | 7 - .../test/functional/tests/compact_lists.py | 13 ++ docutils/test/functional/tests/dangerous.py | 13 ++ .../test/functional/tests/field_name_limit.py | 13 ++ .../test/functional/tests/footnotes_html5.py | 23 +- docutils/test/functional/tests/latex_babel.py | 13 ++ .../functional/tests/latex_cornercases.py | 13 ++ .../test/functional/tests/latex_cyrillic.py | 13 ++ .../test/functional/tests/latex_docinfo.py | 13 ++ .../test/functional/tests/latex_leavevmode.py | 13 ++ .../functional/tests/latex_literal_block.py | 13 ++ .../tests/latex_literal_block_fancyvrb.py | 13 ++ .../tests/latex_literal_block_listings.py | 13 ++ .../tests/latex_literal_block_verbatim.py | 13 ++ .../tests/latex_literal_block_verbatimtab.py | 13 ++ .../test/functional/tests/latex_memoir.py | 13 ++ .../test/functional/tests/math_output_html.py | 13 ++ .../functional/tests/math_output_latex.py | 13 ++ .../functional/tests/math_output_mathjax.py | 13 ++ .../functional/tests/math_output_mathml.py | 13 ++ .../functional/tests/misc_rst_html4css1.py | 13 ++ .../test/functional/tests/misc_rst_html5.py | 13 ++ docutils/test/functional/tests/pep_html.py | 13 ++ .../tests/standalone_rst_docutils_xml.py | 23 +- .../tests/standalone_rst_html4css1.py | 23 +- .../functional/tests/standalone_rst_html5.py | 23 +- .../functional/tests/standalone_rst_latex.py | 23 +- .../tests/standalone_rst_manpage.py | 23 +- .../tests/standalone_rst_pseudoxml.py | 23 +- .../tests/standalone_rst_s5_html_1.py | 70 ++---- .../tests/standalone_rst_s5_html_2.py | 36 ++- .../functional/tests/standalone_rst_xetex.py | 23 +- .../test/functional/tests/xetex_cyrillic.py | 13 ++ docutils/test/test_functional.py | 220 +++++------------- 36 files changed, 560 insertions(+), 269 deletions(-) delete mode 100644 docutils/test/functional/tests/_default.py delete mode 100644 docutils/test/functional/tests/_standalone_rst_defaults.py diff --git a/docutils/docs/dev/testing.txt b/docutils/docs/dev/testing.txt index 2a18fcd86..4f4ccdc42 100644 --- a/docutils/docs/dev/testing.txt +++ b/docutils/docs/dev/testing.txt @@ -211,15 +211,12 @@ Directory Structure - ``some_test.py``, for example. - - ``_default.py``, the `default configuration file`_. - The Testing Process ------------------- When running ``test_functional.py``, all config files in -``functional/tests/`` are processed. (Config files whose names begin -with an underscore are ignored.) The current working directory is +``functional/tests/`` are processed. The current working directory is always Docutils' main test directory (``test/``). For example, ``functional/tests/some_test.py`` could read like this:: @@ -290,14 +287,3 @@ commit the change. .. note: the ``--dtdvalid`` and ``--nonet`` options did not help override a reference to the PUBLIC "docutils.dtd" if there is a local version on the system (e.g. /usr/share/xml/docutils/docutils.dtd in Debian). - - -.. _default configuration file: - -The Default Configuration File ------------------------------- - -The file ``functional/tests/_default.py`` contains default settings. -It is executed just before the actual configuration files, which has -the same effect as if the contents of ``_default.py`` were prepended -to every configuration file. diff --git a/docutils/test/functional/tests/_default.py b/docutils/test/functional/tests/_default.py deleted file mode 100644 index 74865487d..000000000 --- a/docutils/test/functional/tests/_default.py +++ /dev/null @@ -1,10 +0,0 @@ -# Default settings for all tests. - -settings_overrides['report_level'] = 2 -settings_overrides['halt_level'] = 5 -settings_overrides['warning_stream'] = '' -settings_overrides['input_encoding'] = 'utf-8' -settings_overrides['embed_stylesheet'] = False -settings_overrides['auto_id_prefix'] = '%' -# avoid "Pygments not found" -settings_overrides['syntax_highlight'] = 'none' diff --git a/docutils/test/functional/tests/_standalone_rst_defaults.py b/docutils/test/functional/tests/_standalone_rst_defaults.py deleted file mode 100644 index 5efebbee0..000000000 --- a/docutils/test/functional/tests/_standalone_rst_defaults.py +++ /dev/null @@ -1,7 +0,0 @@ -# Keyword parameters passed to publish_file. -reader_name = "standalone" -parser_name = "rst" - -# Settings. -settings_overrides['sectsubtitle_xform'] = 1 -settings_overrides['syntax_highlight'] = 'none' diff --git a/docutils/test/functional/tests/compact_lists.py b/docutils/test/functional/tests/compact_lists.py index 9a8ecf044..e1442c474 100644 --- a/docutils/test/functional/tests/compact_lists.py +++ b/docutils/test/functional/tests/compact_lists.py @@ -1,3 +1,16 @@ +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} # Source and destination file names. test_source = "compact_lists.txt" test_destination = "compact_lists.html" diff --git a/docutils/test/functional/tests/dangerous.py b/docutils/test/functional/tests/dangerous.py index 84f467163..9874b27ff 100644 --- a/docutils/test/functional/tests/dangerous.py +++ b/docutils/test/functional/tests/dangerous.py @@ -1,3 +1,16 @@ +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} # Source and destination file names. test_source = "dangerous.txt" test_destination = "dangerous.html" diff --git a/docutils/test/functional/tests/field_name_limit.py b/docutils/test/functional/tests/field_name_limit.py index 3a2611c5d..10f8a33f0 100644 --- a/docutils/test/functional/tests/field_name_limit.py +++ b/docutils/test/functional/tests/field_name_limit.py @@ -1,3 +1,16 @@ +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} # Source and destination file names. test_source = "field_list.txt" test_destination = "field_name_limit.html" diff --git a/docutils/test/functional/tests/footnotes_html5.py b/docutils/test/functional/tests/footnotes_html5.py index a59e95633..a0e17edb2 100644 --- a/docutils/test/functional/tests/footnotes_html5.py +++ b/docutils/test/functional/tests/footnotes_html5.py @@ -1,6 +1,23 @@ -with open('functional/tests/_standalone_rst_defaults.py', - encoding='utf-8') as _f: - exec(_f.read()) +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} +# Keyword parameters passed to publish_file. +reader_name = "standalone" +parser_name = "rst" + +# Settings. +settings_overrides['sectsubtitle_xform'] = True +settings_overrides['syntax_highlight'] = 'none' # Source and destination file names. test_source = "footnotes.txt" diff --git a/docutils/test/functional/tests/latex_babel.py b/docutils/test/functional/tests/latex_babel.py index d565da0cd..23258774a 100644 --- a/docutils/test/functional/tests/latex_babel.py +++ b/docutils/test/functional/tests/latex_babel.py @@ -1,3 +1,16 @@ +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} # Source and destination file names. test_source = "latex_babel.txt" test_destination = "latex_babel.tex" diff --git a/docutils/test/functional/tests/latex_cornercases.py b/docutils/test/functional/tests/latex_cornercases.py index 6bf46397a..3ce334f38 100644 --- a/docutils/test/functional/tests/latex_cornercases.py +++ b/docutils/test/functional/tests/latex_cornercases.py @@ -1,3 +1,16 @@ +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} # Source and destination file names. test_source = "latex_cornercases.txt" test_destination = "latex_cornercases.tex" diff --git a/docutils/test/functional/tests/latex_cyrillic.py b/docutils/test/functional/tests/latex_cyrillic.py index 6d78fc264..826e44269 100644 --- a/docutils/test/functional/tests/latex_cyrillic.py +++ b/docutils/test/functional/tests/latex_cyrillic.py @@ -1,3 +1,16 @@ +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} # Source and destination file names. test_source = "cyrillic.txt" test_destination = "cyrillic.tex" diff --git a/docutils/test/functional/tests/latex_docinfo.py b/docutils/test/functional/tests/latex_docinfo.py index 5b63ea817..37231a560 100644 --- a/docutils/test/functional/tests/latex_docinfo.py +++ b/docutils/test/functional/tests/latex_docinfo.py @@ -1,3 +1,16 @@ +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} # Source and destination file names. test_source = "latex_docinfo.txt" test_destination = "latex_docinfo.tex" diff --git a/docutils/test/functional/tests/latex_leavevmode.py b/docutils/test/functional/tests/latex_leavevmode.py index 0cefa80ec..6c7ff84c9 100644 --- a/docutils/test/functional/tests/latex_leavevmode.py +++ b/docutils/test/functional/tests/latex_leavevmode.py @@ -1,3 +1,16 @@ +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} # Source and destination file names. test_source = "latex_leavevmode.txt" test_destination = "latex_leavevmode.tex" diff --git a/docutils/test/functional/tests/latex_literal_block.py b/docutils/test/functional/tests/latex_literal_block.py index 30ea21998..f355312d9 100644 --- a/docutils/test/functional/tests/latex_literal_block.py +++ b/docutils/test/functional/tests/latex_literal_block.py @@ -1,3 +1,16 @@ +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} # Source and destination file names. test_source = "latex_literal_block.txt" test_destination = "latex_literal_block.tex" diff --git a/docutils/test/functional/tests/latex_literal_block_fancyvrb.py b/docutils/test/functional/tests/latex_literal_block_fancyvrb.py index f93dd1fbb..2515f5c5b 100644 --- a/docutils/test/functional/tests/latex_literal_block_fancyvrb.py +++ b/docutils/test/functional/tests/latex_literal_block_fancyvrb.py @@ -1,3 +1,16 @@ +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} # Source and destination file names. test_source = "latex_literal_block.txt" test_destination = "latex_literal_block_fancyvrb.tex" diff --git a/docutils/test/functional/tests/latex_literal_block_listings.py b/docutils/test/functional/tests/latex_literal_block_listings.py index ddc48753c..e6f73bc36 100644 --- a/docutils/test/functional/tests/latex_literal_block_listings.py +++ b/docutils/test/functional/tests/latex_literal_block_listings.py @@ -1,3 +1,16 @@ +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} # Source and destination file names. test_source = "latex_literal_block.txt" test_destination = "latex_literal_block_listings.tex" diff --git a/docutils/test/functional/tests/latex_literal_block_verbatim.py b/docutils/test/functional/tests/latex_literal_block_verbatim.py index 8722f5673..090547e1a 100644 --- a/docutils/test/functional/tests/latex_literal_block_verbatim.py +++ b/docutils/test/functional/tests/latex_literal_block_verbatim.py @@ -1,3 +1,16 @@ +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} # Source and destination file names. test_source = "latex_literal_block.txt" test_destination = "latex_literal_block_verbatim.tex" diff --git a/docutils/test/functional/tests/latex_literal_block_verbatimtab.py b/docutils/test/functional/tests/latex_literal_block_verbatimtab.py index d1c4476cc..e9a9495f6 100644 --- a/docutils/test/functional/tests/latex_literal_block_verbatimtab.py +++ b/docutils/test/functional/tests/latex_literal_block_verbatimtab.py @@ -1,3 +1,16 @@ +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} # Source and destination file names. test_source = "latex_literal_block.txt" test_destination = "latex_literal_block_verbatimtab.tex" diff --git a/docutils/test/functional/tests/latex_memoir.py b/docutils/test/functional/tests/latex_memoir.py index 4ccab6725..bc9aa1cd8 100644 --- a/docutils/test/functional/tests/latex_memoir.py +++ b/docutils/test/functional/tests/latex_memoir.py @@ -1,3 +1,16 @@ +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} # Source and destination file names. test_source = "standalone_rst_latex.txt" test_destination = "latex_memoir.tex" diff --git a/docutils/test/functional/tests/math_output_html.py b/docutils/test/functional/tests/math_output_html.py index cca0af8a8..aeb30d642 100644 --- a/docutils/test/functional/tests/math_output_html.py +++ b/docutils/test/functional/tests/math_output_html.py @@ -1,3 +1,16 @@ +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} # Source and destination file names. test_source = "data/math.txt" test_destination = "math_output_html.html" diff --git a/docutils/test/functional/tests/math_output_latex.py b/docutils/test/functional/tests/math_output_latex.py index 09b0819ec..499ed84bc 100644 --- a/docutils/test/functional/tests/math_output_latex.py +++ b/docutils/test/functional/tests/math_output_latex.py @@ -1,3 +1,16 @@ +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} # Source and destination file names. test_source = "data/math.txt" test_destination = "math_output_latex.html" diff --git a/docutils/test/functional/tests/math_output_mathjax.py b/docutils/test/functional/tests/math_output_mathjax.py index a0441dd21..81cc7acbe 100644 --- a/docutils/test/functional/tests/math_output_mathjax.py +++ b/docutils/test/functional/tests/math_output_mathjax.py @@ -1,3 +1,16 @@ +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} # Source and destination file names. test_source = "data/math.txt" test_destination = "math_output_mathjax.html" diff --git a/docutils/test/functional/tests/math_output_mathml.py b/docutils/test/functional/tests/math_output_mathml.py index f73e23632..c53f99a90 100644 --- a/docutils/test/functional/tests/math_output_mathml.py +++ b/docutils/test/functional/tests/math_output_mathml.py @@ -1,3 +1,16 @@ +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} # Source and destination file names. test_source = "data/math.txt" test_destination = "math_output_mathml.html" diff --git a/docutils/test/functional/tests/misc_rst_html4css1.py b/docutils/test/functional/tests/misc_rst_html4css1.py index 6227e9afd..09533bc82 100644 --- a/docutils/test/functional/tests/misc_rst_html4css1.py +++ b/docutils/test/functional/tests/misc_rst_html4css1.py @@ -1,3 +1,16 @@ +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} # Source and destination file names. test_source = "misc_rst_html4css1.txt" test_destination = "misc_rst_html4css1.html" diff --git a/docutils/test/functional/tests/misc_rst_html5.py b/docutils/test/functional/tests/misc_rst_html5.py index d07121f8e..06caf930f 100644 --- a/docutils/test/functional/tests/misc_rst_html5.py +++ b/docutils/test/functional/tests/misc_rst_html5.py @@ -1,3 +1,16 @@ +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} # Source and destination file names. test_source = "misc_rst_html5.txt" test_destination = "misc_rst_html5.html" diff --git a/docutils/test/functional/tests/pep_html.py b/docutils/test/functional/tests/pep_html.py index 09c796292..0ebe94fbf 100644 --- a/docutils/test/functional/tests/pep_html.py +++ b/docutils/test/functional/tests/pep_html.py @@ -1,3 +1,16 @@ +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} # Source and destination file names. test_source = "pep_html.txt" test_destination = "pep_html.html" diff --git a/docutils/test/functional/tests/standalone_rst_docutils_xml.py b/docutils/test/functional/tests/standalone_rst_docutils_xml.py index da09adb8b..ae4aa64f0 100644 --- a/docutils/test/functional/tests/standalone_rst_docutils_xml.py +++ b/docutils/test/functional/tests/standalone_rst_docutils_xml.py @@ -1,6 +1,23 @@ -with open('functional/tests/_standalone_rst_defaults.py', - encoding='utf-8') as _f: - exec(_f.read()) +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} +# Keyword parameters passed to publish_file. +reader_name = "standalone" +parser_name = "rst" + +# Settings. +settings_overrides['sectsubtitle_xform'] = True +settings_overrides['syntax_highlight'] = 'none' # Source and destination file names. test_source = "standalone_rst_docutils_xml.txt" diff --git a/docutils/test/functional/tests/standalone_rst_html4css1.py b/docutils/test/functional/tests/standalone_rst_html4css1.py index 634aaae73..ddf0e68b7 100644 --- a/docutils/test/functional/tests/standalone_rst_html4css1.py +++ b/docutils/test/functional/tests/standalone_rst_html4css1.py @@ -1,6 +1,23 @@ -with open('functional/tests/_standalone_rst_defaults.py', - encoding='utf-8') as _f: - exec(_f.read()) +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} +# Keyword parameters passed to publish_file. +reader_name = "standalone" +parser_name = "rst" + +# Settings. +settings_overrides['sectsubtitle_xform'] = True +settings_overrides['syntax_highlight'] = 'none' # Source and destination file names. test_source = "standalone_rst_html4css1.txt" diff --git a/docutils/test/functional/tests/standalone_rst_html5.py b/docutils/test/functional/tests/standalone_rst_html5.py index 2a2ce215b..e89c55601 100644 --- a/docutils/test/functional/tests/standalone_rst_html5.py +++ b/docutils/test/functional/tests/standalone_rst_html5.py @@ -1,6 +1,23 @@ -with open('functional/tests/_standalone_rst_defaults.py', - encoding='utf-8') as _f: - exec(_f.read()) +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} +# Keyword parameters passed to publish_file. +reader_name = "standalone" +parser_name = "rst" + +# Settings. +settings_overrides['sectsubtitle_xform'] = True +settings_overrides['syntax_highlight'] = 'none' # Source and destination file names. test_source = "standalone_rst_html5.txt" diff --git a/docutils/test/functional/tests/standalone_rst_latex.py b/docutils/test/functional/tests/standalone_rst_latex.py index 49296f2c9..33b622793 100644 --- a/docutils/test/functional/tests/standalone_rst_latex.py +++ b/docutils/test/functional/tests/standalone_rst_latex.py @@ -1,6 +1,23 @@ -with open('functional/tests/_standalone_rst_defaults.py', - encoding='utf-8') as _f: - exec(_f.read()) +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} +# Keyword parameters passed to publish_file. +reader_name = "standalone" +parser_name = "rst" + +# Settings. +settings_overrides['sectsubtitle_xform'] = True +settings_overrides['syntax_highlight'] = 'none' # Source and destination file names. test_source = "standalone_rst_latex.txt" diff --git a/docutils/test/functional/tests/standalone_rst_manpage.py b/docutils/test/functional/tests/standalone_rst_manpage.py index 1ef663ffe..a3a57d338 100644 --- a/docutils/test/functional/tests/standalone_rst_manpage.py +++ b/docutils/test/functional/tests/standalone_rst_manpage.py @@ -1,6 +1,23 @@ -with open('functional/tests/_standalone_rst_defaults.py', - encoding='utf-8') as _f: - exec(_f.read()) +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} +# Keyword parameters passed to publish_file. +reader_name = "standalone" +parser_name = "rst" + +# Settings. +settings_overrides['sectsubtitle_xform'] = True +settings_overrides['syntax_highlight'] = 'none' # Source and destination file names. test_source = "standalone_rst_manpage.txt" diff --git a/docutils/test/functional/tests/standalone_rst_pseudoxml.py b/docutils/test/functional/tests/standalone_rst_pseudoxml.py index b662ce6d8..20bf4759f 100644 --- a/docutils/test/functional/tests/standalone_rst_pseudoxml.py +++ b/docutils/test/functional/tests/standalone_rst_pseudoxml.py @@ -1,6 +1,23 @@ -with open('functional/tests/_standalone_rst_defaults.py', - encoding='utf-8') as _f: - exec(_f.read()) +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} +# Keyword parameters passed to publish_file. +reader_name = "standalone" +parser_name = "rst" + +# Settings. +settings_overrides['sectsubtitle_xform'] = True +settings_overrides['syntax_highlight'] = 'none' # Source and destination file names. test_source = "standalone_rst_pseudoxml.txt" diff --git a/docutils/test/functional/tests/standalone_rst_s5_html_1.py b/docutils/test/functional/tests/standalone_rst_s5_html_1.py index 4857a1c15..00c3db2a4 100755 --- a/docutils/test/functional/tests/standalone_rst_s5_html_1.py +++ b/docutils/test/functional/tests/standalone_rst_s5_html_1.py @@ -1,9 +1,23 @@ -import filecmp as _filecmp - - -with open('functional/tests/_standalone_rst_defaults.py', - encoding='utf-8') as _f: - exec(_f.read()) +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} +# Keyword parameters passed to publish_file. +reader_name = "standalone" +parser_name = "rst" + +# Settings. +settings_overrides['sectsubtitle_xform'] = True +settings_overrides['syntax_highlight'] = 'none' # Source and destination file names: test_source = 'standalone_rst_s5_html.txt' @@ -16,47 +30,3 @@ settings_overrides['theme'] = 'small-black' # local copy of default stylesheet: settings_overrides['stylesheet_path'] = 'functional/input/data/html4css1.css' - - -# Extra functional tests. -# Prefix all names with '_' to avoid confusing `docutils.core.publish_file`. - -def _test_more(expected_dir, output_dir, test_case, parameters): - """Compare ``ui/`` directories.""" - theme = settings_overrides.get('theme', 'default') - expected = '%s/%s/%s' % (expected_dir, 'ui', theme) - output = '%s/%s/%s' % (output_dir, 'ui', theme) - differences, uniques = _compare_directories(expected, output) - parts = [] - if differences: - parts.append('The following files differ from the expected output:') - parts.extend(differences) - expected = [path.replace('functional/output/', 'functional/expected/') - for path in differences] - parts.append('Please compare the expected and actual output files:') - parts.extend([' diff %s %s' % tup - for tup in zip(expected, differences)]) - parts.append('If the actual output is correct, please replace the ' - 'expected output files:') - parts.extend([' mv %s %s' % tup - for tup in zip(differences, expected)]) - parts.append('and check them in to Subversion:') - parts.extend([' svn commit -m "" %s' % path - for path in expected]) - if uniques: - parts.append('The following paths are unique:') - parts.extend(uniques) - test_case.assertTrue(not parts, '\n'.join(parts)) - - -def _compare_directories(expected, output): - dircmp = _filecmp.dircmp(expected, output, ['.svn', 'CVS']) - differences = ['%s/%s' % (output, name) for name in dircmp.diff_files] - uniques = (['%s/%s' % (expected, name) for name in dircmp.left_only] - + ['%s/%s' % (output, name) for name in dircmp.right_only]) - for subdir in dircmp.common_dirs: - diffs, uniqs = _compare_directories('%s/%s' % (expected, subdir), - '%s/%s' % (output, subdir)) - differences.extend(diffs) - uniques.extend(uniqs) - return differences, uniques diff --git a/docutils/test/functional/tests/standalone_rst_s5_html_2.py b/docutils/test/functional/tests/standalone_rst_s5_html_2.py index 2e9f104ce..0f4615fc1 100755 --- a/docutils/test/functional/tests/standalone_rst_s5_html_2.py +++ b/docutils/test/functional/tests/standalone_rst_s5_html_2.py @@ -1,9 +1,33 @@ -# initialize with the settings & definitions from test 1: -with open('functional/tests/standalone_rst_s5_html_1.py', - encoding='utf-8') as _f: - exec(_f.read()) +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} +# Keyword parameters passed to publish_file. +reader_name = "standalone" +parser_name = "rst" -# overrides specific to this test: +# Settings. +settings_overrides['sectsubtitle_xform'] = True +settings_overrides['syntax_highlight'] = 'none' + +# Source and destination file names: +test_source = 'standalone_rst_s5_html.txt' test_destination = 'standalone_rst_s5_html_2.html' -del settings_overrides['theme'] # use the default + +# Keyword parameters passed to publish_file: +writer_name = 's5_html' + +# Settings: +# use default theme +# local copy of default stylesheet: +settings_overrides['stylesheet_path'] = 'functional/input/data/html4css1.css' settings_overrides['current_slide'] = 1 diff --git a/docutils/test/functional/tests/standalone_rst_xetex.py b/docutils/test/functional/tests/standalone_rst_xetex.py index b86569d34..4ee1f51cf 100644 --- a/docutils/test/functional/tests/standalone_rst_xetex.py +++ b/docutils/test/functional/tests/standalone_rst_xetex.py @@ -1,6 +1,23 @@ -with open('functional/tests/_standalone_rst_defaults.py', - encoding='utf-8') as _f: - exec(_f.read()) +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} +# Keyword parameters passed to publish_file. +reader_name = "standalone" +parser_name = "rst" + +# Settings. +settings_overrides['sectsubtitle_xform'] = True +settings_overrides['syntax_highlight'] = 'none' # Source and destination file names. test_source = "standalone_rst_xetex.txt" diff --git a/docutils/test/functional/tests/xetex_cyrillic.py b/docutils/test/functional/tests/xetex_cyrillic.py index 4a35a3bc3..69089dc6e 100644 --- a/docutils/test/functional/tests/xetex_cyrillic.py +++ b/docutils/test/functional/tests/xetex_cyrillic.py @@ -1,3 +1,16 @@ +settings_overrides = { + # disable configuration files + '_disable_config': True, + # Default settings for all tests. + 'report_level': 2, + 'halt_level': 5, + 'warning_stream': False, + 'input_encoding': 'utf-8', + 'embed_stylesheet': False, + 'auto_id_prefix': '%', + # avoid "Pygments not found" + 'syntax_highlight': 'none' +} # Source and destination file names. test_source = "cyrillic.txt" test_destination = "xetex-cyrillic.tex" diff --git a/docutils/test/test_functional.py b/docutils/test/test_functional.py index 6ddcb7bbe..73ecb3700 100755 --- a/docutils/test/test_functional.py +++ b/docutils/test/test_functional.py @@ -11,179 +11,85 @@ __ ../../docs/dev/testing.html#functional """ -import sys import os import os.path +from pathlib import Path import shutil import unittest -import difflib -import DocutilsTestSupport # must be imported before docutils -import docutils -import docutils.core - - -datadir = 'functional' -"""The directory to store the data needed for the functional tests.""" - - -def join_path(*args): - return '/'.join(args) or '.' - - -class FunctionalTestSuite(DocutilsTestSupport.CustomTestSuite): - - """Test suite containing test cases for all config files.""" - - def __init__(self): - """Process all config files in functional/tests/.""" - super().__init__() - os.chdir(DocutilsTestSupport.testroot) - self.clear_output_directory() - self.added = 0 - for root, dirs, files in os.walk(join_path(datadir, 'tests')): - # Process all config files among `names` in `dirname`. A config - # file is a Python file (*.py) which sets several variables. - for name in files: - if name.endswith('.py') and not name.startswith('_'): - config_file_full_path = join_path(root, name) - self.addTestCase(FunctionalTestCase, 'test', None, None, - id=config_file_full_path, - configfile=config_file_full_path) - self.added += 1 - assert self.added, 'No functional tests found.' - def clear_output_directory(self): - files = os.listdir(os.path.join('functional', 'output')) - for f in files: - if f in ('README.txt', '.svn', 'CVS'): - continue # don't touch the infrastructure - path = os.path.join('functional', 'output', f) - if os.path.isdir(path): - shutil.rmtree(path) - else: - os.remove(path) - - -class FunctionalTestCase(DocutilsTestSupport.CustomTestCase): - - """Test case for one config file.""" +import docutils.core - no_expected_template = """\ -Cannot find expected output at %(exp)s -If the output in %(out)s +NO_EXPECTED_TEMPLATE = """\ +Cannot find expected output at {exp} +If the output in {out} is correct, move it to the expected/ dir and check it in: - mv %(out)s %(exp)s - svn add %(exp)s - svn commit -m "" %(exp)s""" + mv {out} {exp} + svn add {exp} + svn commit -m "" {exp}""" - expected_output_differs_template = """\ +EXPECTED_OUTPUT_DIFFERS_TEMPLATE = """\ The expected and actual output differs. Please compare the expected and actual output files: - diff %(exp)s %(out)s\n' + diff {exp} {out} If the actual output is correct, please replace the expected output and check it in: - mv %(out)s %(exp)s - svn add %(exp)s - svn commit -m "" %(exp)s""" - - def __init__(self, *args, configfile=None, **kwargs): - """ - Set self.configfile, pass remaining arguments to parent. - - Requires keyword argument `configfile`. - - Note: the modified signature is incompatible with - the "pytest" and "nose" frameworks. - """ # cf. feature-request #81 - - assert configfile is not None, 'required argument' - self.configfile = configfile - super().__init__(*args, **kwargs) - - def shortDescription(self): - return 'test_functional.py: ' + self.configfile - - def test(self): - """Process self.configfile.""" - os.chdir(DocutilsTestSupport.testroot) - # Keyword parameters for publish_file: - namespace = {} - # Initialize 'settings_overrides' for test settings scripts, - # and disable configuration files: - namespace['settings_overrides'] = {'_disable_config': True} - # Read the variables set in the default config file and in - # the current config file into namespace: - with open(join_path(datadir, 'tests', '_default.py'), - encoding='utf-8') as f: - defaultpy = f.read() - exec(defaultpy, namespace) - with open(self.configfile, encoding='utf-8') as f: - exec(f.read(), namespace) - # Check for required settings: - assert 'test_source' in namespace,\ - "No 'test_source' supplied in " + self.configfile - assert 'test_destination' in namespace,\ - "No 'test_destination' supplied in " + self.configfile - # Set source_path and destination_path if not given: - namespace.setdefault('source_path', - join_path(datadir, 'input', - namespace['test_source'])) - # Path for actual output: - namespace.setdefault('destination_path', - join_path(datadir, 'output', - namespace['test_destination'])) - # Path for expected output: - expected_path = join_path(datadir, 'expected', - namespace['test_destination']) - # shallow copy of namespace to minimize: - params = namespace.copy() - # remove unneeded parameters: - del params['test_source'] - del params['test_destination'] - # Delete private stuff like params['__builtins__']: - for key in list(params.keys()): - if key.startswith('_'): - del params[key] - # Get output (automatically written to the output/ directory - # by publish_file): - output = docutils.core.publish_file(**params) - # Normalize line endings: - output = '\n'.join(output.splitlines()) - # Get the expected output *after* writing the actual output. - no_expected = self.no_expected_template % { - 'exp': expected_path, 'out': params['destination_path']} - self.assertTrue(os.access(expected_path, os.R_OK), no_expected) - # samples are UTF-8 encoded. 'rb' leads to errors with Python 3! - f = open(expected_path, 'r', encoding='utf-8') - # Normalize line endings: - expected = '\n'.join(f.read().splitlines()) - f.close() - - diff = self.expected_output_differs_template % { - 'exp': expected_path, 'out': params['destination_path']} - try: - self.assertEqual(output, expected, diff) - except AssertionError: - diff = ''.join(difflib.unified_diff( - expected.splitlines(True), output.splitlines(True), - expected_path, params['destination_path'])) - print('\n%s:' % (self,), file=sys.stderr) - print(diff, file=sys.stderr) - raise - # Execute optional function containing extra tests: - if '_test_more' in namespace: - namespace['_test_more'](join_path(datadir, 'expected'), - join_path(datadir, 'output'), - self, namespace) - - -def suite(): - return FunctionalTestSuite() + mv {out} {exp} + svn add {exp} + svn commit -m "" {exp}""" + + +class FunctionalTests(unittest.TestCase): + + """Test case for one config file.""" + maxDiff = None + + def setUp(self): + """Clear output directory.""" + for entry in os.scandir(Path('functional', 'output')): + if os.path.isdir(entry.path): + shutil.rmtree(entry.path) + elif entry.name != "README.txt": + os.unlink(entry.path) + + def test_functional(self): + """Process test file.""" + for test_file in Path('functional', 'tests').glob("*.py"): + with self.subTest(test_file=test_file.as_posix()): + namespace = {} + # Load variables set in the current test file into the namespace + exec(test_file.read_text(encoding='utf-8'), namespace) + + # Full source, actual output, and expected output paths + source_path = Path('functional', 'input', namespace['test_source']) + destination_path = Path('functional', 'output', namespace['test_destination']) + expected_path = Path('functional', 'expected', namespace['test_destination']) + + # remove unneeded keys: + for key in 'test_source', 'test_destination', '__builtins__': + del namespace[key] + + # Get output (automatically written to the output/ directory + # by publish_file): + output = docutils.core.publish_file( + **namespace, source_path=source_path.as_posix(), + destination_path=destination_path.as_posix()) + + # Get the expected output *after* writing the actual output. + try: + expected = expected_path.read_text(encoding='utf-8') + except OSError as err: + raise OSError(NO_EXPECTED_TEMPLATE.format( + exp=expected_path, out=destination_path)) from err + + self.assertEqual( + output, expected, + EXPECTED_OUTPUT_DIFFERS_TEMPLATE.format( + exp=expected_path, out=destination_path)) if __name__ == '__main__': - unittest.main(defaultTest='suite') + unittest.main()