Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# 

2# Developed for the LSST Data Management System. 

3# This product includes software developed by the LSST Project 

4# (https://www.lsst.org). 

5# See the COPYRIGHT file at the top-level directory of this distribution 

6# for details of code ownership. 

7# 

8# This program is free software: you can redistribute it and/or modify 

9# it under the terms of the GNU General Public License as published by 

10# the Free Software Foundation, either version 3 of the License, or 

11# (at your option) any later version. 

12# 

13# This program is distributed in the hope that it will be useful, 

14# but WITHOUT ANY WARRANTY; without even the implied warranty of 

15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

16# GNU General Public License for more details. 

17# 

18# You should have received a copy of the GNU General Public License 

19# along with this program. If not, see <https://www.gnu.org/licenses/>. 

20# 

21 

22import sys 

23import unittest 

24import itertools 

25 

26import lsst.utils.tests 

27 

28 

29numCalls = 0 # Number of times testMethodDecorator gets called 

30 

31 

32@lsst.utils.tests.classParameters( 

33 word=["one", "two", "three", "four"], 

34 length=[3, 3, 5, 4] 

35) 

36class DecoratorTestCase(lsst.utils.tests.TestCase): 

37 """Test methodParameters and classParameters decorators""" 

38 def setUp(self): 

39 self.numCalls = 0 

40 self.methodDecorator = False # testMethodDecorator fired 

41 

42 def testClassDecorator(self): 

43 self.assertEqual(len(self.word), self.length) 

44 self.assertEqual(self.__class__.__name__, f"DecoratorTestCase_{self.word}_{self.length}") 

45 

46 @lsst.utils.tests.methodParameters( 

47 xx=[1, 2, 3], 

48 yy=[9, 8, 7], 

49 ) 

50 def testMethodDecorator(self, xx, yy): 

51 self.methodDecorator = True 

52 self.assertEqual(xx + yy, 10) 

53 self.numCalls += 1 

54 

55 def tearDown(self): 

56 if self.methodDecorator: 

57 self.assertEqual(self.numCalls, 3) 

58 

59 

60@lsst.utils.tests.classParametersProduct( 

61 word=["one", "two"], 

62 number=[3, 4] 

63) 

64class DecoratorProductTestCase(lsst.utils.tests.TestCase): 

65 """Test methodParametersProduct and classParametersProduct decorators""" 

66 def setUp(self): 

67 self.combinations = set() 

68 self.methodDecorator = False # testMethodDecorator fired 

69 

70 def testClassDecorator(self): 

71 self.assertEqual(self.__class__.__name__, f"DecoratorProductTestCase_{self.word}_{self.number}") 

72 

73 @lsst.utils.tests.methodParametersProduct( 

74 xx=[1, 2, 3], 

75 yy=[9, 8], 

76 ) 

77 def testMethodDecorator(self, xx, yy): 

78 self.methodDecorator = True 

79 self.combinations.add((xx, yy)) 

80 

81 def tearDown(self): 

82 if self.methodDecorator: 

83 self.assertEqual(len(self.combinations), 6) 

84 for xx, yy in itertools.product((1, 2, 3), (9, 8)): 

85 self.assertIn((xx, yy), self.combinations) 

86 

87 

88def testDecorators(): 

89 world = globals() 

90 assert "DecoratorTestCase_one_3" in world 

91 assert "DecoratorTestCase_two_3" in world 

92 assert "DecoratorTestCase_three_5" in world 

93 assert "DecoratorTestCase_four_4" in world 

94 

95 assert "DecoratorProductTestCase_one_3" in world 

96 assert "DecoratorProductTestCase_one_4" in world 

97 assert "DecoratorProductTestCase_two_3" in world 

98 assert "DecoratorProductTestCase_two_4" in world 

99 

100 

101class TestMemory(lsst.utils.tests.MemoryTestCase): 

102 pass 

103 

104 

105def setup_module(module): 

106 lsst.utils.tests.init() 

107 

108 

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

110 module = sys.modules[__name__] 

111 setup_module(module) 

112 testDecorators() 

113 unittest.main()