Hide keyboard shortcuts

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# 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# (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# Use of this source code is governed by a 3-clause BSD-style 

10# license that can be found in the LICENSE file. 

11 

12"""Simple unit test for Task logging. 

13""" 

14 

15import logging 

16import unittest 

17 

18from lsst.utils.logging import getLogger 

19 

20 

21class TestLogging(unittest.TestCase): 

22 

23 def testLogLevels(self): 

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

25 

26 root = getLogger() 

27 

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

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

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

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

32 

33 def testLogCommands(self): 

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

35 

36 root = getLogger() 

37 

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

39 root.trace("Trace") 

40 root.debug("Debug") 

41 root.verbose("Verbose") 

42 root.info("Info") 

43 root.warning("Warning") 

44 root.fatal("Fatal") 

45 root.critical("Critical") 

46 root.error("Error") 

47 

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

49 

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

51 # "Level N" and comes from this file (and not the logging.py). 

52 for record in cm.records: 

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

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

55 

56 with self.assertLogs(level=root.DEBUG) as cm: 

57 # Should only issue the INFO message. 

58 with root.temporary_log_level(root.INFO): 

59 root.info("Info") 

60 root.debug("Debug") 

61 self.assertEqual(len(cm.records), 1) 

62 

63 child = root.getChild("child") 

64 self.assertEqual(child.getEffectiveLevel(), root.getEffectiveLevel()) 

65 child.setLevel(root.DEBUG) 

66 self.assertNotEqual(child.getEffectiveLevel(), root.getEffectiveLevel()) 

67 

68 

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

70 unittest.main()