From 3ac21c749881d0fb1c35b0f9b7a819e29f61c5c1 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Wed, 25 Jul 2018 21:09:33 -0700 Subject: [PATCH] Unit test confirming all plugin hooks are documented --- tests/test_docs.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/test_docs.py b/tests/test_docs.py index d8fa7be5fd..ffbb7ca151 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -9,14 +9,17 @@ import re docs_path = Path(__file__).parent.parent / 'docs' -markdown = (docs_path / 'config.rst').open().read() -setting_heading_re = re.compile(r'(\w+)\n\-+\n') -setting_headings = set(setting_heading_re.findall(markdown)) + + +def get_headings(filename, underline="-"): + markdown = (docs_path / filename).open().read() + heading_re = re.compile(r'(\S+)\n\{}+\n'.format(underline)) + return set(heading_re.findall(markdown)) @pytest.mark.parametrize('config', app.CONFIG_OPTIONS) def test_config_options_are_documented(config): - assert config.name in setting_headings + assert config.name in get_headings("config.rst") @pytest.mark.parametrize('name,filename', ( @@ -35,3 +38,13 @@ def test_help_includes(name, filename): # because it doesn't know that cli will be aliased to datasette expected = expected.replace('Usage: datasette', 'Usage: cli') assert expected == actual + + +@pytest.mark.parametrize('plugin', [ + name for name in dir(app.pm.hook) if not name.startswith('_') +]) +def test_plugin_hooks_are_documented(plugin): + headings = [ + s.split("(")[0] for s in get_headings("plugins.rst", "~") + ] + assert plugin in headings