Coverage for tests/test_get_caller_name.py: 31%
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
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
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 sys
13import unittest
15import lsst.utils.tests
16from lsst.utils import get_caller_name
19class GetCallerNameTestCase(unittest.TestCase):
20 """Test get_caller_name
22 Warning: due to the different ways this can be run
23 (e.g. directly or py.test), the module name can be one of two different
24 things.
25 """
27 def test_free_function(self):
28 def test_func():
29 return get_caller_name(1)
31 result = test_func()
32 self.assertEqual(result, "{}.test_func".format(__name__))
34 def test_instance_method(self):
35 class TestClass:
36 def run(self):
37 return get_caller_name(1)
39 tc = TestClass()
40 result = tc.run()
41 self.assertEqual(result, "{}.TestClass.run".format(__name__))
43 def test_class_method(self):
44 class TestClass:
45 @classmethod
46 def run(cls):
47 return get_caller_name(1)
49 tc = TestClass()
50 result = tc.run()
51 self.assertEqual(result, "{}.TestClass.run".format(__name__))
53 def test_skip(self):
54 def test_func(skip):
55 return get_caller_name(skip)
57 result = test_func(2)
58 self.assertEqual(result, "{}.GetCallerNameTestCase.test_skip".format(__name__))
60 result = test_func(2000000) # use a large number to avoid details of how the test is run
61 self.assertEqual(result, "")
64def setup_module(module):
65 lsst.utils.tests.init()
68if __name__ == "__main__": 68 ↛ 69line 68 didn't jump to line 69, because the condition on line 68 was never true
69 setup_module(sys.modules[__name__])
70 unittest.main()