Coverage for python/lsst/pex/config/configurableActions/tests.py: 76%
38 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-10 09:56 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-10 09:56 +0000
1# This file is part of pex_config.
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 <https://www.gnu.org/licenses/>.
21from __future__ import annotations
23__all__ = (
24 "ActionTest1",
25 "ActionTest2",
26 "ActionTest3",
27 "TestDivideAction",
28 "TestSingleColumnAction",
29 "TestConfig",
30)
32from lsst.pex.config import Config, Field
34from ._configurableAction import ConfigurableAction
35from ._configurableActionField import ConfigurableActionField
36from ._configurableActionStructField import ConfigurableActionStructField
39class ActionTest1(ConfigurableAction):
40 """Configurable Action Test 1."""
42 var = Field(doc="test field", dtype=int, default=0)
44 def __call__(self):
45 return self.var
47 def validate(self):
48 assert self.var is not None
51class ActionTest2(ConfigurableAction):
52 """Configurable Action Test 2."""
54 var = Field(doc="test field", dtype=int, default=1)
56 def __call__(self):
57 return self.var
59 def validate(self):
60 assert self.var is not None
63class ActionTest3(ConfigurableAction):
64 """Configurable Action Test 3."""
66 var = Field(doc="test field", dtype=int, default=3)
68 def __call__(self):
69 return self.var
71 def validate(self):
72 assert self.var is not None
75class TestDivideAction(ConfigurableAction):
76 """Configurable action that can divide."""
78 colA = ConfigurableActionField(doc="Action used to calculate numerator", default=None)
79 colB = ConfigurableActionField(doc="Action used to calculate divisor", default=None)
81 def __call__(self, arg):
82 return self.colA(arg) / self.colB(arg)
84 def validate(self):
85 assert self.colA is not None and self.colB is not None
88class TestSingleColumnAction(ConfigurableAction):
89 """Configurable action that can return a single column."""
91 column = Field(doc="Column to load for this action", dtype=str, optional=False)
93 def __call__(self, arg, **kwargs):
94 return arg[self.column]
97class TestConfig(Config):
98 """Test configuration for configurable action tests."""
100 actions = ConfigurableActionStructField(doc="Actions to be tested", default=None)
101 singleAction = ConfigurableActionField(doc="A configurable action", default=None)