From 093aee290f26f31d6234e29775d5e03e55ca4c2e Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Mon, 12 Oct 2020 16:06:02 -0500 Subject: [PATCH] Add some basic tests for log_json config Make sure the default value is handled properly based on environment variables. Also checks the validation code based on whether or not json_logging is imported. --- notebook/tests/test_notebookapp.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/notebook/tests/test_notebookapp.py b/notebook/tests/test_notebookapp.py index d8543feed..7471459c1 100644 --- a/notebook/tests/test_notebookapp.py +++ b/notebook/tests/test_notebookapp.py @@ -190,6 +190,12 @@ class NotebookAppTests(NotebookTestBase): assert len(servers) >= 1 assert self.port in {info['port'] for info in servers} + def test_log_json_default(self): + assert self.notebook.log_json == False + + def test_validate_log_json(self): + assert self.notebook._validate_log_json(dict(value=False)) == False + # UNIX sockets aren't available on Windows. if not sys.platform.startswith('win'): @@ -201,3 +207,27 @@ if not sys.platform.startswith('win'): servers = list(notebookapp.list_running_servers()) assert len(servers) >= 1 assert self.sock in {info['sock'] for info in servers} + + +class NotebookAppJSONLoggingTests(NotebookTestBase): + """Tests for when json logging is enabled.""" + @classmethod + def setup_class(cls): + super(NotebookAppJSONLoggingTests, cls).setup_class() + try: + import json_logging + cls.json_logging_available = True + except ImportError: + cls.json_logging_available = False + + @classmethod + def get_patch_env(cls): + test_env = super(NotebookAppJSONLoggingTests, cls).get_patch_env() + test_env.update({'JUPYTER_ENABLE_JSON_LOGGING': 'true'}) + return test_env + + def test_log_json_enabled(self): + assert self.notebook.log_json == self.json_logging_available + + def test_validate_log_json(self): + assert self.notebook._validate_log_json(dict(value=True)) == self.json_logging_available