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.utils import to_upper 

30 

31 

32@click.command() 

33@click.option("--value", callback=to_upper) 

34def cli(value): 

35 click.echo(value) 

36 

37 

38class Suite(unittest.TestCase): 

39 

40 def test_isolated(self): 

41 """test the to_upper callback by itself""" 

42 ctx = "unused" 

43 param = "unused" 

44 self.assertEqual(to_upper(ctx, param, "debug"), "DEBUG") 

45 

46 def test_lowerToUpper(self): 

47 """test the to_upper callback in an option with a lowercase value""" 

48 runner = click.testing.CliRunner() 

49 result = runner.invoke(cli, ["--value", "debug"]) 

50 self.assertEqual(result.exit_code, 0) 

51 self.assertEqual(result.stdout, "DEBUG\n") 

52 

53 def test_upperToUpper(self): 

54 """test the to_upper callback in an option with a uppercase value""" 

55 runner = click.testing.CliRunner() 

56 result = runner.invoke(cli, ["--value", "DEBUG"]) 

57 self.assertEqual(result.exit_code, 0) 

58 self.assertEqual(result.stdout, "DEBUG\n") 

59 

60 def test_mixedToUpper(self): 

61 """test the to_upper callback in an option with a mixed-case value""" 

62 runner = click.testing.CliRunner() 

63 result = runner.invoke(cli, ["--value", "DeBuG"]) 

64 self.assertEqual(result.exit_code, 0) 

65 self.assertEqual(result.stdout, "DEBUG\n") 

66 

67 

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

69 unittest.main()