Coverage for tests/test_decorators.py: 43%
56 statements
« prev ^ index » next coverage.py v7.2.1, created at 2023-03-13 02:35 +0000
« prev ^ index » next coverage.py v7.2.1, created at 2023-03-13 02:35 +0000
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.
12import itertools
13import sys
14import unittest
16import lsst.utils.tests
18numCalls = 0 # Number of times testMethodDecorator gets called
21@lsst.utils.tests.classParameters(word=["one", "two", "three", "four"], length=[3, 3, 5, 4])
22class DecoratorTestCase(lsst.utils.tests.TestCase):
23 """Test methodParameters and classParameters decorators"""
25 def setUp(self):
26 self.numCalls = 0
27 self.methodDecorator = False # testMethodDecorator fired
29 def testClassDecorator(self):
30 self.assertEqual(len(self.word), self.length)
31 self.assertEqual(self.__class__.__name__, f"DecoratorTestCase_{self.word}_{self.length}")
33 @lsst.utils.tests.methodParameters(
34 xx=[1, 2, 3],
35 yy=[9, 8, 7],
36 )
37 def testMethodDecorator(self, xx, yy):
38 self.methodDecorator = True
39 self.assertEqual(xx + yy, 10)
40 self.numCalls += 1
42 def tearDown(self):
43 if self.methodDecorator:
44 self.assertEqual(self.numCalls, 3)
47@lsst.utils.tests.classParametersProduct(word=["one", "two"], number=[3, 4])
48class DecoratorProductTestCase(lsst.utils.tests.TestCase):
49 """Test methodParametersProduct and classParametersProduct decorators"""
51 def setUp(self):
52 self.combinations = set()
53 self.methodDecorator = False # testMethodDecorator fired
55 def testClassDecorator(self):
56 self.assertEqual(self.__class__.__name__, f"DecoratorProductTestCase_{self.word}_{self.number}")
58 @lsst.utils.tests.methodParametersProduct(
59 xx=[1, 2, 3],
60 yy=[9, 8],
61 )
62 def testMethodDecorator(self, xx, yy):
63 self.methodDecorator = True
64 self.combinations.add((xx, yy))
66 def tearDown(self):
67 if self.methodDecorator:
68 self.assertEqual(len(self.combinations), 6)
69 for xx, yy in itertools.product((1, 2, 3), (9, 8)):
70 self.assertIn((xx, yy), self.combinations)
73def testDecorators():
74 world = globals()
75 assert "DecoratorTestCase_one_3" in world
76 assert "DecoratorTestCase_two_3" in world
77 assert "DecoratorTestCase_three_5" in world
78 assert "DecoratorTestCase_four_4" in world
80 assert "DecoratorProductTestCase_one_3" in world
81 assert "DecoratorProductTestCase_one_4" in world
82 assert "DecoratorProductTestCase_two_3" in world
83 assert "DecoratorProductTestCase_two_4" in world
86class TestMemory(lsst.utils.tests.MemoryTestCase):
87 pass
90def setup_module(module):
91 lsst.utils.tests.init()
94if __name__ == "__main__": 94 ↛ 95line 94 didn't jump to line 95, because the condition on line 94 was never true
95 module = sys.modules[__name__]
96 setup_module(module)
97 testDecorators()
98 unittest.main()