summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2019-02-07 14:24:37 +0100
committerMarcello Stanisci <stanisci.m@gmail.com>2019-02-07 14:24:37 +0100
commitb8165e39e441981e1de5f85e9871de443e7dbaae (patch)
tree9fbe95869163bbd5048f0a337a06d97278e43ae0
parent4f37ff122681b5c537e6b8ced56ac469470e80e4 (diff)
downloadtaler-util-b8165e39e441981e1de5f85e9871de443e7dbaae.tar.gz
taler-util-b8165e39e441981e1de5f85e9871de443e7dbaae.tar.bz2
taler-util-b8165e39e441981e1de5f85e9871de443e7dbaae.zip
4453. Test only manual loglevel setup.
-rwxr-xr-xpython/log/test_ut.py34
1 files changed, 29 insertions, 5 deletions
diff --git a/python/log/test_ut.py b/python/log/test_ut.py
index 2b973f5..83086e1 100755
--- a/python/log/test_ut.py
+++ b/python/log/test_ut.py
@@ -46,6 +46,11 @@ def clean_env():
if os.environ.get("GNUNET_FORCE_LOGFILE"):
del os.environ["GNUNET_FORCE_LOGFILE"]
+
+# NOTE: no logs will appear on screen, as the setLevel
+# function is mocked (and the level specified won't be
+# made effective -- rather, only the very default level
+# (WARNING) will apply)!
class TestGnunetLog(TestCase):
def setUp(self):
clean_env()
@@ -54,11 +59,6 @@ class TestGnunetLog(TestCase):
# env variable is set and no explicit loglevel is given
# via the "setup()" method. The expected result is that
# the level is set to INFO.
- #
- # NOTE: no logs will appear on screen, as the setLevel
- # function is mocked (and the level specified won't be
- # made effective -- rather, only the very default level
- # (WARNING) will apply)!
@patch("logging.Logger.setLevel")
@patch("logging.basicConfig")
def test_no_env_and_no_setup(self, mocked_basicConfig, mocked_setLevel):
@@ -81,3 +81,27 @@ class TestGnunetLog(TestCase):
gl = GL("gnunet-pylog")
gl.log("msg", gl.DEBUG)
mocked_setLevel.assert_called_with(level=logging.ERROR)
+
+ # This function tests the case where *only* the GNUNET_FORCE_LOG
+ # env variable is set -- not even the manual setup of the loglevel
+ # is put in place.
+ @patch("logging.Logger.setLevel")
+ @patch("logging.basicConfig")
+ def test_only_forced_env(self, mocked_basicConfig, mocked_setLevel):
+ assert None == os.environ.get("GNUNET_LOG")
+ os.environ["GNUNET_FORCE_LOG"] = "gnunet-pylog;test_ut.py;test_only_forced_env;70-100;ERROR"
+ gl = GL("gnunet-pylog")
+ gl.log("msg", gl.DEBUG)
+ mocked_setLevel.assert_called_with(level=logging.ERROR)
+
+ # This function tests the case where *only* the manual
+ # loglevel setup is put in place.
+ @patch("logging.Logger.setLevel")
+ @patch("logging.basicConfig")
+ def test_only_manual_loglevel_setup(self, mocked_basicConfig, mocked_setLevel):
+ assert None == os.environ.get("GNUNET_LOG")
+ assert None == os.environ.get("GNUNET_FORCE_LOG")
+ gl = GL("gnunet-pylog")
+ gl.setup(gl.DEBUG)
+ gl.log("msg", gl.WARNING)
+ mocked_setLevel.assert_called_with(level=logging.DEBUG)