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 prune-datasets subcommand. 

23""" 

24 

25import unittest 

26from unittest.mock import patch 

27 

28from lsst.daf.butler.cli.butler import cli as butlerCli 

29from lsst.daf.butler.cli.utils import clickResultMsg, LogCliRunner 

30 

31 

32class AssociateTestCase(unittest.TestCase): 

33 """Tests the ``associate`` ``butler`` subcommand. 

34 

35 ``script.associate`` contains no logic, so instead of mocking the 

36 internals, just mock the call to that function to test for expected inputs 

37 and input types. 

38 """ 

39 

40 def setUp(self): 

41 self.runner = LogCliRunner() 

42 

43 @patch("lsst.daf.butler.script.associate") 

44 def test_defaults(self, mockAssociate): 

45 """Test the expected default values & types for optional options. 

46 """ 

47 result = self.runner.invoke( 

48 butlerCli, ["associate", "myRepo", "myCollection"]) 

49 self.assertEqual(result.exit_code, 0, clickResultMsg(result)) 

50 mockAssociate.assert_called_once_with( 

51 repo="myRepo", 

52 collection="myCollection", 

53 dataset_type=tuple(), 

54 collections=tuple(), 

55 where=None, 

56 find_first=False 

57 ) 

58 

59 @patch("lsst.daf.butler.script.associate") 

60 def test_values(self, mockAssociate): 

61 """Test expected values & types when passing in options. 

62 """ 

63 result = self.runner.invoke( 

64 butlerCli, ["associate", "myRepo", "myCollection", 

65 "--dataset-type", "myDatasetType", 

66 "--collections", "myCollection,otherCollection", 

67 "--where", "'a=b'", 

68 "--find-first"]) 

69 self.assertEqual(result.exit_code, 0, clickResultMsg(result)) 

70 mockAssociate.assert_called_once_with( 

71 repo="myRepo", 

72 collection="myCollection", 

73 dataset_type=("myDatasetType",), 

74 collections=("myCollection", "otherCollection"), 

75 where="'a=b'", 

76 find_first=True 

77 ) 

78 

79 

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

81 unittest.main()