Skip to content

Commit

Permalink
adding more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kelle committed Jul 24, 2024
1 parent 570f0e3 commit f9d441a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
18 changes: 13 additions & 5 deletions simple/utils/spectral_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
26 changes: 25 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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,
Expand All @@ -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):
Expand Down

0 comments on commit f9d441a

Please sign in to comment.