Coverage for tests/test_cliCmdQueryDimensionRecords.py: 43%
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 StorageClassFactory
31from lsst.daf.butler import Butler
32from lsst.daf.butler.cli.butler import cli as butlerCli
33from lsst.daf.butler.cli.utils import clickResultMsg, LogCliRunner
34from lsst.daf.butler.tests.utils import (
35 ButlerTestHelper,
36 makeTestTempDir,
37 MetricTestRepo,
38 readTable,
39 removeTestTempDir,
40)
43TESTDIR = os.path.abspath(os.path.dirname(__file__))
46class QueryDimensionRecordsTest(unittest.TestCase, ButlerTestHelper):
48 mockFuncName = "lsst.daf.butler.cli.cmd.commands.script.queryDimensionRecords"
50 configFile = os.path.join(TESTDIR, "config/basic/butler.yaml")
51 storageClassFactory = StorageClassFactory()
53 expectedColumnNames = ("instrument", "id", "physical_filter", "visit_system", "name", "day_obs",
54 "exposure_time", "target_name", "observation_reason", "science_program",
55 "zenith_angle", "region", "timespan [2]")
57 def setUp(self):
58 self.root = makeTestTempDir(TESTDIR)
59 self.testRepo = MetricTestRepo(self.root,
60 configFile=os.path.join(TESTDIR, "config/basic/butler.yaml"))
61 self.runner = LogCliRunner()
63 def tearDown(self):
64 removeTestTempDir(self.root)
66 def testBasic(self):
67 result = self.runner.invoke(butlerCli, ["query-dimension-records",
68 self.root,
69 "visit"])
70 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
71 rows = array((
72 ("DummyCamComp", "423", "d-r", "1", "fourtwentythree", "None", "None", "None", "None", "None",
73 "None", "None", "None .. None"),
74 ("DummyCamComp", "424", "d-r", "1", "fourtwentyfour", "None", "None", "None", "None", "None",
75 "None", "None", "None .. None")
76 ))
77 expected = AstropyTable(rows, names=self.expectedColumnNames)
78 self.assertAstropyTablesEqual(readTable(result.output), expected)
80 def testWhere(self):
81 result = self.runner.invoke(butlerCli, ["query-dimension-records",
82 self.root,
83 "visit",
84 "--where",
85 "instrument='DummyCamComp' AND visit.name='fourtwentythree'"])
86 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
87 rows = array((
88 ("DummyCamComp", "423", "d-r", "1", "fourtwentythree", "None", "None", "None", "None", "None",
89 "None", "None", "None .. None"),
90 ))
91 expected = AstropyTable(rows, names=self.expectedColumnNames)
92 self.assertAstropyTablesEqual(readTable(result.output), expected)
94 def testCollection(self):
96 butler = Butler(self.root, run="foo")
98 # try replacing the testRepo's butler with the one with the "foo" run.
99 self.testRepo.butler = butler
101 self.testRepo.butler.registry.insertDimensionData("visit", {"instrument": "DummyCamComp", "id": 425,
102 "name": "fourtwentyfive",
103 "physical_filter": "d-r",
104 "visit_system": 1})
105 self.testRepo.addDataset(dataId={"instrument": "DummyCamComp", "visit": 425},
106 run="foo")
108 # verify getting records from the "ingest/run" collection
109 result = self.runner.invoke(butlerCli, ["query-dimension-records",
110 self.root,
111 "visit",
112 "--collections", "ingest/run",
113 "--datasets", "test_metric_comp"
114 ])
115 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
116 rows = array((
117 ("DummyCamComp", "423", "d-r", "1", "fourtwentythree", "None", "None", "None", "None", "None",
118 "None", "None", "None .. None"),
119 ("DummyCamComp", "424", "d-r", "1", "fourtwentyfour", "None", "None", "None", "None", "None",
120 "None", "None", "None .. None")
121 ))
122 expected = AstropyTable(rows, names=self.expectedColumnNames)
123 self.assertAstropyTablesEqual(readTable(result.output), expected)
125 # verify getting records from the "foo" collection
126 result = self.runner.invoke(butlerCli, ["query-dimension-records",
127 self.root,
128 "visit",
129 "--collections", "foo",
130 "--datasets", "test_metric_comp"
131 ])
132 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
133 rows = array((
134 ("DummyCamComp", "425", "d-r", "1", "fourtwentyfive", "None", "None", "None", "None", "None",
135 "None", "None", "None .. None"),
136 ))
137 expected = AstropyTable(rows, names=self.expectedColumnNames)
138 self.assertAstropyTablesEqual(readTable(result.output), expected)
141if __name__ == "__main__": 141 ↛ 142line 141 didn't jump to line 142, because the condition on line 141 was never true
142 unittest.main()