Skip to content

Commit

Permalink
Add test for reading JSON with missing group_counter_start entry
Browse files Browse the repository at this point in the history
This tests that the fallback constructor code triggers
correctly.
  • Loading branch information
timj committed May 6, 2022
1 parent 31f72d9 commit a5d4363
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/data/fitsheader-hsc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"_translator": "HSC", "telescope": "Subaru", "instrument": "HSC", "location": [-5464492.282102364, -2493000.6266314997, 2150943.6513960036], "exposure_id": 904024, "visit_id": 904024, "physical_filter": "HSC-I", "datetime_begin": [2456599.0, -0.23853115740740743], "datetime_end": [2456599.0, -0.23816055555555554], "exposure_time": 30.0, "dark_time": 30.0, "boresight_airmass": 1.121626027604189, "boresight_rotation_angle": 270.0, "boresight_rotation_coord": "sky", "detector_num": 50, "detector_name": "12", "detector_unique_name": "1_12", "detector_serial": "120", "detector_group": "1", "detector_exposure_id": 180804850, "object": "STRIPE82L", "temperature": 272.35, "pressure": 621.7, "relative_humidity": 33.1, "tracking_radec": [320.74992499999996, 0.5000194444444445], "altaz_begin": [226.68922661, 63.04359233], "science_program": "o13015", "observation_type": "science", "observation_id": "HSCA90402400", "observation_reason": "science", "exposure_group": "904024", "observing_day": 20131102, "observation_counter": 904024, "group_counter_end": 904024, "__CONTENT__": "translated"}
15 changes: 15 additions & 0 deletions tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,21 @@ def test_file_reading(self):
with self.assertRaises(ValueError):
read_index(bad_file)

def test_obs_info_sidecar(self):
"""Test reading of older files with missing content."""

# First with a real header (but YAML)
file = os.path.join(TESTDATA, "fitsheader-hsc.yaml")
info = read_file_info(file, 1, None, "translated", content_type="native")
self.assertIsInstance(info, ObservationInfo)
self.assertEqual(info.instrument, "HSC")

# With translated metadata sidecar that lacks the group_counter_start.
json_file = os.path.splitext(file)[0] + ".json"
json_info = read_sidecar(json_file)
self.assertIsInstance(json_info, ObservationInfo)
self.assertEqual(json_info, info)


if __name__ == "__main__":
unittest.main()

0 comments on commit a5d4363

Please sign in to comment.