@@ -256,3 +256,119 @@ def test_lookup_study(fixture, api):
256256
257257 with pytest .raises (ValueError ):
258258 api .lookup_study ("foobar" )
259+
260+
261+ def _strip_terms_of_use_from_manifest (manifest_path ):
262+ """Rewrite a manifest TSV file without terms-of-use columns."""
263+ df = pd .read_csv (manifest_path , sep = "\t " )
264+ cols_to_drop = [c for c in df .columns if c .startswith ("terms_of_use" )]
265+ df = df .drop (columns = cols_to_drop )
266+ df .to_csv (manifest_path , index = False , sep = "\t " )
267+
268+
269+ def test_lookup_terms_of_use_info_missing_columns (ag3_sim_fixture ):
270+ import shutil
271+
272+ manifest_paths = [
273+ ag3_sim_fixture .bucket_path / "v3" / "manifest.tsv" ,
274+ ag3_sim_fixture .bucket_path / "v3.1" / "manifest.tsv" ,
275+ ]
276+ backups = []
277+ for mp in manifest_paths :
278+ bp = mp .parent / "manifest.tsv.bak"
279+ shutil .copy2 (mp , bp )
280+ backups .append (bp )
281+
282+ try :
283+ for mp in manifest_paths :
284+ _strip_terms_of_use_from_manifest (mp )
285+
286+ api = AnophelesBase (
287+ url = ag3_sim_fixture .url ,
288+ public_url = ag3_sim_fixture .url ,
289+ config_path = _ag3 .CONFIG_PATH ,
290+ major_version_number = _ag3 .MAJOR_VERSION_NUMBER ,
291+ major_version_path = _ag3 .MAJOR_VERSION_PATH ,
292+ pre = True ,
293+ )
294+
295+ sample_set = "1177-VO-ML-LEHMANN-VMF00004"
296+ info = api .lookup_terms_of_use_info (sample_set )
297+ assert isinstance (info , dict )
298+ assert "terms_of_use_expiry_date" in info
299+ assert "terms_of_use_url" in info
300+ assert "unrestricted_use" in info
301+ assert info ["terms_of_use_expiry_date" ] == "2099-12-31"
302+ assert pd .isna (info ["terms_of_use_url" ])
303+ assert info ["unrestricted_use" ] is False
304+ finally :
305+ for mp , bp in zip (manifest_paths , backups ):
306+ shutil .move (bp , mp )
307+
308+
309+ def test_sample_set_has_unrestricted_use_missing_column (ag3_sim_fixture ):
310+ import shutil
311+
312+ manifest_paths = [
313+ ag3_sim_fixture .bucket_path / "v3" / "manifest.tsv" ,
314+ ag3_sim_fixture .bucket_path / "v3.1" / "manifest.tsv" ,
315+ ]
316+ backups = []
317+ for mp in manifest_paths :
318+ bp = mp .parent / "manifest.tsv.bak"
319+ shutil .copy2 (mp , bp )
320+ backups .append (bp )
321+
322+ try :
323+ for mp in manifest_paths :
324+ _strip_terms_of_use_from_manifest (mp )
325+
326+ api = AnophelesBase (
327+ url = ag3_sim_fixture .url ,
328+ public_url = ag3_sim_fixture .url ,
329+ config_path = _ag3 .CONFIG_PATH ,
330+ major_version_number = _ag3 .MAJOR_VERSION_NUMBER ,
331+ major_version_path = _ag3 .MAJOR_VERSION_PATH ,
332+ pre = True ,
333+ )
334+
335+ sample_set = "1177-VO-ML-LEHMANN-VMF00004"
336+ result = api ._sample_set_has_unrestricted_use (sample_set = sample_set )
337+ assert result is False
338+ finally :
339+ for mp , bp in zip (manifest_paths , backups ):
340+ shutil .move (bp , mp )
341+
342+
343+ def test_sample_sets_no_terms_of_use (ag3_sim_fixture ):
344+ import shutil
345+
346+ manifest_paths = [
347+ ag3_sim_fixture .bucket_path / "v3" / "manifest.tsv" ,
348+ ag3_sim_fixture .bucket_path / "v3.1" / "manifest.tsv" ,
349+ ]
350+ backups = []
351+ for mp in manifest_paths :
352+ bp = mp .parent / "manifest.tsv.bak"
353+ shutil .copy2 (mp , bp )
354+ backups .append (bp )
355+
356+ try :
357+ for mp in manifest_paths :
358+ _strip_terms_of_use_from_manifest (mp )
359+
360+ api = AnophelesBase (
361+ url = ag3_sim_fixture .url ,
362+ public_url = ag3_sim_fixture .url ,
363+ config_path = _ag3 .CONFIG_PATH ,
364+ major_version_number = _ag3 .MAJOR_VERSION_NUMBER ,
365+ major_version_path = _ag3 .MAJOR_VERSION_PATH ,
366+ pre = True ,
367+ )
368+
369+ df = api .sample_sets (release = "3.1" )
370+ assert isinstance (df , pd .DataFrame )
371+ assert len (df ) > 0
372+ finally :
373+ for mp , bp in zip (manifest_paths , backups ):
374+ shutil .move (bp , mp )
0 commit comments