Coverage for tests/test_analysisTool.py: 44%
67 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-03-22 11:50 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-03-22 11:50 +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 TestMetricNameValidation(TestCase):
90 """Test that disallowed characters in measurement names are filtered."""
92 def testMinusNameFails(self):
93 tool = AnalysisTool()
94 with self.assertRaises(pexConfig.FieldValidationError):
95 tool.produce.metric.newNames = {"something": "not-allowed"}
98class LoadFromPipelineTestCase(TestCase):
99 """Test that analysis tools can be loaded from a pipeline"""
101 def setUp(self) -> None:
102 super().setUp()
103 self.pipeline = "$ANALYSIS_TOOLS_DIR/pipelines/coaddQualityExtended.yaml"
105 def testLoadRelative(self) -> None:
106 # test that relative names can be loaded
107 tool = AnalysisTool.fromPipeline(self.pipeline, "shapeSizeDetRadiusVsCmodelMag")
108 self.assertIsNotNone(tool)
109 self.assertEqual(tool.mag_x, "cmodel_err") # type: ignore
110 self.assertEqual(tool.size_y, "shape_slot") # type: ignore
112 def testLoadAbs(self) -> None:
113 ...
114 # test that relative names can be loaded
115 tool = AnalysisTool.fromPipeline(self.pipeline, "atools.shapeSizeDetRadiusVsCmodelMag", fullpath=True)
116 self.assertIsNotNone(tool)
117 self.assertEqual(tool.mag_x, "cmodel_err") # type: ignore
118 self.assertEqual(tool.size_y, "shape_slot") # type: ignore
121class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase):
122 pass
125def setup_module(module):
126 lsst.utils.tests.init()
129if __name__ == "__main__": 129 ↛ 130line 129 didn't jump to line 130, because the condition on line 129 was never true
130 lsst.utils.tests.init()
131 main()