Coverage for tests/test_cliCmdRemoveRuns.py: 35%

Shortcuts 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

39 statements  

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 remove-runs subcommand. 

23""" 

24 

25 

26import os 

27import unittest 

28 

29from lsst.daf.butler.cli import butler 

30from lsst.daf.butler.cli.cmd._remove_runs import ( 

31 abortedMsg, 

32 didRemoveDatasetsMsg, 

33 didRemoveRunsMsg, 

34 noRunCollectionsMsg, 

35 removedRunsMsg, 

36 willRemoveDatasetsMsg, 

37 willRemoveRunsMsg, 

38) 

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

40from lsst.daf.butler.tests.utils import MetricTestRepo 

41 

42TESTDIR = os.path.abspath(os.path.dirname(__file__)) 

43 

44 

45class RemoveCollectionTest(unittest.TestCase): 

46 """Test the butler remove-runs command.""" 

47 

48 def setUp(self): 

49 self.runner = LogCliRunner() 

50 

51 def test_removeRuns(self): 

52 with self.runner.isolated_filesystem(): 

53 root = "repo" 

54 MetricTestRepo(root, configFile=os.path.join(TESTDIR, "config/basic/butler.yaml")) 

55 

56 # Execute cmd but say no, check for expected outputs. 

57 result = self.runner.invoke(butler.cli, ["remove-runs", root, "ingest*"], input="no") 

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

59 self.assertIn(willRemoveRunsMsg, result.output) 

60 self.assertIn(willRemoveDatasetsMsg, result.output) 

61 self.assertIn(abortedMsg, result.output) 

62 

63 # ...say yes 

64 result = self.runner.invoke(butler.cli, ["remove-runs", root, "ingest*"], input="yes") 

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

66 self.assertIn(willRemoveRunsMsg, result.output) 

67 self.assertIn(willRemoveDatasetsMsg, result.output) 

68 self.assertIn(removedRunsMsg, result.output) 

69 

70 # now they've been deleted, try again and check for "none found" 

71 result = self.runner.invoke(butler.cli, ["remove-runs", root, "ingest*"]) 

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

73 self.assertIn(noRunCollectionsMsg, result.output) 

74 

75 # remake the repo and check --no-confirm option 

76 root = "repo1" 

77 MetricTestRepo(root, configFile=os.path.join(TESTDIR, "config/basic/butler.yaml")) 

78 

79 # Execute cmd but say no, check for expected outputs. 

80 result = self.runner.invoke(butler.cli, ["remove-runs", root, "ingest*", "--no-confirm"]) 

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

82 self.assertIn(didRemoveRunsMsg, result.output) 

83 self.assertIn(didRemoveDatasetsMsg, result.output) 

84 

85 # Execute cmd looking for a non-existant collection 

86 result = self.runner.invoke(butler.cli, ["remove-runs", root, "foo"]) 

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

88 self.assertIn(noRunCollectionsMsg, result.output) 

89 

90 

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

92 unittest.main()