@@ -37,19 +37,34 @@ def _build_jurisdiction(full_name="Example Township", code="12345"):
3737@pytest .mark .parametrize ("is_relative" , [True , False ])
3838@pytest .mark .parametrize ("has_wildcard" , [True , False ])
3939@pytest .mark .parametrize ("is_list" , [True , False ])
40+ # ruff:ignore[complex-structure]
4041async def test_load_collection_manifest_jurisdictions_path_variants (
4142 tmp_path , monkeypatch , input_type , is_relative , has_wildcard , is_list
4243):
43- """Manifest paths should support strings, Paths, globs, and lists """
44+ """Manifest inputs and persisted document paths should resolve """
4445 manifest_dir = tmp_path / "manifests"
4546 manifest_fps = [
4647 manifest_dir / "first" / "manifest_first.json" ,
4748 manifest_dir / "second" / "manifest_second.json" ,
4849 ]
4950 expected_jurisdictions = []
5051 for index , manifest_fp in enumerate (manifest_fps , start = 1 ):
51- jurisdiction = {"FIPS" : f"{ index :03d} " }
52- expected_jurisdictions .append (jurisdiction )
52+ document_paths = {
53+ "dot" : "./documents/source.html" ,
54+ "parent" : "../shared/source.html" ,
55+ "normalized" : "./documents/../normalized/source.html" ,
56+ "windows_dot" : r".\documents\source.html" ,
57+ "windows_parent" : r"..\shared\source.html" ,
58+ }
59+ documents = [
60+ {
61+ "path_case" : path_case ,
62+ "source_fp" : source_fp ,
63+ "parsed_fp" : source_fp .replace ("source.html" , "parsed.txt" ),
64+ }
65+ for path_case , source_fp in document_paths .items ()
66+ ]
67+ jurisdiction = {"FIPS" : f"{ index :03d} " , "documents" : documents }
5368 manifest_fp .parent .mkdir (parents = True )
5469 manifest_fp .write_text (
5570 json .dumps (
@@ -60,6 +75,29 @@ async def test_load_collection_manifest_jurisdictions_path_variants(
6075 ),
6176 encoding = "utf-8" ,
6277 )
78+ expected_jurisdictions .append (
79+ {
80+ "FIPS" : f"{ index :03d} " ,
81+ "documents" : [
82+ {
83+ "path_case" : doc_info ["path_case" ],
84+ "source_fp" : str (
85+ (
86+ manifest_fp .parent
87+ / doc_info ["source_fp" ].replace ("\\ " , "/" )
88+ ).resolve ()
89+ ),
90+ "parsed_fp" : str (
91+ (
92+ manifest_fp .parent
93+ / doc_info ["parsed_fp" ].replace ("\\ " , "/" )
94+ ).resolve ()
95+ ),
96+ }
97+ for doc_info in documents
98+ ],
99+ }
100+ )
63101
64102 manifest_inputs = []
65103 for manifest_fp in manifest_fps :
@@ -91,6 +129,69 @@ async def test_load_collection_manifest_jurisdictions_path_variants(
91129 assert sorted (jurisdictions , key = itemgetter ("FIPS" )) == (
92130 expected_jurisdictions
93131 )
132+ for index , jurisdiction in enumerate (
133+ sorted (jurisdictions , key = itemgetter ("FIPS" ))
134+ ):
135+ manifest_fp = manifest_fps [index ]
136+ for doc_info in jurisdiction ["documents" ]:
137+ for key in ("source_fp" , "parsed_fp" ):
138+ assert Path (doc_info [key ]).is_absolute ()
139+ expected_path = document_paths [doc_info ["path_case" ]]
140+ if key == "parsed_fp" :
141+ expected_path = expected_path .replace (
142+ "source.html" , "parsed.txt"
143+ )
144+ expected_path = expected_path .replace ("\\ " , "/" )
145+ assert doc_info [key ] == str (
146+ (manifest_fp .parent / expected_path ).resolve ()
147+ )
148+
149+
150+ @pytest .mark .asyncio
151+ async def test_load_collection_manifest_jurisdictions_resolves_shard_paths (
152+ tmp_path ,
153+ ):
154+ """Shard-recovered document paths should resolve from manifest root"""
155+ manifest_dir = tmp_path / "collection"
156+ shard_dir = manifest_dir / "shards"
157+ shard_dir .mkdir (parents = True )
158+ collection_info = {
159+ "FIPS" : "12345" ,
160+ "full_name" : "Example Township" ,
161+ "documents" : [
162+ {
163+ "source_fp" : "./downloaded/source.html" ,
164+ "parsed_fp" : "./parsed/source.txt" ,
165+ }
166+ ],
167+ }
168+ shard_fp = (
169+ shard_dir
170+ / persistence_module ._collection_manifest_shard_filename (
171+ collection_info
172+ )
173+ )
174+ shard_fp .write_text (json .dumps (collection_info ), encoding = "utf-8" )
175+
176+ manifest_fp = (
177+ manifest_dir / persistence_module .COLLECTION_MANIFEST_FILENAME
178+ )
179+ async with RunningAsyncServices ([GenericFuncRunner ()]):
180+ jurisdictions = (
181+ await persistence_module .load_collection_manifest_jurisdictions (
182+ manifest_fp , "solar"
183+ )
184+ )
185+
186+ document = jurisdictions [0 ]["documents" ][0 ]
187+ assert document ["source_fp" ] == str (
188+ (manifest_dir / "downloaded/source.html" ).resolve ()
189+ )
190+ assert document ["parsed_fp" ] == str (
191+ (manifest_dir / "parsed/source.txt" ).resolve ()
192+ )
193+ assert Path (document ["source_fp" ]).is_absolute ()
194+ assert Path (document ["parsed_fp" ]).is_absolute ()
94195
95196
96197@pytest .mark .asyncio
0 commit comments