瀏覽代碼

add test to check that log_file is disabled
if logging is disabled

Signed-off-by: Soumik Dutta <shalearkane@gmail.com>

Soumik Dutta 2 年之前
父節點
當前提交
3d41ed3a34
共有 1 個文件被更改,包括 22 次插入0 次删除
  1. 22 0
      tests/unit/test_logger.py

+ 22 - 0
tests/unit/test_logger.py

@@ -284,6 +284,7 @@ def test_configure_logging_skips_syslog_if_interactive_console():
 
     module.configure_logging(console_log_level=logging.INFO)
 
+
 def test_configure_logging_skips_syslog_if_syslog_logging_is_disabled():
     flexmock(module).should_receive('add_custom_log_levels')
     flexmock(module.logging).DISABLED = module.DISABLED
@@ -301,6 +302,27 @@ def test_configure_logging_skips_syslog_if_syslog_logging_is_disabled():
     module.configure_logging(console_log_level=logging.INFO, syslog_log_level=logging.DISABLED)
 
 
+def test_configure_logging_skips_log_file_if_log_file_logging_is_disabled():
+    flexmock(module).should_receive('add_custom_log_levels')
+    flexmock(module.logging).DISABLED = module.DISABLED
+    flexmock(module).should_receive('Multi_stream_handler').and_return(
+        flexmock(setFormatter=lambda formatter: None, setLevel=lambda level: None)
+    )
+
+    # syslog skipped in non-interactive console if --log-file argument provided
+    flexmock(module).should_receive('interactive_console').and_return(False)
+    flexmock(module.logging).should_receive('basicConfig').with_args(
+        level=logging.INFO, handlers=tuple
+    )
+    flexmock(module.os.path).should_receive('exists').with_args('/dev/log').never()
+    flexmock(module.logging.handlers).should_receive('SysLogHandler').never()
+    flexmock(module.logging.handlers).should_receive('WatchedFileHandler').never()
+
+    module.configure_logging(
+        console_log_level=logging.INFO, log_file_log_level=logging.DISABLED, log_file='/tmp/logfile'
+    )
+
+
 def test_configure_logging_to_log_file_instead_of_syslog():
     flexmock(module).should_receive('add_custom_log_levels')
     flexmock(module.logging).ANSWER = module.ANSWER