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"""
25from astropy.table import Table as AstropyTable
26from numpy import array
27import unittest
29from lsst.daf.butler import Butler, DatasetType, StorageClass
30from lsst.daf.butler.cli.butler import cli
31from lsst.daf.butler.cli.cmd import query_dataset_types
32from lsst.daf.butler.cli.utils import clickResultMsg, LogCliRunner
33from lsst.daf.butler.tests import CliCmdTestBase
34from lsst.daf.butler.tests.utils import ButlerTestHelper, readTable
37class QueryDatasetTypesCmdTest(CliCmdTestBase, unittest.TestCase):
39 @staticmethod
40 def defaultExpected():
41 return dict(repo=None,
42 verbose=False,
43 glob=(),
44 components=None)
46 @staticmethod
47 def command():
48 return query_dataset_types
50 def test_minimal(self):
51 """Test only required parameters.
52 """
53 self.run_test(["query-dataset-types", "here"],
54 self.makeExpected(repo="here"))
56 def test_requiredMissing(self):
57 """Test that if the required parameter is missing it fails"""
58 self.run_missing(["query-dataset-types"], r"Error: Missing argument ['\"]REPO['\"].")
60 def test_all(self):
61 """Test all parameters."""
62 self.run_test(["query-dataset-types", "here", "--verbose", "foo*", "--components"],
63 self.makeExpected(repo="here", verbose=True, glob=("foo*", ), components=True))
64 self.run_test(["query-dataset-types", "here", "--verbose", "foo*", "--no-components"],
65 self.makeExpected(repo="here", verbose=True, glob=("foo*", ), components=False))
68class QueryDatasetTypesScriptTest(ButlerTestHelper, unittest.TestCase):
70 def testQueryDatasetTypes(self):
71 self.maxDiff = None
72 datasetName = "test"
73 instrumentDimension = "instrument"
74 visitDimension = "visit"
75 storageClassName = "testDatasetType"
76 expectedNotVerbose = AstropyTable((("test",),), names=("name",))
77 runner = LogCliRunner()
78 with runner.isolated_filesystem():
79 butlerCfg = Butler.makeRepo("here")
80 butler = Butler(butlerCfg, writeable=True)
81 storageClass = StorageClass(storageClassName)
82 butler.registry.storageClasses.registerStorageClass(storageClass)
83 dimensions = butler.registry.dimensions.extract((instrumentDimension, visitDimension))
84 datasetType = DatasetType(datasetName, dimensions, storageClass)
85 butler.registry.registerDatasetType(datasetType)
86 # check not-verbose output:
87 result = runner.invoke(cli, ["query-dataset-types", "here"])
88 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
89 self.assertAstropyTablesEqual(readTable(result.output), expectedNotVerbose)
90 # check glob output:
91 result = runner.invoke(cli, ["query-dataset-types", "here", "t*"])
92 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
93 self.assertAstropyTablesEqual(readTable(result.output), expectedNotVerbose)
94 # check verbose output:
95 result = runner.invoke(cli, ["query-dataset-types", "here", "--verbose"])
96 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
97 expected = AstropyTable(array((
98 "test",
99 "['band', 'instrument', 'physical_filter', 'visit_system', 'visit']",
100 "testDatasetType")),
101 names=("name", "dimensions", "storage class"))
102 self.assertAstropyTablesEqual(readTable(result.output), expected)
104 # Now remove and check that it was removed
105 # First a non-existent one
106 result = runner.invoke(cli, ["remove-dataset-type", "here", "unreal"])
107 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
109 # Now one we now has been registered
110 result = runner.invoke(cli, ["remove-dataset-type", "here", datasetName])
111 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
113 # and check that it has gone
114 result = runner.invoke(cli, ["query-dataset-types", "here"])
115 self.assertEqual(result.exit_code, 0, clickResultMsg(result))
116 self.assertIn("No results", result.output)
119if __name__ == "__main__": 119 ↛ 120line 119 didn't jump to line 120, because the condition on line 119 was never true
120 unittest.main()