Coverage for tests/test_cliCmdQueryDataIds.py: 50%
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# This file is part of daf_butler.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
22"""Unit tests for daf_butler CLI query-collections command.
23"""
25from astropy.table import Table as AstropyTable
26from numpy import array
27import os
28import unittest
30from lsst.daf.butler import Butler
31from lsst.daf.butler import script
32from lsst.daf.butler.tests.utils import ButlerTestHelper, makeTestTempDir, MetricTestRepo, removeTestTempDir
35TESTDIR = os.path.abspath(os.path.dirname(__file__))
38class QueryDataIdsTest(unittest.TestCase, ButlerTestHelper):
40 mockFuncName = "lsst.daf.butler.cli.cmd.commands.script.queryDataIds"
42 @staticmethod
43 def _queryDataIds(repo, dimensions=(), collections=(), datasets=None, where=None):
44 """Helper to populate the call to script.queryDataIds with default
45 values."""
46 return script.queryDataIds(repo=repo,
47 dimensions=dimensions,
48 collections=collections,
49 datasets=datasets,
50 where=where,
51 order_by=None,
52 limit=0,
53 offset=0)
55 def setUp(self):
56 self.root = makeTestTempDir(TESTDIR)
57 self.repo = MetricTestRepo(root=self.root,
58 configFile=os.path.join(TESTDIR, "config/basic/butler.yaml"))
60 def tearDown(self):
61 removeTestTempDir(self.root)
63 def testDimensions(self):
64 """Test getting a dimension."""
65 res = self._queryDataIds(self.root, dimensions=("visit",))
66 expected = AstropyTable(
67 array((
68 ("R", "DummyCamComp", "d-r", 1, 423),
69 ("R", "DummyCamComp", "d-r", 1, 424)
70 )),
71 names=("band", "instrument", "physical_filter", "visit_system", "visit")
72 )
73 self.assertAstropyTablesEqual(res, expected)
75 def testNull(self):
76 "Test asking for nothing."
77 res = self._queryDataIds(self.root)
78 self.assertEqual(res, None)
80 def testWhere(self):
81 """Test with a WHERE constraint."""
82 res = self._queryDataIds(self.root, dimensions=("visit",),
83 where="instrument='DummyCamComp' AND visit=423")
84 expected = AstropyTable(
85 array((
86 ("R", "DummyCamComp", "d-r", 1, 423),
87 )),
88 names=("band", "instrument", "physical_filter", "visit_system", "visit")
89 )
90 self.assertAstropyTablesEqual(res, expected)
92 def testDatasetsAndCollections(self):
93 """Test constraining via datasets and collections."""
95 # Add a dataset in a different collection
96 self.butler = Butler(self.root, run="foo")
97 self.repo.butler.registry.insertDimensionData("visit", {"instrument": "DummyCamComp", "id": 425,
98 "name": "fourtwentyfive",
99 "physical_filter": "d-r",
100 "visit_system": 1})
101 self.repo.addDataset(dataId={"instrument": "DummyCamComp", "visit": 425},
102 run="foo")
104 # Verify the new dataset is not found in the "ingest/run" collection.
105 res = self._queryDataIds(repo=self.root, dimensions=("visit",), collections=("ingest/run",),
106 datasets="test_metric_comp")
107 expected = AstropyTable(
108 array((
109 ("R", "DummyCamComp", "d-r", 1, 423),
110 ("R", "DummyCamComp", "d-r", 1, 424)
111 )),
112 names=("band", "instrument", "physical_filter", "visit_system", "visit")
113 )
114 self.assertAstropyTablesEqual(res, expected)
116 # Verify the new dataset is found in the "foo" collection.
117 res = self._queryDataIds(repo=self.root, dimensions=("visit",), collections=("foo",),
118 datasets="test_metric_comp")
119 expected = AstropyTable(
120 array((
121 ("R", "DummyCamComp", "d-r", 1, 425),
122 )),
123 names=("band", "instrument", "physical_filter", "visit_system", "visit")
124 )
125 self.assertAstropyTablesEqual(res, expected)
128if __name__ == "__main__": 128 ↛ 129line 128 didn't jump to line 129, because the condition on line 128 was never true
129 unittest.main()