Skip to content

Commit 5e3f308

Browse files
committed
Documentation unit tests for widgets, closes #125
1 parent acb3752 commit 5e3f308

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

docs/widgets.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ select 'Number of states' as label, count(*) as big_number from states;
4242

4343
Big number live demo: [simonwillison.net/dashboard/big-numbers-demo/](https://simonwillison.net/dashboard/big-numbers-demo/)
4444

45-
## Progress bar: total_count, completed_count
45+
## Progress bar: completed_count, total_count
4646

4747
To display a progress bar, return columns `total_count` and `completed_count`.
4848

@@ -62,7 +62,7 @@ select (
6262

6363
Progress bar live demo: [simonwillison.net/dashboard/progress-bar-demo/](https://simonwillison.net/dashboard/progress-bar-demo/)
6464

65-
## Word cloud: wordcloud_word, wordcloud_count
65+
## Word cloud: wordcloud_count, wordcloud_word
6666

6767
To display a word cloud, return a column `wordcloud_word` containing words with a corresponding `wordcloud_count` column with the frequency of those words.
6868

test_project/test_docs.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import pytest
2+
import pathlib
3+
import re
4+
5+
docs_dir = pathlib.Path(__file__).parent.parent / "docs"
6+
widgets_md = (docs_dir / "widgets.md").read_text()
7+
widget_templates_dir = (
8+
pathlib.Path(__file__).parent.parent
9+
/ "django_sql_dashboard"
10+
/ "templates"
11+
/ "django_sql_dashboard"
12+
/ "widgets"
13+
)
14+
header_re = re.compile(r"^## (.*)", re.M)
15+
headers = [
16+
bit.split(":")[-1].strip().replace(", ", "-")
17+
for bit in header_re.findall(widgets_md)
18+
]
19+
20+
21+
@pytest.mark.parametrize(
22+
"template",
23+
[
24+
t
25+
for t in widget_templates_dir.glob("*.html")
26+
if t.stem not in ("default", "error") and not t.stem.startswith("_")
27+
],
28+
)
29+
def test_widgets_are_documented(template):
30+
assert template.stem in headers, "Widget {} is not documented".format(template.stem)

0 commit comments

Comments
 (0)