Add the schema for the place registry and the record's place fields
This commit is contained in:
1 parent
fe2306d90b
commit
aad93a246c
5 files changed
+107
-5
No files matched your search
@@ -0,0 +1,56 @@
|
||||
"""Tests for the place schema: the record's [[place]] table, places_checked and
|
||||
places_track, and their place in the history rules (tools/trail_history.py, docs/schema.md).
|
||||
|
||||
Run from the repository root:
|
||||
python3 -m unittest discover tools/tests -p "test_places_schema.py"
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.dont_write_bytecode = True
|
||||
TOOLS = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
ROOT = os.path.dirname(TOOLS)
|
||||
sys.path.insert(0, TOOLS)
|
||||
|
||||
import trail_history as H # noqa: E402
|
||||
|
||||
|
||||
class PlaceSchemaTest(unittest.TestCase):
|
||||
def test_place_fields_are_schema_fields(self):
|
||||
self.assertIn("place", H.SCHEMA_FIELDS)
|
||||
self.assertIn("place.km", H.SCHEMA_FIELDS)
|
||||
self.assertIn("places_checked", H.SCHEMA_FIELDS)
|
||||
self.assertIn("places_track", H.SCHEMA_FIELDS)
|
||||
|
||||
def test_km_and_stamps_are_not_facts(self):
|
||||
self.assertFalse(H.is_fact("place.km"))
|
||||
self.assertFalse(H.is_fact("places_checked"))
|
||||
self.assertFalse(H.is_fact("places_track"))
|
||||
self.assertTrue(H.is_fact("place.slug"))
|
||||
self.assertTrue(H.is_fact("place.basis"))
|
||||
self.assertTrue(H.is_fact("place.kind"))
|
||||
self.assertTrue(H.is_fact("place.source"))
|
||||
|
||||
def test_a_km_only_change_needs_no_history(self):
|
||||
old = {"id": "x", "place": [{"kind": "range", "slug": "a", "basis": "track", "km": 10.0}]}
|
||||
new = {"id": "x", "place": [{"kind": "range", "slug": "a", "basis": "track", "km": 11.5}]}
|
||||
changed = H.changed_paths(old, new)
|
||||
self.assertEqual(changed, ["place.km"])
|
||||
self.assertEqual([p for p in changed if H.is_fact(p)], [])
|
||||
|
||||
def test_schema_documents_every_place_field(self):
|
||||
with open(os.path.join(ROOT, "docs", "schema.md"), encoding="utf-8") as f:
|
||||
text = f.read()
|
||||
for name in H._TABLES["place"]:
|
||||
self.assertIn(f"`{name}`", text, name)
|
||||
for name in ("places_checked", "places_track"):
|
||||
self.assertIn(f"`{name}`", text, name)
|
||||
|
||||
def test_facts_text_names_place(self):
|
||||
self.assertIn("place", H.FACTS_TEXT)
|
||||
self.assertIn("place.km", H.NOT_FACTS_TEXT)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -19,7 +19,7 @@ URL_RE = re.compile(r"^https?://[^\s/]+\S*$")
|
||||
# names these. A table name on its own ("source", "hike.source") names every field in it.
|
||||
_TABLES = {
|
||||
"": ("id", "name", "common_name", "short_name", "short_name_url", "country", "regions", "length_km",
|
||||
"length_note", "system_km", "system_note", "built_km", "kind", "tier", "designation", "wave", "wave_note", "inclusion", "short_reason"),
|
||||
"length_note", "system_km", "system_note", "built_km", "kind", "tier", "designation", "wave", "wave_note", "inclusion", "short_reason", "places_checked", "places_track"),
|
||||
"source": ("status", "publisher", "publisher_url", "url", "discovery", "format", "crs",
|
||||
"licence", "licence_text", "permission_quote", "permission_by",
|
||||
"permission_date", "permission_url", "attribution", "osm_only", "mainline",
|
||||
@@ -37,6 +37,7 @@ _TABLES = {
|
||||
"guide": ("title", "author", "access", "url", "format", "price", "price_checked",
|
||||
"publisher", "isbn"),
|
||||
"link": ("title", "publisher", "url", "note"),
|
||||
"place": ("kind", "slug", "basis", "km", "source"),
|
||||
}
|
||||
SCHEMA_FIELDS = set()
|
||||
for _table, _names in _TABLES.items():
|
||||
@@ -60,6 +61,8 @@ NOT_FACTS = (
|
||||
"guide.price", "guide.price_checked", # a price read on a date, and refreshed
|
||||
"osm.note", "shield.note", "route.note", "link", # notes and other pages about the trail
|
||||
"wave", "wave_note", # the dataset's own bookkeeping
|
||||
"places_checked", "places_track", # when the places were last measured, and of which track
|
||||
"place.km", # a measurement of the track inside a place, refreshed by the tool
|
||||
)
|
||||
FACTS_TEXT = (
|
||||
"name, common_name, short_name, short_name_url, country, regions, length_km, length_note, system_km, system_note, built_km, kind, tier, "
|
||||
@@ -68,12 +71,14 @@ FACTS_TEXT = (
|
||||
"decision, decision_text, redistributable); osm.relation; shield.* except note; "
|
||||
"hike.* except summary, checked and source (start, end, official_url, days, season, terrain, "
|
||||
"travel, high_point, permit, unfinished, caution and the rest); route.* except note; "
|
||||
"guide.* except price. A replaced track file counts as a change to source.line_file."
|
||||
"guide.* except price; place.* except km (kind, slug, basis, source). "
|
||||
"A replaced track file counts as a change to source.line_file."
|
||||
)
|
||||
NOT_FACTS_TEXT = (
|
||||
"history; verification.*; source.source_checked, discovery, format, crs, mainline, "
|
||||
"length_gap_note; hike.summary, hike.checked, hike.source; guide.price, "
|
||||
"guide.price_checked; osm.note, shield.note, route.note; link; wave, wave_note."
|
||||
"guide.price_checked; osm.note, shield.note, route.note; link; wave, wave_note; "
|
||||
"places_checked, places_track, place.km."
|
||||
)
|
||||
TRACK_FIELD = "source.line_file"
|
||||
|
||||
|
||||
Reference in new issue
Block a user