Skip to content

Commit

Permalink
add dask pytest mark + black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwest-uw committed Oct 30, 2023
1 parent b95de6d commit 49c9310
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 72 deletions.
45 changes: 23 additions & 22 deletions src/hipscat_import/cross_match/macauff_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
@dataclass
class MacauffArguments(RuntimeArguments):
"""Data class for holding cross-match association arguments"""

## Input - Cross-match data
input_path: FilePointer | None = None
"""path to search for the input data"""
Expand Down Expand Up @@ -102,26 +103,26 @@ def get_column_names(self):
# TODO: Actually read in the metadata file once we get the example file from Tom.

return [
'Gaia_designation',
'Gaia_RA',
'Gaia_Dec',
'BP',
'G',
'RP',
'CatWISE_Name',
'CatWISE_RA',
'CatWISE_Dec',
'W1',
'W2',
'match_p',
'Separation',
'eta',
'xi',
'Gaia_avg_cont',
'CatWISE_avg_cont',
'Gaia_cont_f1',
'Gaia_cont_f10',
'CatWISE_cont_f1',
'CatWISE_cont_f10',
'CatWISE_fit_sig',
"Gaia_designation",
"Gaia_RA",
"Gaia_Dec",
"BP",
"G",
"RP",
"CatWISE_Name",
"CatWISE_RA",
"CatWISE_Dec",
"W1",
"W2",
"match_p",
"Separation",
"eta",
"xi",
"Gaia_avg_cont",
"CatWISE_avg_cont",
"Gaia_cont_f1",
"Gaia_cont_f10",
"CatWISE_cont_f1",
"CatWISE_cont_f10",
"CatWISE_fit_sig",
]
1 change: 1 addition & 0 deletions src/hipscat_import/cross_match/run_macauff_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# pylint: disable=unused-argument


def run(args, client):
"""run macauff cross-match import pipeline"""
if not args:
Expand Down
1 change: 1 addition & 0 deletions tests/hipscat_import/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def formats_pandasindex(test_data_dir):
def formats_multiindex(test_data_dir):
return os.path.join(test_data_dir, "test_formats", "multiindex.parquet")


@pytest.fixture
def formats_yaml(test_data_dir):
return os.path.join(test_data_dir, "test_formats", "macauff_metadata.yaml")
Expand Down
62 changes: 18 additions & 44 deletions tests/hipscat_import/cross_match/test_macauff_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@


def test_macauff_arguments(
small_sky_object_catalog,
small_sky_source_catalog,
small_sky_dir,
formats_yaml,
tmp_path
small_sky_object_catalog, small_sky_source_catalog, small_sky_dir, formats_yaml, tmp_path
):
"""Test that we can create a MacauffArguments instance with two valid catalogs."""
args = MacauffArguments(
Expand All @@ -37,12 +33,9 @@ def test_macauff_arguments(

assert len(args.input_paths) > 0


def test_empty_required(
small_sky_object_catalog,
small_sky_source_catalog,
small_sky_dir,
formats_yaml,
tmp_path
small_sky_object_catalog, small_sky_source_catalog, small_sky_dir, formats_yaml, tmp_path
):
"""All non-runtime arguments are required."""

Expand All @@ -62,7 +55,7 @@ def test_empty_required(
["right_id_column", "source_id"],
["input_path", small_sky_dir],
["input_format", "csv"],
["metadata_file_path", formats_yaml]
["metadata_file_path", formats_yaml],
]

## For each required argument, check that a ValueError is raised that matches the
Expand Down Expand Up @@ -96,11 +89,7 @@ def test_empty_required(


def test_macauff_arguments_file_list(
small_sky_object_catalog,
small_sky_source_catalog,
small_sky_dir,
formats_yaml,
tmp_path
small_sky_object_catalog, small_sky_source_catalog, small_sky_dir, formats_yaml, tmp_path
):
"""Test that we can create a MacauffArguments instance with two valid catalogs."""
files = [path.join(small_sky_dir, "catalog.csv")]
Expand All @@ -123,18 +112,14 @@ def test_macauff_arguments_file_list(

assert len(args.input_paths) > 0

def test_macauff_args_invalid_catalog(
small_sky_source_catalog,
small_sky_dir,
formats_yaml,
tmp_path
):

def test_macauff_args_invalid_catalog(small_sky_source_catalog, small_sky_dir, formats_yaml, tmp_path):
with pytest.raises(ValueError, match="left_catalog_dir"):
MacauffArguments(
output_path=tmp_path,
output_catalog_name="object_to_source",
tmp_dir=tmp_path,
left_catalog_dir=small_sky_dir, # valid path, but not a catalog
left_catalog_dir=small_sky_dir, # valid path, but not a catalog
left_ra_column="ra",
left_dec_column="dec",
left_id_column="id",
Expand All @@ -147,12 +132,8 @@ def test_macauff_args_invalid_catalog(
metadata_file_path=formats_yaml,
)

def test_macauff_args_right_invalid_catalog(
small_sky_object_catalog,
small_sky_dir,
formats_yaml,
tmp_path
):

def test_macauff_args_right_invalid_catalog(small_sky_object_catalog, small_sky_dir, formats_yaml, tmp_path):
with pytest.raises(ValueError, match="right_catalog_dir"):
MacauffArguments(
output_path=tmp_path,
Expand All @@ -162,7 +143,7 @@ def test_macauff_args_right_invalid_catalog(
left_ra_column="ra",
left_dec_column="dec",
left_id_column="id",
right_catalog_dir=small_sky_dir, # valid directory with files, not a catalog
right_catalog_dir=small_sky_dir, # valid directory with files, not a catalog
right_ra_column="source_ra",
right_dec_column="source_dec",
right_id_column="source_id",
Expand All @@ -171,11 +152,9 @@ def test_macauff_args_right_invalid_catalog(
metadata_file_path=formats_yaml,
)


def test_macauff_args_invalid_metadata_file(
small_sky_object_catalog,
small_sky_source_catalog,
small_sky_dir,
tmp_path
small_sky_object_catalog, small_sky_source_catalog, small_sky_dir, tmp_path
):
with pytest.raises(ValueError, match="column metadata file must"):
MacauffArguments(
Expand All @@ -195,11 +174,9 @@ def test_macauff_args_invalid_metadata_file(
metadata_file_path="ceci_n_est_pas_un_fichier.xml",
)


def test_macauff_args_invalid_input_directory(
small_sky_object_catalog,
small_sky_source_catalog,
formats_yaml,
tmp_path
small_sky_object_catalog, small_sky_source_catalog, formats_yaml, tmp_path
):
with pytest.raises(FileNotFoundError, match="input_path not found"):
MacauffArguments(
Expand All @@ -219,12 +196,9 @@ def test_macauff_args_invalid_input_directory(
metadata_file_path=formats_yaml,
)


def test_macauff_args_no_files(
small_sky_object_catalog,
small_sky_source_catalog,
small_sky_dir,
formats_yaml,
tmp_path
small_sky_object_catalog, small_sky_source_catalog, small_sky_dir, formats_yaml, tmp_path
):
with pytest.raises(FileNotFoundError, match="No input files found"):
MacauffArguments(
Expand All @@ -240,6 +214,6 @@ def test_macauff_args_no_files(
right_dec_column="source_dec",
right_id_column="source_id",
input_path=small_sky_dir,
input_format="parquet", # no files of this format will be found
input_format="parquet", # no files of this format will be found
metadata_file_path=formats_yaml,
)
15 changes: 9 additions & 6 deletions tests/hipscat_import/cross_match/test_macauff_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# pylint: disable=too-many-instance-attributes
# pylint: disable=duplicate-code


@pytest.mark.dask
def test_bad_args(dask_client):
"""Runner should fail with empty or mis-typed arguments"""
with pytest.raises(TypeError, match="MacauffArguments"):
Expand All @@ -16,13 +18,14 @@ def test_bad_args(dask_client):
runner.run(args, dask_client)


@pytest.mark.dask
def test_no_implementation(
small_sky_object_catalog,
small_sky_source_catalog,
small_sky_dir,
formats_yaml,
tmp_path,
dask_client,
small_sky_object_catalog,
small_sky_source_catalog,
small_sky_dir,
formats_yaml,
tmp_path,
dask_client,
):
"""Test that we can create a MacauffArguments instance with two valid catalogs."""
args = MacauffArguments(
Expand Down

0 comments on commit 49c9310

Please sign in to comment.