Coverage for tests / test_script_utils.py: 29%

19 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-28 08:44 +0000

1# This file is part of pipe_base. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (https://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 software is dual licensed under the GNU General Public License and also 

10# under a 3-clause BSD license. Recipients may choose which of these licenses 

11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt, 

12# respectively. If you choose the GPL option then the following text applies 

13# (but note that there is still no warranty even if you opt for BSD instead): 

14# 

15# This program is free software: you can redistribute it and/or modify 

16# it under the terms of the GNU General Public License as published by 

17# the Free Software Foundation, either version 3 of the License, or 

18# (at your option) any later version. 

19# 

20# This program is distributed in the hope that it will be useful, 

21# but WITHOUT ANY WARRANTY; without even the implied warranty of 

22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

23# GNU General Public License for more details. 

24# 

25# You should have received a copy of the GNU General Public License 

26# along with this program. If not, see <https://www.gnu.org/licenses/>. 

27 

28"""Tests for scripts/utils.py functions.""" 

29 

30import logging 

31import unittest 

32 

33from lsst.pipe.base.script.utils import filter_by_existence 

34 

35 

36class FilterByExistenceTestCase(unittest.TestCase): 

37 """Test filter_by_existence function.""" 

38 

39 def setUp(self): 

40 # Currently function itself does not need real DatasetRefs. 

41 # Only the butler calls requires DatasetRefs, but butler 

42 # is being mocked in these tests. So using strings in place 

43 # of DatasetRefs. 

44 self.orig_refs = [f"{i:05}" for i in range(1, 11)] 

45 self.mock_exists = {} 

46 for i in range(1, 11): 

47 self.mock_exists[f"{i:05}"] = True if i % 3 == 0 else False 

48 self.filtered_refs = [f"{i:05}" for i in range(1, 11) if i % 3 != 0] 

49 

50 def test_success(self): 

51 butler_mock = unittest.mock.Mock() 

52 butler_mock._datastore.knows_these.return_value = self.mock_exists 

53 with self.assertLogs(logging.getLogger("lsst.pipe.base"), level="VERBOSE") as cm: 

54 filtered = filter_by_existence(butler_mock, self.orig_refs) 

55 self.assertCountEqual(self.filtered_refs, filtered) 

56 log_messages = " ".join(cm.output) 

57 self.assertIn("Filtering out datasets already known to the target butler", log_messages) 

58 self.assertIn("number of datasets to transfer", log_messages) 

59 

60 

61if __name__ == "__main__": 

62 unittest.main()