Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.

9 downloads

dbbasic-object-server/tests/test_docs_no_line_references.py
Install on DigitalOcean Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-object-server.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-object-server.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-object-server.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

Daniel Quellhorst Changelog for this batch. 65ef78d 3 hours, 19 minutes ago History
test_docs_no_line_references.py · 1.4 KB · 34 lines
1"""docs/ and the README never point at code by line number.
2
3`object_records.py:5411` is wrong after the next commit to that file, and
4nothing notices: name the function (`object_records._is_empty`) instead."""
5
6import re
7from pathlib import Path
8
9REPO = Path(__file__).resolve().parents[1]
10LINE_REFERENCE = re.compile(r"[A-Za-z0-9_./-]+\.py:\d+(?:-\d+)?")
11
12
13def line_references(text):
14 return LINE_REFERENCE.findall(text)
15
16
17def test_the_pattern_finds_line_references_and_spares_names():
18 assert line_references("see `object_records.py:5411`, `5546`") == ["object_records.py:5411"]
19 assert line_references("delete (object_records.py:1384-1487)") == ["object_records.py:1384-1487"]
20 assert line_references("tests/test_x.py:12: AssertionError") == ["tests/test_x.py:12"]
21 assert line_references("`object_records._is_empty`, `tests/test_x.py::test_y`, port 8001") == []
22
23
24def test_no_doc_points_at_code_by_line_number():
25 files = sorted((REPO / "docs").glob("*.md")) + [REPO / "README.md"]
26 assert len(files) > 30
27 found = []
28 for path in files:
29 for number, line in enumerate(path.read_text(encoding="utf-8").split("\n"), 1):
30 found += [f"{path.relative_to(REPO)} line {number}: {ref}" for ref in line_references(line)]
31 assert not found, (
32 "Line numbers go stale with the next commit; name the function instead "
33 "(`module.function`):\n" + "\n".join(found)
34 )