Skip to content

Commit 341b5fa

Browse files
committed
tool: set up tests for tooling code
1 parent 89f6156 commit 341b5fa

10 files changed

Lines changed: 99 additions & 44 deletions

File tree

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
44
init::
55
python -m pip install --upgrade pip
66
python -m pip install pip-tools
7-
python -m piptools compile explorer/requirements/dev-requirements.in
8-
python -m piptools compile explorer/requirements/requirements.in
9-
python -m piptools sync explorer/requirements/dev-requirements.txt explorer/requirements/requirements.txt
7+
python -m piptools compile requirements/dev-requirements.in
8+
python -m piptools compile requirements/requirements.in
9+
python -m piptools sync requirements/dev-requirements.txt requirements/requirements.txt
1010

1111

1212
checks:
@@ -49,4 +49,4 @@ commit-issue-tracking::
4949

5050
commit-outputs:
5151
git add generated/
52-
git diff --quiet && git diff --staged --quiet || (git commit -m "Latest generated outputs $(shell date +%F)"; git push origin $(BRANCH))
52+
git diff --quiet && git diff --staged --quiet || (git commit -m "Latest generated outputs $(shell date +%F)"; git push origin $(BRANCH))

bin/utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,18 @@ def save_string_to_file(content: str, file_path: str):
1616
os.makedirs(folder, exist_ok=True)
1717
with open(file_path, "w", encoding="utf-8") as f:
1818
f.write(content)
19+
20+
21+
# New helpers for name/anchor formatting
22+
def to_anchor(s: str) -> str:
23+
"""
24+
Convert a string into a URL-safe kebab-case anchor.
25+
e.g. "Site constraint" -> "site-constraint"
26+
"""
27+
if not s:
28+
return ""
29+
s = s.lower()
30+
# replace any sequence of non-alphanumeric characters with a single hyphen
31+
s = re.sub(r"[^a-z0-9]+", "-", s)
32+
s = s.strip("-")
33+
return s

explorer/requirements/dev-requirements.txt

Lines changed: 0 additions & 34 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
-c requirements.in
22
flake8
33
black
4-
isort
4+
isort
5+
pytest

requirements/dev-requirements.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.10
3+
# by the following command:
4+
#
5+
# pip-compile requirements/dev-requirements.in
6+
#
7+
black==25.1.0
8+
# via -r requirements/dev-requirements.in
9+
click==8.1.8
10+
# via
11+
# -c /Users/colm/code/mhclg/digital-land/planning-application-data-specification/requirements/requirements.in
12+
# black
13+
exceptiongroup==1.3.0
14+
# via pytest
15+
flake8==7.2.0
16+
# via -r requirements/dev-requirements.in
17+
iniconfig==2.1.0
18+
# via pytest
19+
isort==6.0.1
20+
# via -r requirements/dev-requirements.in
21+
mccabe==0.7.0
22+
# via flake8
23+
mypy-extensions==1.1.0
24+
# via black
25+
packaging==25.0
26+
# via
27+
# black
28+
# pytest
29+
pathspec==0.12.1
30+
# via black
31+
platformdirs==4.3.8
32+
# via black
33+
pluggy==1.6.0
34+
# via pytest
35+
pycodestyle==2.13.0
36+
# via flake8
37+
pyflakes==3.3.2
38+
# via flake8
39+
pygments==2.19.2
40+
# via pytest
41+
pytest==8.4.1
42+
# via -r requirements/dev-requirements.in
43+
tomli==2.2.1
44+
# via
45+
# black
46+
# pytest
47+
typing-extensions==4.13.2
48+
# via
49+
# black
50+
# exceptiongroup
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
# This file is autogenerated by pip-compile with Python 3.10
33
# by the following command:
44
#
5-
# pip-compile explorer/requirements/requirements.in
5+
# pip-compile requirements/requirements.in
66
#
77
certifi==2025.6.15
88
# via requests
99
charset-normalizer==3.4.2
1010
# via requests
1111
click==8.1.8
12-
# via -r explorer/requirements/requirements.in
12+
# via -r requirements/requirements.in
1313
idna==3.10
1414
# via requests
1515
python-dotenv==1.1.1
16-
# via -r explorer/requirements/requirements.in
16+
# via -r requirements/requirements.in
1717
python-frontmatter==1.1.0
18-
# via -r explorer/requirements/requirements.in
18+
# via -r requirements/requirements.in
1919
pyyaml==6.0.2
2020
# via python-frontmatter
2121
requests==2.32.4
22-
# via -r explorer/requirements/requirements.in
22+
# via -r requirements/requirements.in
2323
urllib3==2.5.0
2424
# via requests

tests/__init__.py

Whitespace-only changes.

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# tests/conftest.py
2+
import os
3+
import sys
4+
5+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))

tests/test_utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from bin.utils import to_anchor
2+
3+
4+
def test_to_anchor_simple():
5+
assert to_anchor("Site constraint") == "site-constraint"
6+
7+
8+
def test_to_anchor_non_alnum():
9+
assert to_anchor("Site: Constraint / Area") == "site-constraint-area"
10+
11+
12+
def test_to_anchor_trims_hyphens():
13+
assert to_anchor(" --Example!! ") == "example"
14+
15+
16+
def test_to_anchor_empty():
17+
assert to_anchor("") == ""
18+
assert to_anchor(None) == ""

0 commit comments

Comments
 (0)