Skip to content

Commit

Permalink
improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Exu-112 committed Jul 8, 2024
1 parent 83443d7 commit d144f61
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 10 deletions.
12 changes: 4 additions & 8 deletions scripts/ingests/ultracool_sheet/Ingest_Parallax.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from simple.schema import Photometry
from simple.schema import REFERENCE_TABLES
from math import isnan
import sqlalchemy.exc
from simple.utils.astrometry import ingest_parallax
from scripts.ingests.ultracool_sheet.references import uc_ref_to_simple_ref

Expand Down Expand Up @@ -79,10 +78,7 @@

try:
references = source["ref_plx_lit"].split(";")
if references[0] == "Harr15": # weird reference in UC sheet.
reference = "Harr15"
else:
reference = uc_ref_to_simple_ref(db, references[0])
reference = uc_ref_to_simple_ref(db, references[0])

comment = None
if len(references) > 1:
Expand Down Expand Up @@ -115,16 +111,16 @@


# 1108 data points in UC sheet in total
logger.info(f"ingested:{ingested}") # 1013 ingested
logger.info(f"ingested:{ingested}") # 1014 ingested
logger.info(f"already exists:{already_exists}") # skipped 6 due to preexisting data
logger.info(f"no sources:{no_sources}") # skipped 86 due to 0 matches
logger.info(f"multiple sources:{multiple_sources}") # skipped 2 due to multiple matches
logger.info(f"no data: {no_data}")
logger.info(f"no data: {no_data}") # 2782
logger.info(
f"data points tracked:{ingested+already_exists+no_sources+multiple_sources}"
) # 1108
total = ingested + already_exists + no_sources + multiple_sources + no_data
logger.info(f"total: {total}")
logger.info(f"total: {total}") # 3890

if total != len(uc_sheet_table):
msg = "data points tracked inconsistent with UC sheet"
Expand Down
13 changes: 11 additions & 2 deletions simple/utils/astrometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,21 @@ def ingest_parallax(
comment: str
comments
raise_error: bool
raise error if there is an error during ingest
True: raises error when encountered
False: does not raise error, returns flags dictionary
Returns
-------
flags: dict
'added' : bool - true if properly ingested
'content' : dict - content attempted to ingest
'message' : str - error message
"""
# Search for existing parallax data and determine if this is the best
# If no previous measurement exists, set the new one to the Adopted measurement
flags = {"added": False, "content": {}, "message": ""}
adopted = None
adopted = False
source_plx_data: Table = (
db.query(db.Parallaxes).filter(db.Parallaxes.c.source == source).table()
)
Expand Down Expand Up @@ -142,6 +150,7 @@ def ingest_parallax(
flags["added"] = True
return flags
except sqlalchemy.exc.IntegrityError as error_msg:
flags["added"] = False
msg = ""
matching_sources = (
db.query(db.Sources).filter(db.Sources.c.source == source).astropy()
Expand Down
37 changes: 37 additions & 0 deletions tests/test_astrometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,54 @@ def test_parallax_exceptions(temp_db):
ingest_parallax(temp_db, "bad source", 1, 1, "Ref 1")
assert "does not exist in Sources table" in str(error_message.value)

flags = ingest_parallax(temp_db, "bad source", 1, 1, "Ref 1", "comment", False)
assert flags == {
"added": False,
"content": {
"source": "bad source",
"parallax": 1,
"parallax_error": 1,
"reference": "Ref 1",
"adopted": True,
"comments": "comment",
},
"message": "Source 'bad source' does not exist in Sources table. ",
}

with pytest.raises(AstroDBError) as error_message:
ingest_parallax(temp_db, "Fake 1", 1, 1, "bad ref")
assert "does not exist in Publications table" in str(error_message.value)

flags = ingest_parallax(temp_db, "Fake 1", 1, 1, "bad ref", "comment", False)
print(flags)
assert flags == {
"added": False,
"content": {
"source": "Fake 1",
"parallax": 1,
"parallax_error": 1,
"reference": "bad ref",
"adopted": False,
"comments": "comment",
},
"message": "Reference 'bad ref' does not exist in Publications table. ",
}

ingest_parallax(temp_db, "Fake 2", 1, 1, "Ref 2")
with pytest.raises(AstroDBError) as error_message:
ingest_parallax(temp_db, "Fake 2", 1, 1, "Ref 2")
assert "Duplicate measurement exists with same reference" in str(
error_message.value
)

flags = ingest_parallax(temp_db, "Fake 2", 1, 1, "Ref 2", "comment", False)
print(flags)
assert flags == {
"added": False,
"content": {},
"message": "Duplicate measurement exists with same reference",
}


def test_ingest_proper_motions(temp_db, t_pm):
ingest_proper_motions(
Expand Down

0 comments on commit d144f61

Please sign in to comment.