diff options
Diffstat (limited to 'tests/test_extensions/test_ext_apidoc.py')
-rw-r--r-- | tests/test_extensions/test_ext_apidoc.py | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/tests/test_extensions/test_ext_apidoc.py b/tests/test_extensions/test_ext_apidoc.py index c3c979f..13c43df 100644 --- a/tests/test_extensions/test_ext_apidoc.py +++ b/tests/test_extensions/test_ext_apidoc.py @@ -2,6 +2,7 @@ import os.path from collections import namedtuple +from pathlib import Path import pytest @@ -9,7 +10,7 @@ import sphinx.ext.apidoc from sphinx.ext.apidoc import main as apidoc_main -@pytest.fixture() +@pytest.fixture def apidoc(rootdir, tmp_path, apidoc_params): _, kwargs = apidoc_params coderoot = rootdir / kwargs.get('coderoot', 'test-root') @@ -20,7 +21,7 @@ def apidoc(rootdir, tmp_path, apidoc_params): return namedtuple('apidoc', 'coderoot,outdir')(coderoot, outdir) -@pytest.fixture() +@pytest.fixture def apidoc_params(request): pargs = {} kwargs = {} @@ -661,3 +662,23 @@ def test_no_duplicates(rootdir, tmp_path): finally: sphinx.ext.apidoc.PY_SUFFIXES = original_suffixes + + +def test_remove_old_files(tmp_path: Path): + """Test that old files are removed when using the -r option. + + Also ensure that pre-existing files are not re-written, if unchanged. + This is required to avoid unnecessary rebuilds. + """ + module_dir = tmp_path / 'module' + module_dir.mkdir() + (module_dir / 'example.py').write_text('', encoding='utf8') + gen_dir = tmp_path / 'gen' + gen_dir.mkdir() + (gen_dir / 'other.rst').write_text('', encoding='utf8') + apidoc_main(['-o', str(gen_dir), str(module_dir)]) + assert set(gen_dir.iterdir()) == {gen_dir / 'modules.rst', gen_dir / 'example.rst', gen_dir / 'other.rst'} + example_mtime = (gen_dir / 'example.rst').stat().st_mtime + apidoc_main(['--remove-old', '-o', str(gen_dir), str(module_dir)]) + assert set(gen_dir.iterdir()) == {gen_dir / 'modules.rst', gen_dir / 'example.rst'} + assert (gen_dir / 'example.rst').stat().st_mtime == example_mtime |