From f9d441a9600fb7d55b39dd0623bdddbb3c971cc9 Mon Sep 17 00:00:00 2001 From: kelle Date: Wed, 24 Jul 2024 11:58:57 -0400 Subject: [PATCH] adding more tests --- simple/utils/spectral_types.py | 18 +++++++++++++----- tests/test_utils.py | 26 +++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/simple/utils/spectral_types.py b/simple/utils/spectral_types.py index 4dc69e2a3..33bbe5881 100644 --- a/simple/utils/spectral_types.py +++ b/simple/utils/spectral_types.py @@ -13,7 +13,7 @@ __all__ = [ "ingest_spectral_type", "convert_spt_string_to_code", - "convert_spt_code_to_string_to_code", + "convert_spt_code_to_string", ] logger = logging.getLogger("SIMPLE") @@ -35,22 +35,30 @@ def ingest_spectral_type( ): """ Script to ingest spectral types + Parameters ---------- db: astrodbkit2.astrodb.Database Database object created by astrodbkit2 + source: str - Name of source - spectral_type: str + Name of source. Constrained by the Sources table + + spectral_type_string: str Spectral Type of source + spectral_type_error: str, optional Spectral Type Error of source + regime: str - String + String. Constrained by Regimes table + comment: str, optional Comments + reference: str Reference of the Spectral Type + raise_error: bool, optional Returns @@ -196,7 +204,7 @@ def ingest_spectral_type( logger.error(msg) raise AstroDBError(msg + msg1) else: - logger.warning(msg) + logger.warning(msg + msg1) else: msg = f"Spectral type ingest failed with error {e}\n" if raise_error: diff --git a/tests/test_utils.py b/tests/test_utils.py index bb57a6dba..e4f9cff1b 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -117,6 +117,11 @@ def test_ingest_spectral_type(temp_db): assert results["spectral_type_code"][0] == [92] +def test_ingest_spectral_type_adopted(temp_db): + # TODO: write test for adopted spectral type + pass + + def test_ingest_spectral_type_errors(temp_db): # testing for publication error spt_data4 = { @@ -138,6 +143,16 @@ def test_ingest_spectral_type_errors(temp_db): # "reference": "Ref 4", # } + with pytest.raises(AstroDBError) as error_message: + ingest_spectral_type( + temp_db, + source="not a source", + spectral_type_string=spt_data4["spectral_type"], + reference=spt_data4["reference"], + regime=spt_data4["regime"], + ) + assert "No unique source match" in str(error_message.value) + with pytest.raises(AstroDBError) as error_message: ingest_spectral_type( temp_db, @@ -147,7 +162,16 @@ def test_ingest_spectral_type_errors(temp_db): regime=spt_data4["regime"], ) assert "Spectral type already in the database" in str(error_message.value) - # assert "The publication does not exist in the database" in str(error_message.value) + + with pytest.raises(AstroDBError) as error_message: + ingest_spectral_type( + temp_db, + spt_data4["source"], + spectral_type_string="M6", + reference="not a reference", + regime=spt_data4["regime"], + ) + assert "The publication does not exist in the database" in str(error_message.value) def test_companion_relationships(temp_db):