Coverage for tests/test_get_caller_name.py : 31%

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#
22import sys
23import unittest
25import lsst.utils.tests
26from lsst.utils import get_caller_name
29class GetCallerNameTestCase(unittest.TestCase):
30 """Test get_caller_name
32 Warning: due to the different ways this can be run
33 (e.g. directly or py.test), the module name can be one of two different
34 things.
35 """
37 def test_free_function(self):
38 def test_func():
39 return get_caller_name(1)
41 result = test_func()
42 self.assertEqual(result, "{}.test_func".format(__name__))
44 def test_instance_method(self):
45 class TestClass:
46 def run(self):
47 return get_caller_name(1)
49 tc = TestClass()
50 result = tc.run()
51 self.assertEqual(result, "{}.TestClass.run".format(__name__))
53 def test_class_method(self):
54 class TestClass:
55 @classmethod
56 def run(cls):
57 return get_caller_name(1)
59 tc = TestClass()
60 result = tc.run()
61 self.assertEqual(result, "{}.TestClass.run".format(__name__))
63 def test_skip(self):
64 def test_func(skip):
65 return get_caller_name(skip)
67 result = test_func(2)
68 self.assertEqual(result, "{}.GetCallerNameTestCase.test_skip".format(__name__))
70 result = test_func(2000000) # use a large number to avoid details of how the test is run
71 self.assertEqual(result, "")
74def setup_module(module):
75 lsst.utils.tests.init()
78if __name__ == "__main__": 78 ↛ 79line 78 didn't jump to line 79, because the condition on line 78 was never true
79 setup_module(sys.modules[__name__])
80 unittest.main()