diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 17:25:40 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 17:25:40 +0000 |
commit | cf7da1843c45a4c2df7a749f7886a2d2ba0ee92a (patch) | |
tree | 18dcde1a8d1f5570a77cd0c361de3b490d02c789 /tests/roots/test-ext-doctest | |
parent | Initial commit. (diff) | |
download | sphinx-be21195fae81d3ed2bf307cc2df9ad6779da83b0.tar.xz sphinx-be21195fae81d3ed2bf307cc2df9ad6779da83b0.zip |
Adding upstream version 7.2.6.upstream/7.2.6
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | tests/roots/test-ext-doctest-skipif/conf.py | 16 | ||||
-rw-r--r-- | tests/roots/test-ext-doctest-skipif/skipif.txt | 81 | ||||
-rw-r--r-- | tests/roots/test-ext-doctest-with-autodoc/conf.py | 7 | ||||
-rw-r--r-- | tests/roots/test-ext-doctest-with-autodoc/dir/__init__.py | 0 | ||||
-rw-r--r-- | tests/roots/test-ext-doctest-with-autodoc/dir/bar.py | 4 | ||||
-rw-r--r-- | tests/roots/test-ext-doctest-with-autodoc/dir/inner.rst | 4 | ||||
-rw-r--r-- | tests/roots/test-ext-doctest-with-autodoc/foo.py | 5 | ||||
-rw-r--r-- | tests/roots/test-ext-doctest-with-autodoc/index.rst | 4 | ||||
-rw-r--r-- | tests/roots/test-ext-doctest/conf.py | 6 | ||||
-rw-r--r-- | tests/roots/test-ext-doctest/doctest.txt | 163 |
10 files changed, 290 insertions, 0 deletions
diff --git a/tests/roots/test-ext-doctest-skipif/conf.py b/tests/roots/test-ext-doctest-skipif/conf.py new file mode 100644 index 0000000..6f54982 --- /dev/null +++ b/tests/roots/test-ext-doctest-skipif/conf.py @@ -0,0 +1,16 @@ +extensions = ['sphinx.ext.doctest'] + +project = 'test project for the doctest :skipif: directive' +root_doc = 'skipif' +source_suffix = '.txt' +exclude_patterns = ['_build'] + +doctest_global_setup = ''' +from tests.test_ext_doctest import record + +record('doctest_global_setup', 'body', True) +''' + +doctest_global_cleanup = ''' +record('doctest_global_cleanup', 'body', True) +''' diff --git a/tests/roots/test-ext-doctest-skipif/skipif.txt b/tests/roots/test-ext-doctest-skipif/skipif.txt new file mode 100644 index 0000000..c5bd398 --- /dev/null +++ b/tests/roots/test-ext-doctest-skipif/skipif.txt @@ -0,0 +1,81 @@ +Testing the doctest extension's `:skipif:` option +================================================= + +testsetup +--------- + +.. testsetup:: group-skipif + :skipif: record('testsetup', ':skipif:', True) != 'this will be True' + + record('testsetup', 'body', True) + +.. testsetup:: group-skipif + :skipif: record('testsetup', ':skipif:', False) == 'this will be False' + + record('testsetup', 'body', False) + + +doctest +------- +.. doctest:: group-skipif + :skipif: record('doctest', ':skipif:', True) != 'this will be True' + + >>> print(record('doctest', 'body', True)) + The test is skipped, and this expected text is ignored + + +.. doctest:: + :skipif: record('doctest', ':skipif:', False) == 'this will be False' + + >>> print(record('doctest', 'body', False)) + Recorded doctest body False + + +testcode and testoutput +----------------------- + +testcode skipped +~~~~~~~~~~~~~~~~ + +.. testcode:: group-skipif + :skipif: record('testcode', ':skipif:', True) != 'this will be True' + + print(record('testcode', 'body', True)) + +.. testoutput:: group-skipif + :skipif: record('testoutput-1', ':skipif:', True) != 'this will be True' + + The previous testcode is skipped, and the :skipif: condition is True, + so this testoutput is ignored + +testcode executed +~~~~~~~~~~~~~~~~~ + +.. testcode:: group-skipif + :skipif: record('testcode', ':skipif:', False) == 'this will be False' + + print(record('testcode', 'body', False)) + +.. testoutput:: group-skipif + :skipif: record('testoutput-2', ':skipif:', False) == 'this will be False' + + Recorded testcode body False + +.. testoutput:: group-skipif + :skipif: record('testoutput-2', ':skipif:', True) != 'this will be True' + + The :skipif: condition is False, so this testoutput is ignored + + +testcleanup +----------- + +.. testcleanup:: group-skipif + :skipif: record('testcleanup', ':skipif:', True) != 'this will be True' + + record('testcleanup', 'body', True) + +.. testcleanup:: group-skipif + :skipif: record('testcleanup', ':skipif:', False) == 'this will be False' + + record('testcleanup', 'body', False) diff --git a/tests/roots/test-ext-doctest-with-autodoc/conf.py b/tests/roots/test-ext-doctest-with-autodoc/conf.py new file mode 100644 index 0000000..1ec1dd9 --- /dev/null +++ b/tests/roots/test-ext-doctest-with-autodoc/conf.py @@ -0,0 +1,7 @@ +import sys +from os import path + +sys.path.insert(0, path.abspath(path.dirname(__file__))) + +project = 'test project for doctest + autodoc reporting' +extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest'] diff --git a/tests/roots/test-ext-doctest-with-autodoc/dir/__init__.py b/tests/roots/test-ext-doctest-with-autodoc/dir/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/roots/test-ext-doctest-with-autodoc/dir/__init__.py diff --git a/tests/roots/test-ext-doctest-with-autodoc/dir/bar.py b/tests/roots/test-ext-doctest-with-autodoc/dir/bar.py new file mode 100644 index 0000000..122fdf7 --- /dev/null +++ b/tests/roots/test-ext-doctest-with-autodoc/dir/bar.py @@ -0,0 +1,4 @@ +""" +>>> 'dir/bar.py:2' + +""" diff --git a/tests/roots/test-ext-doctest-with-autodoc/dir/inner.rst b/tests/roots/test-ext-doctest-with-autodoc/dir/inner.rst new file mode 100644 index 0000000..b2ee47f --- /dev/null +++ b/tests/roots/test-ext-doctest-with-autodoc/dir/inner.rst @@ -0,0 +1,4 @@ +>>> 'dir/inner.rst:1' + +.. automodule:: dir.bar + :members: diff --git a/tests/roots/test-ext-doctest-with-autodoc/foo.py b/tests/roots/test-ext-doctest-with-autodoc/foo.py new file mode 100644 index 0000000..9f62a19 --- /dev/null +++ b/tests/roots/test-ext-doctest-with-autodoc/foo.py @@ -0,0 +1,5 @@ +""" + +>>> 'foo.py:3' + +""" diff --git a/tests/roots/test-ext-doctest-with-autodoc/index.rst b/tests/roots/test-ext-doctest-with-autodoc/index.rst new file mode 100644 index 0000000..09d1239 --- /dev/null +++ b/tests/roots/test-ext-doctest-with-autodoc/index.rst @@ -0,0 +1,4 @@ +.. automodule:: foo + :members: + +>>> 'index.rst:4' diff --git a/tests/roots/test-ext-doctest/conf.py b/tests/roots/test-ext-doctest/conf.py new file mode 100644 index 0000000..d0e8b10 --- /dev/null +++ b/tests/roots/test-ext-doctest/conf.py @@ -0,0 +1,6 @@ +extensions = ['sphinx.ext.doctest'] + +project = 'test project for doctest' +root_doc = 'doctest' +source_suffix = '.txt' +exclude_patterns = ['_build'] diff --git a/tests/roots/test-ext-doctest/doctest.txt b/tests/roots/test-ext-doctest/doctest.txt new file mode 100644 index 0000000..04780cf --- /dev/null +++ b/tests/roots/test-ext-doctest/doctest.txt @@ -0,0 +1,163 @@ +Testing the doctest extension +============================= + +Simple doctest blocks +--------------------- + +>>> 1+1 +2 +>>> 1/0 +Traceback (most recent call last): + ... +ZeroDivisionError: integer division or modulo by zero + + +Special directives +------------------ + +* doctest + + .. doctest:: + + >>> 1+1 + 2 + >>> 1/0 + Traceback (most recent call last): + ... + ZeroDivisionError: integer division or modulo by zero + +* testcode/testoutput + + .. testcode:: + + print(1+1) + + .. testoutput:: + + 2 + + .. testcode:: + + 1/0 + + .. testoutput:: + + Traceback (most recent call last): + ... + ZeroDivisionError: integer division or modulo by zero + +* testsetup + + .. testsetup:: * + + def squared(x): + return x * x + + .. doctest:: + + >>> squared(2) + 4 + + .. testcode:: + + print(squared(2)) + + .. testoutput:: + + 4 + + >>> squared(2) + 4 + +* options for doctest/testcode/testoutput blocks + + .. testcode:: + :hide: + + print('Output text.') + + .. testoutput:: + :hide: + :options: +NORMALIZE_WHITESPACE + + Output text. + + .. doctest:: + :pyversion: >= 2.0 + + >>> a = 3 + >>> a + 3 + + .. doctest:: + :pyversion: < 2.0 + + >>> a = 3 + >>> a + 4 + +* grouping + + .. testsetup:: group1 + + def add(x, y): + return x + y + + + ``add`` is now known in "group1", but not in others. + + .. doctest:: group1 + + >>> add(1, 1) + 2 + + .. doctest:: group2 + + >>> add(1, 1) + Traceback (most recent call last): + ... + NameError: name 'add' is not defined + + Interleaving testcode/testoutput: + + .. testcode:: group1 + + print(squared(3)) + + .. testcode:: group2 + + print(squared(4)) + + .. testoutput:: group1 + + 9 + + .. testoutput:: group2 + + 16 + + +.. testcleanup:: * + + from tests import test_ext_doctest + test_ext_doctest.cleanup_call() + +non-ASCII result +---------------- + +>>> print('umlauts: äöü.') +umlauts: äöü. +>>> print('Japanese: 日本語') +Japanese: 日本語 + +keep control char in raw string +------------------------------- + +.. doctest:: + + >>> print('one\ntwo') + one + two + >>> print(r'one\ntwo') + one\ntwo + |