Coverage for tests/test_cliCmdQueryDimensionRecords.py : 42%

Hot-keys 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 shutil
29import tempfile
30import unittest
32from lsst.daf.butler import StorageClassFactory
33from lsst.daf.butler import Butler
34from lsst.daf.butler.cli.butler import cli as butlerCli
35from lsst.daf.butler.cli.utils import clickResultMsg, LogCliRunner
36from lsst.daf.butler.tests.utils import ButlerTestHelper, MetricTestRepo, readTable
39TESTDIR = os.path.abspath(os.path.dirname(__file__))
42class QueryDimensionRecordsTest(unittest.TestCase, ButlerTestHelper):
44 configFile = os.path.join(TESTDIR, "config/basic/butler.yaml")
45 storageClassFactory = StorageClassFactory()
47 expectedColumnNames = ("instrument", "id", "physical_filter", "visit_system", "name", "day_obs",
48 "exposure_time", "target_name", "observation_reason", "science_program",
49 "zenith_angle", "region", "timespan [2]")
51 def setUp(self):
52 self.root = tempfile.mkdtemp(dir=TESTDIR)
53 self.testRepo = MetricTestRepo(self.root,
54 configFile=os.path.join(TESTDIR, "config/basic/butler.yaml"))
55 self.runner = LogCliRunner()
57 def tearDown(self):
58 if os.path.exists(self.root):
59 shutil.rmtree(self.root, ignore_errors=True)
61 def testBasic(self):
62 result = self.runner.invoke(butlerCli, ["query-dimension-records",
63 self.root,
64 "visit"])
65 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
66 rows = array((
67 ("DummyCamComp", "423", "d-r", "1", "fourtwentythree", "None", "None", "None", "None", "None",
68 "None", "None", "None .. None"),
69 ("DummyCamComp", "424", "d-r", "1", "fourtwentyfour", "None", "None", "None", "None", "None",
70 "None", "None", "None .. None")
71 ))
72 expected = AstropyTable(rows, names=self.expectedColumnNames)
73 self.assertAstropyTablesEqual(readTable(result.output), expected)
75 def testWhere(self):
76 result = self.runner.invoke(butlerCli, ["query-dimension-records",
77 self.root,
78 "visit",
79 "--where",
80 "instrument='DummyCamComp' AND visit.name='fourtwentythree'"])
81 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
82 rows = array((
83 ("DummyCamComp", "423", "d-r", "1", "fourtwentythree", "None", "None", "None", "None", "None",
84 "None", "None", "None .. None"),
85 ))
86 expected = AstropyTable(rows, names=self.expectedColumnNames)
87 self.assertAstropyTablesEqual(readTable(result.output), expected)
89 def testCollection(self):
91 butler = Butler(self.root, run="foo")
93 # try replacing the testRepo's butler with the one with the "foo" run.
94 self.testRepo.butler = butler
96 self.testRepo.butler.registry.insertDimensionData("visit", {"instrument": "DummyCamComp", "id": 425,
97 "name": "fourtwentyfive",
98 "physical_filter": "d-r",
99 "visit_system": 1})
100 self.testRepo.addDataset(dataId={"instrument": "DummyCamComp", "visit": 425},
101 run="foo")
103 # verify getting records from the "ingest/run" collection
104 result = self.runner.invoke(butlerCli, ["query-dimension-records",
105 self.root,
106 "visit",
107 "--collections", "ingest/run",
108 "--datasets", "test_metric_comp"
109 ])
110 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
111 rows = array((
112 ("DummyCamComp", "423", "d-r", "1", "fourtwentythree", "None", "None", "None", "None", "None",
113 "None", "None", "None .. None"),
114 ("DummyCamComp", "424", "d-r", "1", "fourtwentyfour", "None", "None", "None", "None", "None",
115 "None", "None", "None .. None")
116 ))
117 expected = AstropyTable(rows, names=self.expectedColumnNames)
118 self.assertAstropyTablesEqual(readTable(result.output), expected)
120 # verify getting records from the "foo" collection
121 result = self.runner.invoke(butlerCli, ["query-dimension-records",
122 self.root,
123 "visit",
124 "--collections", "foo",
125 "--datasets", "test_metric_comp"
126 ])
127 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
128 rows = array((
129 ("DummyCamComp", "425", "d-r", "1", "fourtwentyfive", "None", "None", "None", "None", "None",
130 "None", "None", "None .. None"),
131 ))
132 expected = AstropyTable(rows, names=self.expectedColumnNames)
133 self.assertAstropyTablesEqual(readTable(result.output), expected)
136if __name__ == "__main__": 136 ↛ 137line 136 didn't jump to line 137, because the condition on line 136 was never true
137 unittest.main()