Coverage for tests/test_analysisTool.py: 45%
62 statements
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-15 13:33 +0000
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-15 13:33 +0000
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/>.
22from unittest import TestCase, main
24import lsst.pex.config as pexConfig
25import lsst.utils.tests
27# This is needed to work around a bug with pyproj when it is imported
28# inside a function, in this case through a pipeline
29import skyproj # noqa: F401
30from lsst.analysis.tools.interfaces import AnalysisTool
33class NamedTool(AnalysisTool):
34 name = pexConfig.Field[str](doc="Name", default="")
37class A(NamedTool):
38 pass
41class B(NamedTool):
42 def finalize(self):
43 super().finalize()
44 self.name += "B"
47class C(B):
48 # Override the default finalize to show that it does get called just once
49 # at the end. This should not be implemented normally.
50 def _baseFinalize(self) -> None:
51 self.name += "_final"
54class D(A, C):
55 def finalize(self):
56 super().finalize()
57 self.name += "D"
60class E(C, A):
61 def finalize(self):
62 super().finalize()
63 self.name += "E"
66class FinalizeTestCase(TestCase):
67 """Test that finalize method properly calls through the MRO, and that
68 it appropriately calls the base finalize once, at the end.
69 """
71 def setUp(self) -> None:
72 super().setUp()
73 self.a = A()
74 self.c = C()
75 self.d = D()
76 self.e = E()
78 def testFinalize(self):
79 self.a.finalize()
80 self.assertEqual(self.a.name, "")
81 self.c.finalize()
82 self.assertEqual(self.c.name, "B_final")
83 self.d.finalize()
84 self.assertEqual(self.d.name, "BD_final")
85 self.e.finalize()
86 self.assertEqual(self.e.name, "BE_final")
89class LoadFromPipelineTestCase(TestCase):
90 """Test that analysis tools can be loaded from a pipeline"""
92 def setUp(self) -> None:
93 super().setUp()
94 self.pipeline = "$ANALYSIS_TOOLS_DIR/pipelines/coaddQualityExtended.yaml"
96 def testLoadRelative(self) -> None:
97 # test that relative names can be loaded
98 tool = AnalysisTool.fromPipeline(self.pipeline, "shapeSizeDetRadiusVsCmodelMag")
99 self.assertIsNotNone(tool)
100 self.assertEqual(tool.mag_x, "cmodel_err") # type: ignore
101 self.assertEqual(tool.size_y, "shape_slot") # type: ignore
103 def testLoadAbs(self) -> None:
104 ...
105 # test that relative names can be loaded
106 tool = AnalysisTool.fromPipeline(self.pipeline, "atools.shapeSizeDetRadiusVsCmodelMag", fullpath=True)
107 self.assertIsNotNone(tool)
108 self.assertEqual(tool.mag_x, "cmodel_err") # type: ignore
109 self.assertEqual(tool.size_y, "shape_slot") # type: ignore
112class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase):
113 pass
116def setup_module(module):
117 lsst.utils.tests.init()
120if __name__ == "__main__": 120 ↛ 121line 120 didn't jump to line 121, because the condition on line 120 was never true
121 lsst.utils.tests.init()
122 main()