def test_no_lock_clone_handler(self): """ clone handler with locking=False (so 'class' is in its dict) """ lcd = LCDict() expected = self.get_expected_starting_dict() self.assertEqual(lcd, expected) lcd.add_stdout_handler('con', level='WARNING', formatter='msg') lcd.clone_handler(clone='con2', handler='con') # lcd.dump() # | DEBUG comment out self.assertEqual( lcd['handlers'], { 'con': { 'class': 'logging.StreamHandler', 'formatter': 'msg', 'level': 'WARNING', 'stream': 'ext://sys.stdout' }, 'con2': { 'class': 'logging.StreamHandler', 'formatter': 'msg', 'level': 'WARNING', 'stream': 'ext://sys.stdout' } })
def test_root_handlers_lock(self): """ DO add handlers to root, locking=True """ lcd = LCDict(attach_handlers_to_root=True, locking=True) self.assertEqual(lcd.locking, True) self.assertEqual(lcd.attach_handlers_to_root, True) # lcd.dump() # | DEBUG comment out expected = self.get_expected_starting_dict() self.assertEqual(lcd, expected) # No formatters, use default lcd.add_stderr_handler('console', level='WARNING').add_file_handler( 'default_file', filename='blather.log', formatter='process_time_logger_level_msg') # lcd.dump() # | DEBUG comment out self.assertEqual( lcd['handlers'], { 'console': { '()': 'ext://prelogging.LockingStreamHandler', 'create_lock': True, 'level': 'WARNING', 'stream': 'ext://sys.stderr' }, 'default_file': { '()': 'ext://prelogging.LockingFileHandler', 'create_lock': True, 'delay': False, 'filename': 'blather.log', 'formatter': 'process_time_logger_level_msg', # 'level': 'NOTSET', 'mode': 'a' } }) lcd.clone_handler(clone='con2', handler='console') # lcd.dump() # | DEBUG comment out self.assertEqual( lcd['handlers'], { 'con2': { '()': 'ext://prelogging.LockingStreamHandler', 'create_lock': True, 'level': 'WARNING', 'stream': 'ext://sys.stderr' }, 'console': { '()': 'ext://prelogging.LockingStreamHandler', 'create_lock': True, 'level': 'WARNING', 'stream': 'ext://sys.stderr' }, 'default_file': { '()': 'ext://prelogging.LockingFileHandler', 'create_lock': True, 'delay': False, 'filename': 'blather.log', 'formatter': 'process_time_logger_level_msg', # 'level': 'NOTSET', 'mode': 'a' } }) # For more coverage (locking_handlers.py from 46% to 60%) lcd.config(disable_existing_loggers=True)