Coverage for tests/test_logging.py: 31%

28 statements  

« prev     ^ index     » next       coverage.py v6.4.1, created at 2022-06-18 02:36 -0700

1# This file is part of pipe_base. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (http://www.lsst.org). 

6# See the COPYRIGHT file at the top-level directory of this distribution 

7# for details of code ownership. 

8# 

9# This program is free software: you can redistribute it and/or modify 

10# it under the terms of the GNU General Public License as published by 

11# the Free Software Foundation, either version 3 of the License, or 

12# (at your option) any later version. 

13# 

14# This program is distributed in the hope that it will be useful, 

15# but WITHOUT ANY WARRANTY; without even the implied warranty of 

16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

17# GNU General Public License for more details. 

18# 

19# You should have received a copy of the GNU General Public License 

20# along with this program. If not, see <http://www.gnu.org/licenses/>. 

21 

22"""Simple unit test for Task logging. 

23""" 

24 

25import logging 

26import unittest 

27 

28from lsst.pipe.base import getTaskLogger 

29 

30 

31class TestLogging(unittest.TestCase): 

32 def testLogLevels(self): 

33 """Check that the new log levels look reasonable.""" 

34 

35 root = getTaskLogger() 

36 

37 self.assertEqual(root.DEBUG, logging.DEBUG) 

38 self.assertGreater(root.VERBOSE, logging.DEBUG) 

39 self.assertLess(root.VERBOSE, logging.INFO) 

40 self.assertLess(root.TRACE, logging.DEBUG) 

41 

42 def testLogCommands(self): 

43 """Check that all the log commands work.""" 

44 

45 root = getTaskLogger() 

46 

47 with self.assertLogs(level=root.TRACE) as cm: 

48 root.trace("Trace") 

49 root.debug("Debug") 

50 root.verbose("Verbose") 

51 root.info("Info") 

52 root.warning("Warning") 

53 root.fatal("Fatal") 

54 root.critical("Critical") 

55 root.error("Error") 

56 

57 self.assertEqual(len(cm.records), 8) 

58 

59 # Check that each record has an explicit level name rather than 

60 # "Level N" and comes from this file (and not the task_logging.py). 

61 for record in cm.records: 

62 self.assertRegex(record.levelname, "^[A-Z]+$") 

63 self.assertEqual(record.filename, "test_logging.py") 

64 

65 

66if __name__ == "__main__": 66 ↛ 67line 66 didn't jump to line 67, because the condition on line 66 was never true

67 unittest.main()