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 the daf_butler shared CLI options. 

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 

31from lsst.daf.butler.cli.opt import directory_argument, repo_argument 

32 

33 

34class MockerTestCase(unittest.TestCase): 

35 

36 def test_callMock(self): 

37 """Test that a mocked subcommand calls the Mocker and can be verified. 

38 """ 

39 runner = click.testing.CliRunner(env=mockEnvVar) 

40 result = runner.invoke(butler.cli, ["create", "repo"]) 

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

42 Mocker.mock.assert_called_with(repo="repo", config_file=None, standalone=False, override=False, 

43 outfile=None) 

44 

45 

46class ArgumentHelpGeneratorTestCase(unittest.TestCase): 

47 

48 @staticmethod 

49 @click.command() 

50 # Use custom help in the arguments so that any changes to default help text 

51 # do not break this test unnecessarily. 

52 @repo_argument(help="repo help text") 

53 @directory_argument(help="directory help text") 

54 def cli(): 

55 pass 

56 

57 def test_help(self): 

58 """Tests `utils.addArgumentHelp` and its use in repo_argument and 

59 directory_argument; verifies that the argument help gets added to the 

60 command fucntion help, and that it's added in the correct order. See 

61 addArgumentHelp for more details.""" 

62 runner = click.testing.CliRunner() 

63 result = runner.invoke(ArgumentHelpGeneratorTestCase.cli, ["--help"]) 

64 expected = """Usage: cli [OPTIONS] [REPO] [DIRECTORY] 

65 

66 directory help text 

67 

68 repo help text 

69 

70Options: 

71 --help Show this message and exit. 

72""" 

73 self.assertIn(expected, result.output) 

74 

75 

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

77 unittest.main()