Hide keyboard shortcuts

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/>. 

21 

22"""Unit tests for daf_butler CLI query-collections command. 

23""" 

24 

25import click 

26import unittest 

27import yaml 

28 

29from lsst.daf.butler import Butler, DatasetType, StorageClass 

30from lsst.daf.butler.cli.butler import cli 

31from lsst.daf.butler.cli.utils import clickResultMsg 

32from lsst.daf.butler.tests.mockeredTest import MockeredTestBase 

33 

34 

35class QueryDatasetTypesCmdTest(MockeredTestBase): 

36 

37 defaultExpected = dict(repo=None, 

38 verbose=False, 

39 glob=(), 

40 components=None) 

41 

42 def test_minimal(self): 

43 """Test only required parameters. 

44 """ 

45 self.run_test(["query-dataset-types", "here"], 

46 self.makeExpected(repo="here")) 

47 

48 def test_requiredMissing(self): 

49 """Test that if the required parameter is missing it fails""" 

50 self.run_missing(["query-dataset-types"], 'Error: Missing argument "REPO".') 

51 

52 def test_all(self): 

53 """Test all parameters.""" 

54 self.run_test(["query-dataset-types", "here", "--verbose", "foo*", "--components"], 

55 self.makeExpected(repo="here", verbose=True, glob=("foo*", ), components=True)) 

56 self.run_test(["query-dataset-types", "here", "--verbose", "foo*", "--no-components"], 

57 self.makeExpected(repo="here", verbose=True, glob=("foo*", ), components=False)) 

58 

59 

60class QueryDatasetTypesScriptTest(unittest.TestCase): 

61 

62 def testQueryDatasetTypes(self): 

63 self.maxDiff = None 

64 datasetName = "test" 

65 instrumentDimension = "instrument" 

66 visitDimension = "visit" 

67 storageClassName = "testDatasetType" 

68 expectedNotVerbose = {"datasetTypes": [datasetName]} 

69 runner = click.testing.CliRunner() 

70 with runner.isolated_filesystem(): 

71 butlerCfg = Butler.makeRepo("here") 

72 butler = Butler(butlerCfg, writeable=True) 

73 storageClass = StorageClass(storageClassName) 

74 butler.registry.storageClasses.registerStorageClass(storageClass) 

75 dimensions = butler.registry.dimensions.extract((instrumentDimension, visitDimension)) 

76 datasetType = DatasetType(datasetName, dimensions, storageClass) 

77 butler.registry.registerDatasetType(datasetType) 

78 # check not-verbose output: 

79 result = runner.invoke(cli, ["query-dataset-types", "here"]) 

80 self.assertEqual(result.exit_code, 0, clickResultMsg(result)) 

81 self.assertEqual(expectedNotVerbose, yaml.safe_load(result.output)) 

82 # check glob output: 

83 result = runner.invoke(cli, ["query-dataset-types", "here", "t*"]) 

84 self.assertEqual(result.exit_code, 0, clickResultMsg(result)) 

85 self.assertEqual(expectedNotVerbose, yaml.safe_load(result.output)) 

86 # check verbose output: 

87 result = runner.invoke(cli, ["query-dataset-types", "here", "--verbose"]) 

88 self.assertEqual(result.exit_code, 0, clickResultMsg(result)) 

89 response = yaml.safe_load(result.output) 

90 # output dimension names contain all required dimensions, more than 

91 # the registered dimensions, so verify the expected components 

92 # individually. 

93 self.assertEqual(response["datasetTypes"][0]["name"], datasetName) 

94 self.assertEqual(response["datasetTypes"][0]["storageClass"], storageClassName) 

95 self.assertIn(instrumentDimension, response["datasetTypes"][0]["dimensions"]) 

96 self.assertIn(visitDimension, response["datasetTypes"][0]["dimensions"]) 

97 

98 

99if __name__ == "__main__": 99 ↛ 100line 99 didn't jump to line 100, because the condition on line 99 was never true

100 unittest.main()