Coverage for tests/test_decorators.py: 43%

Shortcuts 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

56 statements  

1# This file is part of utils. 

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# Use of this source code is governed by a 3-clause BSD-style 

10# license that can be found in the LICENSE file. 

11 

12import sys 

13import unittest 

14import itertools 

15 

16import lsst.utils.tests 

17 

18 

19numCalls = 0 # Number of times testMethodDecorator gets called 

20 

21 

22@lsst.utils.tests.classParameters( 

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

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

25) 

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

27 """Test methodParameters and classParameters decorators""" 

28 def setUp(self): 

29 self.numCalls = 0 

30 self.methodDecorator = False # testMethodDecorator fired 

31 

32 def testClassDecorator(self): 

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

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

35 

36 @lsst.utils.tests.methodParameters( 

37 xx=[1, 2, 3], 

38 yy=[9, 8, 7], 

39 ) 

40 def testMethodDecorator(self, xx, yy): 

41 self.methodDecorator = True 

42 self.assertEqual(xx + yy, 10) 

43 self.numCalls += 1 

44 

45 def tearDown(self): 

46 if self.methodDecorator: 

47 self.assertEqual(self.numCalls, 3) 

48 

49 

50@lsst.utils.tests.classParametersProduct( 

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

52 number=[3, 4] 

53) 

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

55 """Test methodParametersProduct and classParametersProduct decorators""" 

56 def setUp(self): 

57 self.combinations = set() 

58 self.methodDecorator = False # testMethodDecorator fired 

59 

60 def testClassDecorator(self): 

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

62 

63 @lsst.utils.tests.methodParametersProduct( 

64 xx=[1, 2, 3], 

65 yy=[9, 8], 

66 ) 

67 def testMethodDecorator(self, xx, yy): 

68 self.methodDecorator = True 

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

70 

71 def tearDown(self): 

72 if self.methodDecorator: 

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

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

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

76 

77 

78def testDecorators(): 

79 world = globals() 

80 assert "DecoratorTestCase_one_3" in world 

81 assert "DecoratorTestCase_two_3" in world 

82 assert "DecoratorTestCase_three_5" in world 

83 assert "DecoratorTestCase_four_4" in world 

84 

85 assert "DecoratorProductTestCase_one_3" in world 

86 assert "DecoratorProductTestCase_one_4" in world 

87 assert "DecoratorProductTestCase_two_3" in world 

88 assert "DecoratorProductTestCase_two_4" in world 

89 

90 

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

92 pass 

93 

94 

95def setup_module(module): 

96 lsst.utils.tests.init() 

97 

98 

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

100 module = sys.modules[__name__] 

101 setup_module(module) 

102 testDecorators() 

103 unittest.main()