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 config-dump command. 

23""" 

24 

25import click 

26import click.testing 

27import unittest 

28 

29from lsst.daf.butler.cli import butler 

30from lsst.daf.butler.cli.utils import DAF_BUTLER_MOCK, verifyFunctionInfo 

31 

32 

33def makeExpectedKwargs(**kwargs): 

34 expected = dict(directory=None, 

35 file=None, 

36 transfer="auto", 

37 ingest_task="lsst.obs.base.RawIngestTask", 

38 config={}, 

39 config_file=None) 

40 expected.update(kwargs) 

41 return expected 

42 

43 

44class Suite(unittest.TestCase): 

45 

46 def run_test(self, inputs, expectedKwargs): 

47 """Test command line interaction with ingest_raws command function. 

48 

49 Parameters 

50 ---------- 

51 inputs : [`str`] 

52 A list of the arguments to the butler command, starting with 

53 `ingest-raws` 

54 expectedKwargs : `dict` [`str`, `str`] 

55 The expected arguments to the ingestRaws command function, keys are 

56 the argument name and values are the argument value. 

57 """ 

58 runner = click.testing.CliRunner(env=DAF_BUTLER_MOCK) 

59 result = runner.invoke(butler.cli, inputs) 

60 self.assertEqual(result.exit_code, 0, f"output: {result.output} exception: {result.exception}") 

61 verifyFunctionInfo(self, result.output, "ingestRaws", (), expectedKwargs) 

62 

63 def test_repoAndOutput(self): 

64 """Test the most basic required arguments, repo and output run""" 

65 expected = makeExpectedKwargs(repo="here", output_run="out") 

66 self.run_test(["ingest-raws", "here", "--output-run", "out"], expected) 

67 

68 def test_configMulti(self): 

69 """Test config overrides""" 

70 expected = makeExpectedKwargs(repo="here", output_run="out", config=dict(foo="1", bar="2", baz="3")) 

71 self.run_test(["ingest-raws", "here", 

72 "--output-run", "out", 

73 "-c", "foo=1", 

74 "--config", "bar=2,baz=3"], expected) 

75 

76 def test_configFile(self): 

77 """Test config file override""" 

78 expected = makeExpectedKwargs(repo="here", output_run="out", config_file="path/to/file.txt") 

79 self.run_test(["ingest-raws", "here", 

80 "--output-run", "out", 

81 "--config-file", "path/to/file.txt"], expected) 

82 

83 def test_transfer(self): 

84 """Test the transfer argument""" 

85 expected = makeExpectedKwargs(repo="here", output_run="out", transfer="foo") 

86 self.run_test(["ingest-raws", "here", 

87 "--output-run", "out", 

88 "--transfer", "foo"], expected) 

89 

90 def test_ingestTask(self): 

91 """Test the ingest task argument""" 

92 expected = makeExpectedKwargs(repo="here", output_run="out", ingest_task="foo.bar.baz") 

93 self.run_test(["ingest-raws", "here", 

94 "--output-run", "out", 

95 "--ingest-task", "foo.bar.baz"], expected) 

96 

97 

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

99 unittest.main()