Skip to content

Commit

Permalink
Fix race condition in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fred3m committed Jul 8, 2024
1 parent 6a3c3f1 commit 72480e2
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 11 deletions.
12 changes: 12 additions & 0 deletions tests/joins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,15 @@ joins:
- exposure_id
visit1_quicklook:
- visit_id
- type: inner
matches:
exposure:
- exposure_id
visit1:
- visit_id
- type: inner
matches:
visit1:
- visit_id
visit1_quicklook:
- visit_id
35 changes: 35 additions & 0 deletions tests/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,41 @@ tables:
- name: obs_start_mjd
datatype: double
description: Start of the exposure in MJD, TAI, accurate to 10ms.
- name: visit1
index_columns:
- visit_id
columns:
- name: visit_id
datatype: long
description: Unique identifier for the exposure.
- name: seq_num
datatype: long
description: Sequence number
- name: day_obs
datatype: date
description: The night of the observation. This is different than the
observation date, as this is the night that the observations started,
so for observations after midnight obsStart and obsNight will be
different days.
- name: ra
datatype: double
unit: degree
description: RA of focal plane center.
- name: dec
datatype: double
unit: degree
description: Declination of focal plane center
- name: physical_filter
datatype: char
description: ID of physical filter,
the filter associated with a particular instrument.
- name: obs_start
datatype: datetime
description: Start time of the exposure at the fiducial center
of the focal plane array, TAI, accurate to 10ms.
- name: obs_start_mjd
datatype: double
description: Start of the exposure in MJD, TAI, accurate to 10ms.
- name: visit1_quicklook
index_columns:
- visit_id
Expand Down
1 change: 1 addition & 0 deletions tests/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_get_table_names(self):
table_names,
(
"exposure",
"visit1",
"visit1_quicklook",
),
)
Expand Down
25 changes: 14 additions & 11 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def create_table(cursor: sqlite3.Cursor, tbl_name: str, schema: dict):
cursor.execute(command)


def get_exposure_data_dict() -> dict:
def get_exposure_data_dict(table_name: str, id_name: str) -> dict:
"""Get a dictionary containing the visit test data"""

obs_start = [
Expand All @@ -88,9 +88,9 @@ def get_exposure_data_dict() -> dict:
obs_start_mjd = [Time(time).mjd for time in obs_start]

return {
"exposure.exposure_id": [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],
"exposure.seq_num": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
"exposure.day_obs": [
f"{table_name}.{id_name}": [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],
f"{table_name}.seq_num": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
f"{table_name}.day_obs": [
"2023-05-19",
"2023-05-19",
"2023-05-19",
Expand All @@ -102,9 +102,9 @@ def get_exposure_data_dict() -> dict:
"2023-02-14",
"2023-02-14",
],
"exposure.ra": [10, 20, None, 40, 50, 60, 70, None, 90, 100],
"exposure.dec": [-40, -30, None, -10, 0, 10, None, 30, 40, 50],
"exposure.physical_filter": [
f"{table_name}.ra": [10, 20, None, 40, 50, 60, 70, None, 90, 100],
f"{table_name}.dec": [-40, -30, None, -10, 0, 10, None, 30, 40, 50],
f"{table_name}.physical_filter": [
"LSST g-band",
"LSST r-band",
"LSST i-band",
Expand All @@ -116,8 +116,8 @@ def get_exposure_data_dict() -> dict:
"DECam z-band",
"DECam y-band",
],
"exposure.obs_start": obs_start,
"exposure.obs_start_mjd": obs_start_mjd,
f"{table_name}.obs_start": obs_start,
f"{table_name}.obs_start_mjd": obs_start_mjd,
}


Expand All @@ -132,7 +132,7 @@ def get_visit_data_dict() -> dict:
def get_test_data(table: str) -> ApTable:
"""Generate data for the test database"""
if table == "exposure":
data_dict = get_exposure_data_dict()
data_dict = get_exposure_data_dict("exposure", "exposure_id")
else:
data_dict = get_visit_data_dict()

Expand All @@ -157,8 +157,11 @@ def create_database(schema: dict, db_filename: str):
create_table(cursor, table["name"], table["columns"])

if table["name"] == "exposure":
data = get_exposure_data_dict()
data = get_exposure_data_dict("exposure", "exposure_id")
index_key = "exposure.exposure_id"
elif table["name"] == "visit1":
data = get_exposure_data_dict("visit1", "visit_id")
index_key = "visit1.visit_id"
elif table["name"] == "visit1_quicklook":
data = get_visit_data_dict()
index_key = "visit1_quicklook.visit_id"
Expand Down

0 comments on commit 72480e2

Please sign in to comment.