Skip to content

Commit

Permalink
Improve queryDataIds command tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Jul 1, 2022
1 parent 311b40f commit 0d74d24
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion tests/test_cliCmdQueryDataIds.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import unittest

from astropy.table import Table as AstropyTable
from lsst.daf.butler import Butler, script
from lsst.daf.butler import Butler, DatasetType, script
from lsst.daf.butler.tests.utils import ButlerTestHelper, MetricTestRepo, makeTestTempDir, removeTestTempDir
from numpy import array

Expand Down Expand Up @@ -127,6 +127,45 @@ def testDatasetsAndCollections(self):
self.assertAstropyTablesEqual(res, expected)
self.assertFalse(msg)

# Verify the new dataset is found in the "foo" collection and the
# dimensions are determined automatically.
with self.assertLogs("lsst.daf.butler.script.queryDataIds", "INFO") as cm:
res, msg = self._queryDataIds(repo=self.root, collections=("foo",), datasets="test_metric_comp")
self.assertIn("Determined dimensions", "\n".join(cm.output))
expected = AstropyTable(
array((("R", "DummyCamComp", "d-r", 425),)),
names=("band", "instrument", "physical_filter", "visit"),
)
self.assertAstropyTablesEqual(res, expected)
self.assertFalse(msg)

# Check that we get a reason if no dimensions can be inferred.
new_dataset_type = DatasetType(
"test_metric_dimensionless",
(),
"StructuredDataDict",
universe=self.repo.butler.registry.dimensions,
)
self.repo.butler.registry.registerDatasetType(new_dataset_type)
res, msg = self._queryDataIds(repo=self.root, collections=("foo",), datasets=...)
self.assertIsNone(res)
self.assertIn("No dimensions in common", msg)

# Check that we get a reason returned if no dataset type is found.
res, msg = self._queryDataIds(
repo=self.root, dimensions=("visit",), collections=("foo",), datasets="raw"
)
self.assertIsNone(res)
self.assertEqual(msg, "Dataset type raw is not registered.")

# Check that we get a reason returned if no dataset is found in
# collection.
res, msg = self._queryDataIds(
repo=self.root, dimensions=("visit",), collections=("ingest",), datasets="test_metric_comp"
)
self.assertIsNone(res)
self.assertIn("No datasets of type test_metric_comp", msg)


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

0 comments on commit 0d74d24

Please sign in to comment.