Coverage for tests/test_get_caller_name.py: 31%

37 statements  

« prev     ^ index     » next       coverage.py v6.4, created at 2022-05-25 10:15 +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. 

11 

12import sys 

13import unittest 

14 

15import lsst.utils.tests 

16from lsst.utils import get_caller_name 

17 

18 

19class GetCallerNameTestCase(unittest.TestCase): 

20 """Test get_caller_name 

21 

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 """ 

26 

27 def test_free_function(self): 

28 def test_func(): 

29 return get_caller_name(1) 

30 

31 result = test_func() 

32 self.assertEqual(result, "{}.test_func".format(__name__)) 

33 

34 def test_instance_method(self): 

35 class TestClass: 

36 def run(self): 

37 return get_caller_name(1) 

38 

39 tc = TestClass() 

40 result = tc.run() 

41 self.assertEqual(result, "{}.TestClass.run".format(__name__)) 

42 

43 def test_class_method(self): 

44 class TestClass: 

45 @classmethod 

46 def run(cls): 

47 return get_caller_name(1) 

48 

49 tc = TestClass() 

50 result = tc.run() 

51 self.assertEqual(result, "{}.TestClass.run".format(__name__)) 

52 

53 def test_skip(self): 

54 def test_func(skip): 

55 return get_caller_name(skip) 

56 

57 result = test_func(2) 

58 self.assertEqual(result, "{}.GetCallerNameTestCase.test_skip".format(__name__)) 

59 

60 result = test_func(2000000) # use a large number to avoid details of how the test is run 

61 self.assertEqual(result, "") 

62 

63 

64def setup_module(module): 

65 lsst.utils.tests.init() 

66 

67 

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()