mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Apply black to everything, enforce via unit tests (#449)
I've run the black code formatting tool against everything:
black tests datasette setup.py
I also added a new unit test, in tests/test_black.py, which will fail if the code does not
conform to black's exacting standards.
This unit test only runs on Python 3.6 or higher, because black itself doesn't run on 3.5.
This commit is contained in:
parent
66c87cee0c
commit
35d6ee2790
31 changed files with 2758 additions and 2702 deletions
|
|
@ -9,13 +9,13 @@ from pathlib import Path
|
|||
import pytest
|
||||
import re
|
||||
|
||||
docs_path = Path(__file__).parent.parent / 'docs'
|
||||
label_re = re.compile(r'\.\. _([^\s:]+):')
|
||||
docs_path = Path(__file__).parent.parent / "docs"
|
||||
label_re = re.compile(r"\.\. _([^\s:]+):")
|
||||
|
||||
|
||||
def get_headings(filename, underline="-"):
|
||||
content = (docs_path / filename).open().read()
|
||||
heading_re = re.compile(r'(\w+)(\([^)]*\))?\n\{}+\n'.format(underline))
|
||||
heading_re = re.compile(r"(\w+)(\([^)]*\))?\n\{}+\n".format(underline))
|
||||
return set(h[0] for h in heading_re.findall(content))
|
||||
|
||||
|
||||
|
|
@ -24,38 +24,37 @@ def get_labels(filename):
|
|||
return set(label_re.findall(content))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('config', app.CONFIG_OPTIONS)
|
||||
@pytest.mark.parametrize("config", app.CONFIG_OPTIONS)
|
||||
def test_config_options_are_documented(config):
|
||||
assert config.name in get_headings("config.rst")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("name,filename", (
|
||||
("serve", "datasette-serve-help.txt"),
|
||||
("package", "datasette-package-help.txt"),
|
||||
("publish now", "datasette-publish-now-help.txt"),
|
||||
("publish heroku", "datasette-publish-heroku-help.txt"),
|
||||
("publish cloudrun", "datasette-publish-cloudrun-help.txt"),
|
||||
))
|
||||
@pytest.mark.parametrize(
|
||||
"name,filename",
|
||||
(
|
||||
("serve", "datasette-serve-help.txt"),
|
||||
("package", "datasette-package-help.txt"),
|
||||
("publish now", "datasette-publish-now-help.txt"),
|
||||
("publish heroku", "datasette-publish-heroku-help.txt"),
|
||||
("publish cloudrun", "datasette-publish-cloudrun-help.txt"),
|
||||
),
|
||||
)
|
||||
def test_help_includes(name, filename):
|
||||
expected = open(str(docs_path / filename)).read()
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, name.split() + ["--help"], terminal_width=88)
|
||||
actual = "$ datasette {} --help\n\n{}".format(
|
||||
name, result.output
|
||||
)
|
||||
actual = "$ datasette {} --help\n\n{}".format(name, result.output)
|
||||
# actual has "Usage: cli package [OPTIONS] FILES"
|
||||
# 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('_')
|
||||
])
|
||||
@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", "~")
|
||||
]
|
||||
headings = [s.split("(")[0] for s in get_headings("plugins.rst", "~")]
|
||||
assert plugin in headings
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue