Coverage for tests/testMethodRegistry.py : 53%

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
1from __future__ import with_statement
2from builtins import object
3import unittest
4import lsst.utils.tests
5from lsst.sims.catalogs.decorators import register_class, register_method
8def setup_module(module):
9 lsst.utils.tests.init()
12@register_class
13class ClassA(object):
15 def call(self, key):
16 return self._methodRegistry[key](self)
18 @register_method('a')
19 def _a_method(self):
20 return 'a'
23@register_class
24class ClassB(ClassA):
26 @register_method('b')
27 def _b_method(self):
28 return 'b'
31@register_class
32class ClassC(ClassB):
34 @register_method('c')
35 def _c_method(self):
36 return 'c'
39@register_class
40class ClassD(ClassA):
42 @register_method('d')
43 def _d_method(self):
44 return 'd'
47class MethodRegistryTestCase(unittest.TestCase):
49 def testMethodInheritance(self):
50 """
51 Test that the register_class and register_method decorators
52 behave appropriately and preserve inheritance.
53 """
55 aa = ClassA()
56 self.assertEqual(aa.call('a'), 'a')
58 # below, we test to make sure that methods which
59 # should not be in ClassA's _methodRegistry are not
60 # spuriously added to the registry
61 self.assertRaises(KeyError, aa.call, 'b')
62 self.assertRaises(KeyError, aa.call, 'c')
63 self.assertRaises(KeyError, aa.call, 'd')
65 bb = ClassB()
66 self.assertEqual(bb.call('a'), 'a')
67 self.assertEqual(bb.call('b'), 'b')
68 self.assertRaises(KeyError, bb.call, 'c')
69 self.assertRaises(KeyError, bb.call, 'd')
71 cc = ClassC()
72 self.assertEqual(cc.call('a'), 'a')
73 self.assertEqual(cc.call('b'), 'b')
74 self.assertEqual(cc.call('c'), 'c')
75 self.assertRaises(KeyError, cc.call, 'd')
77 dd = ClassD()
78 self.assertEqual(dd.call('a'), 'a')
79 self.assertEqual(dd.call('d'), 'd')
80 self.assertRaises(KeyError, dd.call, 'b')
81 self.assertRaises(KeyError, dd.call, 'c')
84class MemoryTestClass(lsst.utils.tests.MemoryTestCase):
85 pass
87if __name__ == "__main__": 87 ↛ 88line 87 didn't jump to line 88, because the condition on line 87 was never true
88 lsst.utils.tests.init()
89 unittest.main()