From e39a051c38430990b3d6d8f9a2442beef36764fc Mon Sep 17 00:00:00 2001 From: Melissa DeLucchi <113376043+delucchi-cmu@users.noreply.github.com> Date: Mon, 6 Jan 2025 13:57:43 -0500 Subject: [PATCH] Check for existing valid catalog (#52) --- tests/hats_import/test_create_margin.py | 14 ++++++++++++++ tests/hats_import/test_run_catalog_import.py | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/tests/hats_import/test_create_margin.py b/tests/hats_import/test_create_margin.py index 7809eb2..6dcdc57 100644 --- a/tests/hats_import/test_create_margin.py +++ b/tests/hats_import/test_create_margin.py @@ -1,4 +1,5 @@ import hats_import.margin_cache.margin_cache as mc +import pytest from hats import read_hats from hats_import.margin_cache.margin_cache_arguments import MarginCacheArguments @@ -64,3 +65,16 @@ def test_margin_cache_gen_read_from_cloud( catalog = read_hats(args.catalog_path) assert catalog.on_disk assert catalog.catalog_path == args.catalog_path + + +def test_no_margin_cache_overwrite(small_sky_order1_dir_cloud): + """Runner should refuse to generate margin cache which overwrites valid catalog""" + catalog_dir = small_sky_order1_dir_cloud.parent + catalog_name = small_sky_order1_dir_cloud.name + with pytest.raises(ValueError, match="already contains a valid catalog"): + MarginCacheArguments( + input_catalog_path=small_sky_order1_dir_cloud, + output_path=catalog_dir, + margin_threshold=10.0, + output_artifact_name=catalog_name, + ) diff --git a/tests/hats_import/test_run_catalog_import.py b/tests/hats_import/test_run_catalog_import.py index 205cc38..db30dd3 100644 --- a/tests/hats_import/test_run_catalog_import.py +++ b/tests/hats_import/test_run_catalog_import.py @@ -85,3 +85,16 @@ def test_read_csv_cloud(small_sky_parts_dir_cloud): assert len(frame) == 25 assert total_chunks == 1 + + +def test_no_import_overwrite(small_sky_order1_dir_cloud, small_sky_parts_dir_local): + """Runner should refuse to overwrite a valid catalog""" + catalog_dir = small_sky_order1_dir_cloud.parent + catalog_name = small_sky_order1_dir_cloud.name + with pytest.raises(ValueError, match="already contains a valid catalog"): + ImportArguments( + input_path=small_sky_parts_dir_local, + output_path=catalog_dir, + output_artifact_name=catalog_name, + file_reader="parquet", + )