Coverage for python/lsst/pex/config/configurableActions/tests.py: 76%

38 statements  

« prev     ^ index     » next       coverage.py v7.2.5, created at 2023-05-11 10:00 +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 

22 

23__all__ = ( 

24 "ActionTest1", 

25 "ActionTest2", 

26 "ActionTest3", 

27 "TestDivideAction", 

28 "TestSingleColumnAction", 

29 "TestConfig", 

30) 

31 

32from lsst.pex.config import Config, Field 

33 

34from ._configurableAction import ConfigurableAction 

35from ._configurableActionField import ConfigurableActionField 

36from ._configurableActionStructField import ConfigurableActionStructField 

37 

38 

39class ActionTest1(ConfigurableAction): 

40 var = Field(doc="test field", dtype=int, default=0) 

41 

42 def __call__(self): 

43 return self.var 

44 

45 def validate(self): 

46 assert self.var is not None 

47 

48 

49class ActionTest2(ConfigurableAction): 

50 var = Field(doc="test field", dtype=int, default=1) 

51 

52 def __call__(self): 

53 return self.var 

54 

55 def validate(self): 

56 assert self.var is not None 

57 

58 

59class ActionTest3(ConfigurableAction): 

60 var = Field(doc="test field", dtype=int, default=3) 

61 

62 def __call__(self): 

63 return self.var 

64 

65 def validate(self): 

66 assert self.var is not None 

67 

68 

69class TestDivideAction(ConfigurableAction): 

70 colA = ConfigurableActionField(doc="Action used to calculate numerator", default=None) 

71 colB = ConfigurableActionField(doc="Action used to calculate divisor", default=None) 

72 

73 def __call__(self, arg): 

74 return self.colA(arg) / self.colB(arg) 

75 

76 def validate(self): 

77 assert self.colA is not None and self.colB is not None 

78 

79 

80class TestSingleColumnAction(ConfigurableAction): 

81 column = Field(doc="Column to load for this action", dtype=str, optional=False) 

82 

83 def __call__(self, arg, **kwargs): 

84 return arg[self.column] 

85 

86 

87class TestConfig(Config): 

88 actions = ConfigurableActionStructField(doc="Actions to be tested", default=None) 

89 singleAction = ConfigurableActionField(doc="A configurable action", default=None)