From baa95e98ac266eca63fe115ddb3a6ea08c493408 Mon Sep 17 00:00:00 2001 From: Ed Slavich Date: Mon, 27 Dec 2021 14:10:22 -0500 Subject: [PATCH 1/2] Add test of :skip: with stdlib objects --- .../tests/example_module/stdlib.py | 12 +++++ sphinx_automodapi/tests/test_automodapi.py | 50 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 sphinx_automodapi/tests/example_module/stdlib.py diff --git a/sphinx_automodapi/tests/example_module/stdlib.py b/sphinx_automodapi/tests/example_module/stdlib.py new file mode 100644 index 0000000..3ce715d --- /dev/null +++ b/sphinx_automodapi/tests/example_module/stdlib.py @@ -0,0 +1,12 @@ +""" +A module that imports objects from the standard library. +""" +from pathlib import Path +from datetime import time + + +def add(a, b): + """ + Add two numbers + """ + return a + b diff --git a/sphinx_automodapi/tests/test_automodapi.py b/sphinx_automodapi/tests/test_automodapi.py index cd0550e..21f6e1d 100644 --- a/sphinx_automodapi/tests/test_automodapi.py +++ b/sphinx_automodapi/tests/test_automodapi.py @@ -327,6 +327,56 @@ def test_am_replacer_skip(tmpdir): assert result == am_replacer_skip_expected +am_replacer_skip_stdlib_str = """ +This comes before + +.. automodapi:: sphinx_automodapi.tests.example_module.stdlib + :skip: time + :skip: Path + +This comes after +""" + + +am_replacer_skip_stdlib_expected = """ +This comes before + + +sphinx_automodapi.tests.example_module.stdlib Module +---------------------------------------------------- + +.. automodule:: sphinx_automodapi.tests.example_module.stdlib + +Functions +^^^^^^^^^ + +.. automodsumm:: sphinx_automodapi.tests.example_module.stdlib + :functions-only: + :toctree: api + :skip: time,Path + + +This comes after +""".format(empty='') + + +def test_am_replacer_skip_stdlib(tmpdir): + """ + Tests using the ":skip:" option in an ".. automodapi::" + that skips objects imported from the standard library. + """ + + with open(tmpdir.join('index.rst').strpath, 'w') as f: + f.write(am_replacer_skip_stdlib_str.format(options='')) + + run_sphinx_in_tmpdir(tmpdir) + + with open(tmpdir.join('index.rst.automodapi').strpath) as f: + result = f.read() + + assert result == am_replacer_skip_stdlib_expected + + am_replacer_include_str = """ This comes before From 8be51e311d8748594e3537ed22471b6d114e3799 Mon Sep 17 00:00:00 2001 From: Ed Slavich Date: Mon, 27 Dec 2021 14:19:12 -0500 Subject: [PATCH 2/2] Fix style issue --- sphinx_automodapi/tests/example_module/stdlib.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sphinx_automodapi/tests/example_module/stdlib.py b/sphinx_automodapi/tests/example_module/stdlib.py index 3ce715d..626dc69 100644 --- a/sphinx_automodapi/tests/example_module/stdlib.py +++ b/sphinx_automodapi/tests/example_module/stdlib.py @@ -5,6 +5,9 @@ from datetime import time +__all__ = ['Path', 'time', 'add'] + + def add(a, b): """ Add two numbers