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 convert 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 Mocker, mockEnvVar 

31 

32 

33def makeExpectedKwargs(**kwargs): 

34 expected = dict(skymap_name=None, 

35 skymap_config=None, 

36 calibs=None, 

37 reruns=[], 

38 transfer="auto", 

39 config_file=None) 

40 expected.update(kwargs) 

41 return expected 

42 

43 

44class Case(unittest.TestCase): 

45 

46 def run_test(self, inputs, expectedKwargs): 

47 """Test command line interaction with convert 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=mockEnvVar) 

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

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

61 Mocker.mock.assert_called_with(**expectedKwargs) 

62 

63 def test_repoInstrGen2root(self): 

64 """Test the most basic required arguments.""" 

65 expected = makeExpectedKwargs(repo="here", gen2root="from", instrument="a.b.c") 

66 self.run_test(["convert", "here", 

67 "--gen2root", "from", 

68 "--instrument", "a.b.c"], expected) 

69 

70 def test_all(self): 

71 """Test all the arguments.""" 

72 expected = dict(repo="here", gen2root="from", instrument="a.b.c", skymap_name="sky", 

73 skymap_config="/path/to/config", calibs="path/to/calib/repo", 

74 reruns=["one", "two", "three"], transfer="symlink", config_file="/path/to/config") 

75 self.run_test(["convert", "here", 

76 "--gen2root", "from", 

77 "--instrument", "a.b.c", 

78 "--skymap-name", "sky", 

79 "--skymap-config", "/path/to/config", 

80 "--calibs", "path/to/calib/repo", 

81 "--reruns", "one,two", 

82 "--reruns", "three", 

83 "--transfer", "symlink", 

84 "--config-file", "/path/to/config"], expected) 

85 

86 def test_missing(self): 

87 """test a missing argument""" 

88 with self.assertRaises(TypeError): 

89 self.run_test(["convert", "--gen2root", "from"]) 

90 

91 

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

93 unittest.main()