Coverage for tests/test_analysisTool.py: 50%

46 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-24 03:44 -0700

1# This file is part of analysis_tools. 

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 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 

22from unittest import TestCase, main 

23 

24import lsst.pex.config as pexConfig 

25import lsst.utils.tests 

26from lsst.analysis.tools.interfaces import AnalysisTool 

27 

28 

29class NamedTool(AnalysisTool): 

30 name = pexConfig.Field[str](doc="Name", default="") 

31 

32 

33class A(NamedTool): 

34 pass 

35 

36 

37class B(NamedTool): 

38 def finalize(self): 

39 super().finalize() 

40 self.name += "B" 

41 

42 

43class C(B): 

44 # Override the default finalize to show that it does get called just once 

45 # at the end. This should not be implemented normally. 

46 def _baseFinalize(self) -> None: 

47 self.name += "_final" 

48 

49 

50class D(A, C): 

51 def finalize(self): 

52 super().finalize() 

53 self.name += "D" 

54 

55 

56class E(C, A): 

57 def finalize(self): 

58 super().finalize() 

59 self.name += "E" 

60 

61 

62class FinalizeTestCase(TestCase): 

63 """Test that finalize method properly calls through the MRO, and that 

64 it appropriately calls the base finalize once, at the end. 

65 """ 

66 

67 def setUp(self) -> None: 

68 super().setUp() 

69 self.a = A() 

70 self.c = C() 

71 self.d = D() 

72 self.e = E() 

73 

74 def testFinalize(self): 

75 self.a.finalize() 

76 self.assertEqual(self.a.name, "") 

77 self.c.finalize() 

78 self.assertEqual(self.c.name, "B_final") 

79 self.d.finalize() 

80 self.assertEqual(self.d.name, "BD_final") 

81 self.e.finalize() 

82 self.assertEqual(self.e.name, "BE_final") 

83 

84 

85class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase): 

86 pass 

87 

88 

89def setup_module(module): 

90 lsst.utils.tests.init() 

91 

92 

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

94 lsst.utils.tests.init() 

95 main()