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 split_commas 

30 

31 

32@click.command() 

33@click.option("--list-of-values", "-l", multiple=True, callback=split_commas) 

34def cli(list_of_values): 

35 click.echo(list_of_values) 

36 

37 

38class Suite(unittest.TestCase): 

39 

40 def test_separate(self): 

41 """test the split_commas callback by itself""" 

42 ctx = "unused" 

43 param = "unused" 

44 self.assertEqual(split_commas(ctx, param, ("one,two", "three,four")), # noqa E231 

45 ["one", "two", "three", "four"]) 

46 

47 def test_single(self): 

48 """test the split_commas callback in an option with one value""" 

49 runner = click.testing.CliRunner() 

50 result = runner.invoke(cli, ["-l", "one"]) 

51 self.assertEqual(result.exit_code, 0) 

52 self.assertEqual(result.stdout, "['one']\n") 

53 

54 def test_multiple(self): 

55 """test the split_commas callback in an option with two single 

56 values""" 

57 runner = click.testing.CliRunner() 

58 result = runner.invoke(cli, ["-l", "one", "-l", "two"]) 

59 self.assertEqual(result.exit_code, 0) 

60 self.assertEqual(result.stdout, "['one', 'two']\n") 

61 

62 def test_singlePair(self): 

63 """test the split_commas callback in an option with one pair of 

64 values""" 

65 runner = click.testing.CliRunner() 

66 result = runner.invoke(cli, ["-l", "one,two"]) 

67 self.assertEqual(result.exit_code, 0) 

68 self.assertEqual(result.stdout, "['one', 'two']\n") 

69 

70 def test_multiplePair(self): 

71 """test the split_commas callback in an option with two pairs of 

72 values""" 

73 runner = click.testing.CliRunner() 

74 result = runner.invoke(cli, ["-l", "one,two", "-l", "three,four"]) 

75 self.assertEqual(result.exit_code, 0) 

76 self.assertEqual(result.stdout, "['one', 'two', 'three', 'four']\n") 

77 

78 

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

80 unittest.main()