forked from OurHike/OurHike
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_poi_schema.py
More file actions
127 lines (101 loc) · 4.86 KB
/
Copy pathtest_poi_schema.py
File metadata and controls
127 lines (101 loc) · 4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
"""Tests for lib/poi_schema.py - the unified POI schema (ROADMAP.md's
"Unified POI schema" line) that export_poi.py maps every source (ATC
shelters/campsites/communities, opentrail.org water/resupply tags) into.
Pure-function tests only, per TESTING.md - no I/O, no DuckDB, no network.
export_poi.py's own tests cover the corridor-clip/export/manifest wiring
this schema plugs into.
"""
import copy
import pytest
from lib.poi_schema import CONFIDENCE_HIGH, CONFIDENCE_LOW, CONFIDENCE_RANK, unify_poi
SHELTER_FEATURE = {
"type": "Feature",
"id": 1,
"geometry": {"type": "Point", "coordinates": [-69.2624152728137, 45.4531807456927]},
"properties": {
"GlobalID": "11111111-1111-1111-1111-111111111111",
"OBJECTID": 1,
"Name": "Chairback Gap Lean-to Shelter",
},
}
SHELTER_FIELD_MAP = {"id_field": "GlobalID", "name_field": "Name", "confidence": CONFIDENCE_HIGH}
def _community_feature():
return {
"type": "Feature",
"id": 1,
"geometry": {"type": "Point", "coordinates": [-82.4168092597345, 36.1451152009164]},
"properties": {
"GlobalID": "1dd87b3c-56b4-46a9-994f-5634049e509e",
"FID": 1,
"NAME": "Unicoi County",
},
}
def _opentrail_resupply_feature():
return {
"type": "Feature",
"id": 0,
"geometry": {"type": "Point", "coordinates": [-84.0, 34.5]},
"properties": {"title": "Neels Gap Outfitter", "icon": "r", "dbid": 1237},
}
def test_unify_poi_id_is_stable_across_repeated_runs_on_identical_input():
"""A future Report/Closure references a POI by id - it must never drift
on a re-run of the pipeline against unchanged source data, so it can't
be a randomly regenerated UUID."""
feature = copy.deepcopy(SHELTER_FEATURE)
first = unify_poi(feature, "shelter", "atc_shelters", "AT", SHELTER_FIELD_MAP)
second = unify_poi(copy.deepcopy(feature), "shelter", "atc_shelters", "AT", SHELTER_FIELD_MAP)
assert first["id"] == second["id"]
assert first["id"] == "atc_shelters:11111111-1111-1111-1111-111111111111"
def test_unify_poi_does_not_hardcode_a_trail_id():
"""trail_id must come from the caller/field_map, never baked into the
function as "AT" - this project starts AT-only but the schema itself
has to be inheritable to a future trail/club (value #7)."""
feature = copy.deepcopy(SHELTER_FEATURE)
at_result = unify_poi(feature, "shelter", "atc_shelters", "AT", SHELTER_FIELD_MAP)
lt_result = unify_poi(feature, "shelter", "atc_shelters", "LT", SHELTER_FIELD_MAP)
assert at_result["trail_id"] == "AT"
assert lt_result["trail_id"] == "LT"
# Only trail_id should differ between the two calls - everything else is
# derived from the feature/source, not the trail.
assert at_result["id"] == lt_result["id"]
assert at_result["poi_type"] == lt_result["poi_type"]
def test_unify_poi_marks_atc_communities_as_a_lower_confidence_resupply_proxy():
"""A town being an "official A.T. Community" isn't the same confidence
as opentrail.org's actual resupply-point tagging - both feed poi_type
"resupply", but the schema must be able to tell them apart."""
community_result = unify_poi(
_community_feature(),
"resupply",
"atc_communities",
"AT",
{"id_field": "GlobalID", "name_field": "NAME", "confidence": CONFIDENCE_LOW},
)
opentrail_result = unify_poi(
_opentrail_resupply_feature(),
"resupply",
"opentrail_at",
"AT",
{"id_field": "dbid", "name_field": "title", "confidence": CONFIDENCE_HIGH},
)
assert community_result["poi_type"] == opentrail_result["poi_type"] == "resupply"
assert community_result["confidence"] == CONFIDENCE_LOW
assert opentrail_result["confidence"] == CONFIDENCE_HIGH
assert CONFIDENCE_RANK[community_result["confidence"]] < CONFIDENCE_RANK[opentrail_result["confidence"]]
def test_unify_poi_raises_on_missing_source_feature_id():
"""A misconfigured field_map (id_field pointing at a property the source
doesn't actually have) must fail loudly, not silently produce ids like
"source:None" that collide across every feature from that source. No
top-level "id" fallback either, unlike the other tests here - this
proves the failure isn't masked by that fallback."""
feature = {
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [-69.0, 45.0]},
"properties": {"Name": "No id field here"},
}
bad_field_map = {"id_field": "NotARealField", "confidence": CONFIDENCE_HIGH}
with pytest.raises(ValueError):
unify_poi(feature, "shelter", "atc_shelters", "AT", bad_field_map)
def test_unify_poi_rejects_an_unknown_poi_type():
feature = copy.deepcopy(SHELTER_FEATURE)
with pytest.raises(ValueError):
unify_poi(feature, "not_a_real_poi_type", "atc_shelters", "AT", SHELTER_FIELD_MAP)