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-collections subcommand. 

23""" 

24 

25import unittest 

26 

27import lsst.daf.butler 

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

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

30 

31 

32class PruneCollectionsTest(unittest.TestCase): 

33 

34 def setUp(self): 

35 self.runner = LogCliRunner() 

36 

37 def testPruneCollections(self): 

38 """Test removing a collection and run from a repository using the 

39 butler prune-collection subcommand.""" 

40 with self.runner.isolated_filesystem(): 

41 repoName = "myRepo" 

42 runName = "myRun" 

43 taggedName = "taggedCollection" 

44 

45 # Add the run and the tagged collection to the repo: 

46 result = self.runner.invoke(butlerCli, ["create", repoName]) 

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

48 lsst.daf.butler.Butler(repoName, run=runName, tags=[taggedName]) 

49 

50 # Verify the run and tag show up in query-collections: 

51 result = self.runner.invoke(butlerCli, ["query-collections", repoName]) 

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

53 self.assertIn(runName, result.output) 

54 self.assertIn(taggedName, result.output) 

55 

56 # Verify the tagged collection can be removed: 

57 result = self.runner.invoke(butlerCli, ["prune-collection", repoName, 

58 "--collection", taggedName, 

59 "--unstore"]) 

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

61 result = self.runner.invoke(butlerCli, ["query-collections", repoName]) 

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

63 self.assertIn(runName, result.output) 

64 self.assertNotIn(taggedName, result.output) 

65 

66 # Verify the run can be removed: 

67 result = self.runner.invoke(butlerCli, ["prune-collection", repoName, 

68 "--collection", runName, 

69 "--purge", 

70 "--unstore"]) 

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

72 self.assertNotIn(runName, result.output) 

73 self.assertNotIn(taggedName, 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()