Skip to content

Commit

Permalink
Add tests for duplicate information in dataId
Browse files Browse the repository at this point in the history
day_obs and exposure can be given and if they are consistent
this should not raise an exception.
  • Loading branch information
timj committed Dec 29, 2021
1 parent 66f9de7 commit 152a9bf
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/test_simpleButler.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,11 @@ def testButlerGet(self):
},
{},
),
# Duplicate (but valid) information.
(None, {"instrument": "Cam1", "detector": 2, "raft": "A", "physical_filter": "Cam1-G"}),
({"detector": 2}, {"instrument": "Cam1", "raft": "A", "physical_filter": "Cam1-G"}),
({"raft": "A"}, {"instrument": "Cam1", "detector": 2, "physical_filter": "Cam1-G"}),
({"raft": "A"}, {"instrument": "Cam1", "detector": "Ab", "physical_filter": "Cam1-G"}),
)

for dataId, kwds in variants:
Expand All @@ -377,6 +382,21 @@ def testButlerGet(self):
raise type(e)(f"{str(e)}: dataId={dataId}, kwds={kwds}") from e
self.assertEqual(flat_id, flat2g.id, msg=f"DataId: {dataId}, kwds: {kwds}")

# Check that bad combinations raise.
variants = (
# Inconsistent detector information.
(None, {"instrument": "Cam1", "detector": 2, "raft": "B", "physical_filter": "Cam1-G"}),
({"detector": 2}, {"instrument": "Cam1", "raft": "B", "physical_filter": "Cam1-G"}),
({"raft": "B"}, {"instrument": "Cam1", "detector": 2, "physical_filter": "Cam1-G"}),
({"raft": "B"}, {"instrument": "Cam1", "detector": "Ab", "physical_filter": "Cam1-G"}),
# Spurious kwargs.
(None, {"instrument": "Cam1", "detector": 2, "physical_filter": "Cam1-G", "x": "y"}),
({"x": "y"}, {"instrument": "Cam1", "detector": 2, "physical_filter": "Cam1-G"}),
)
for dataId, kwds in variants:
with self.assertRaises(ValueError):
butler.get("flat", dataId=dataId, collections=coll, **kwds)

def testGetCalibration(self):
"""Test that `Butler.get` can be used to fetch from
`~CollectionType.CALIBRATION` collections if the data ID includes
Expand Down Expand Up @@ -476,6 +496,33 @@ def testGetCalibration(self):
)
self.assertEqual(bias3b_id, bias3b.id)

# Allow a fully-specified dataId and unnecessary extra information
# that comes from the record.
bias3b_id, _ = butler.get(
"bias",
dataId=dict(
exposure=4,
day_obs=20211114,
seq_num=42,
detector=3,
instrument="Cam1",
),
collections="calibs",
)
self.assertEqual(bias3b_id, bias3b.id)

# Extra but inconsistent record values are a problem.
with self.assertRaises(ValueError):
bias3b_id, _ = butler.get(
"bias",
exposure=3,
day_obs=20211114,
seq_num=42,
detector=3,
collections="calibs",
instrument="Cam1",
)

# Ensure that spurious kwargs cause an exception.
with self.assertRaises(ValueError):
butler.get(
Expand Down

0 comments on commit 152a9bf

Please sign in to comment.