From 88337c65336f1bc0663fbd599d6db931f6c3264b Mon Sep 17 00:00:00 2001 From: taschini Date: Thu, 21 Apr 2016 10:43:41 +0200 Subject: [PATCH 1/4] Added config variable for default doctest flags (#2471). --- CHANGES | 1 + sphinx/ext/doctest.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index d86e85dc0..55cba1f73 100644 --- a/CHANGES +++ b/CHANGES @@ -11,6 +11,7 @@ Features added * Add ``:caption:`` option for sphinx.ext.inheritance_diagram. * #894: Add ``lualatexpdf`` and ``xelatexpdf`` as a make target to build PDF using lualatex or xelatex +* #2471: Add config variable for default doctest flags. Bugs fixed ---------- diff --git a/sphinx/ext/doctest.py b/sphinx/ext/doctest.py index 0f5241a19..244762b69 100644 --- a/sphinx/ext/doctest.py +++ b/sphinx/ext/doctest.py @@ -214,8 +214,7 @@ class DocTestBuilder(Builder): def init(self): # default options - self.opt = doctest.DONT_ACCEPT_TRUE_FOR_1 | doctest.ELLIPSIS | \ - doctest.IGNORE_EXCEPTION_DETAIL + self.opt = self.config.doctest_default_flags # HACK HACK HACK # doctest compiles its snippets with type 'single'. That is nice @@ -464,4 +463,8 @@ def setup(app): app.add_config_value('doctest_test_doctest_blocks', 'default', False) app.add_config_value('doctest_global_setup', '', False) app.add_config_value('doctest_global_cleanup', '', False) + app.add_config_value( + 'doctest_default_flags', + doctest.DONT_ACCEPT_TRUE_FOR_1 | doctest.ELLIPSIS | doctest.IGNORE_EXCEPTION_DETAIL, + False) return {'version': sphinx.__display_version__, 'parallel_read_safe': True} From 8c1d9cc71cbc1890281696812dc5e6f50669f4af Mon Sep 17 00:00:00 2001 From: taschini Date: Thu, 21 Apr 2016 10:54:53 +0200 Subject: [PATCH 2/4] Documenting doctest_default_flags config variable (#2471). --- doc/ext/doctest.rst | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/doc/ext/doctest.rst b/doc/ext/doctest.rst index 9b1b4e6d4..482e23ca4 100644 --- a/doc/ext/doctest.rst +++ b/doc/ext/doctest.rst @@ -55,13 +55,10 @@ names. .. rst:directive:: .. doctest:: [group] - A doctest-style code block. You can use standard :mod:`doctest` flags for - controlling how actual output is compared with what you give as output. By - default, these options are enabled: ``ELLIPSIS`` (allowing you to put - ellipses in the expected output that match anything in the actual output), - ``IGNORE_EXCEPTION_DETAIL`` (not comparing tracebacks), - ``DONT_ACCEPT_TRUE_FOR_1`` (by default, doctest accepts "True" in the output - where "1" is given -- this is a relic of pre-Python 2.2 times). + A doctest-style code block. You can use standard :mod:`doctest` + flags for controlling how actual output is compared with what you + give as output. The default set of flags is specified by the + :confval:`doctest_default_flags` configuration variable. This directive supports two options: @@ -176,6 +173,16 @@ The following is an example for the usage of the directives. The test via There are also these config values for customizing the doctest extension: +.. confval:: doctest_default_flags + + By default, these options are enabled: ``ELLIPSIS`` (allowing you + to put ellipses in the expected output that match anything in the + actual output), ``IGNORE_EXCEPTION_DETAIL`` (everything following + the leftmost colon and any module information in the exception name + is ignored), ``DONT_ACCEPT_TRUE_FOR_1`` (by default, doctest + accepts "True" in the output where "1" is given -- this is a relic + of pre-Python 2.2 times). + .. confval:: doctest_path A list of directories that will be added to :data:`sys.path` when the doctest From 604b45d44b8005b100957726f65bf32453649e1e Mon Sep 17 00:00:00 2001 From: taschini Date: Thu, 21 Apr 2016 12:30:39 +0200 Subject: [PATCH 3/4] Incorporated feeback on doc for doctest_default_flags (#2471). --- doc/ext/doctest.rst | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/doc/ext/doctest.rst b/doc/ext/doctest.rst index 482e23ca4..bc5878cf6 100644 --- a/doc/ext/doctest.rst +++ b/doc/ext/doctest.rst @@ -55,10 +55,10 @@ names. .. rst:directive:: .. doctest:: [group] - A doctest-style code block. You can use standard :mod:`doctest` - flags for controlling how actual output is compared with what you - give as output. The default set of flags is specified by the - :confval:`doctest_default_flags` configuration variable. + A doctest-style code block. You can use standard :mod:`doctest` flags for + controlling how actual output is compared with what you give as output. The + default set of flags is specified by the :confval:`doctest_default_flags` + configuration variable. This directive supports two options: @@ -175,13 +175,14 @@ There are also these config values for customizing the doctest extension: .. confval:: doctest_default_flags - By default, these options are enabled: ``ELLIPSIS`` (allowing you - to put ellipses in the expected output that match anything in the - actual output), ``IGNORE_EXCEPTION_DETAIL`` (everything following - the leftmost colon and any module information in the exception name - is ignored), ``DONT_ACCEPT_TRUE_FOR_1`` (by default, doctest - accepts "True" in the output where "1" is given -- this is a relic - of pre-Python 2.2 times). + By default, these options are enabled: ``ELLIPSIS`` (allowing you to put + ellipses in the expected output that match anything in the actual output), + ``IGNORE_EXCEPTION_DETAIL`` (everything following the leftmost colon and any + module information in the exception name is ignored), + ``DONT_ACCEPT_TRUE_FOR_1`` (by default, doctest accepts "True" in the output + where "1" is given -- this is a relic of pre-Python 2.2 times). + + .. versionadded:: 1.5 .. confval:: doctest_path From 80bbdd4998a4f84ecdbf983cdb5857ae1aa2b996 Mon Sep 17 00:00:00 2001 From: taschini Date: Thu, 21 Apr 2016 14:17:43 +0200 Subject: [PATCH 4/4] Reformatted doc for doctest_default_flags (#2471). --- doc/ext/doctest.rst | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/doc/ext/doctest.rst b/doc/ext/doctest.rst index bc5878cf6..f3086f398 100644 --- a/doc/ext/doctest.rst +++ b/doc/ext/doctest.rst @@ -175,12 +175,15 @@ There are also these config values for customizing the doctest extension: .. confval:: doctest_default_flags - By default, these options are enabled: ``ELLIPSIS`` (allowing you to put - ellipses in the expected output that match anything in the actual output), - ``IGNORE_EXCEPTION_DETAIL`` (everything following the leftmost colon and any - module information in the exception name is ignored), - ``DONT_ACCEPT_TRUE_FOR_1`` (by default, doctest accepts "True" in the output - where "1" is given -- this is a relic of pre-Python 2.2 times). + By default, these options are enabled: + + - ``ELLIPSIS``, allowing you to put ellipses in the expected output that + match anything in the actual output; + - ``IGNORE_EXCEPTION_DETAIL``, causing everything following the leftmost + colon and any module information in the exception name to be ignored; + - ``DONT_ACCEPT_TRUE_FOR_1``, rejecting "True" in the output where "1" is + given -- the default behavior of accepting this substitution is a relic of + pre-Python 2.2 times. .. versionadded:: 1.5