Coverage for tests/test_cliCmdQueryDatasetTypes.py : 35%

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