Coverage for tests/test_cliCmdQueryDatasetTypes.py : 33%

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"""
25import unittest
26import yaml
28from lsst.daf.butler import Butler, DatasetType, StorageClass
29from lsst.daf.butler.cli.butler import cli
30from lsst.daf.butler.cli.cmd import query_dataset_types
31from lsst.daf.butler.cli.utils import clickResultMsg, LogCliRunner
32from lsst.daf.butler.tests import CliCmdTestBase
35class QueryDatasetTypesCmdTest(CliCmdTestBase, unittest.TestCase):
37 @staticmethod
38 def defaultExpected():
39 return dict(repo=None,
40 verbose=False,
41 glob=(),
42 components=None)
44 @staticmethod
45 def command():
46 return query_dataset_types
48 def test_minimal(self):
49 """Test only required parameters.
50 """
51 self.run_test(["query-dataset-types", "here"],
52 self.makeExpected(repo="here"))
54 def test_requiredMissing(self):
55 """Test that if the required parameter is missing it fails"""
56 self.run_missing(["query-dataset-types"], r"Error: Missing argument ['\"]REPO['\"].")
58 def test_all(self):
59 """Test all parameters."""
60 self.run_test(["query-dataset-types", "here", "--verbose", "foo*", "--components"],
61 self.makeExpected(repo="here", verbose=True, glob=("foo*", ), components=True))
62 self.run_test(["query-dataset-types", "here", "--verbose", "foo*", "--no-components"],
63 self.makeExpected(repo="here", verbose=True, glob=("foo*", ), components=False))
66class QueryDatasetTypesScriptTest(unittest.TestCase):
68 def testQueryDatasetTypes(self):
69 self.maxDiff = None
70 datasetName = "test"
71 instrumentDimension = "instrument"
72 visitDimension = "visit"
73 storageClassName = "testDatasetType"
74 expectedNotVerbose = {"datasetTypes": [datasetName]}
75 runner = LogCliRunner()
76 with runner.isolated_filesystem():
77 butlerCfg = Butler.makeRepo("here")
78 butler = Butler(butlerCfg, writeable=True)
79 storageClass = StorageClass(storageClassName)
80 butler.registry.storageClasses.registerStorageClass(storageClass)
81 dimensions = butler.registry.dimensions.extract((instrumentDimension, visitDimension))
82 datasetType = DatasetType(datasetName, dimensions, storageClass)
83 butler.registry.registerDatasetType(datasetType)
84 # check not-verbose output:
85 result = runner.invoke(cli, ["query-dataset-types", "here"])
86 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
87 self.assertEqual(expectedNotVerbose, yaml.safe_load(result.output))
88 # check glob output:
89 result = runner.invoke(cli, ["query-dataset-types", "here", "t*"])
90 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
91 self.assertEqual(expectedNotVerbose, yaml.safe_load(result.output))
92 # check verbose output:
93 result = runner.invoke(cli, ["query-dataset-types", "here", "--verbose"])
94 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
95 response = yaml.safe_load(result.output)
96 # output dimension names contain all required dimensions, more than
97 # the registered dimensions, so verify the expected components
98 # individually.
99 self.assertEqual(response["datasetTypes"][0]["name"], datasetName)
100 self.assertEqual(response["datasetTypes"][0]["storageClass"], storageClassName)
101 self.assertIn(instrumentDimension, response["datasetTypes"][0]["dimensions"])
102 self.assertIn(visitDimension, response["datasetTypes"][0]["dimensions"])
105if __name__ == "__main__": 105 ↛ 106line 105 didn't jump to line 106, because the condition on line 105 was never true
106 unittest.main()