gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-taler-util] 38/51: 4453. Test GNUNET_FORCE_LOGFILE.


From: gnunet
Subject: [GNUnet-SVN] [taler-taler-util] 38/51: 4453. Test GNUNET_FORCE_LOGFILE.
Date: Mon, 23 Sep 2019 22:02:29 +0200

This is an automated email from the git hooks/post-receive script.

ng0 pushed a commit to branch master
in repository taler-util.

commit d3a6c1b86431c394b72eaecc8cc12db817ff5806
Author: Marcello Stanisci <address@hidden>
AuthorDate: Thu Feb 7 16:46:25 2019 +0100

    4453.  Test GNUNET_FORCE_LOGFILE.
---
 python/log/test.py | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/python/log/test.py b/python/log/test.py
index 8fc6e59..b2f316e 100755
--- a/python/log/test.py
+++ b/python/log/test.py
@@ -28,8 +28,9 @@
 from unittest import TestCase
 from gnunet_log import GnunetLogger as GL
 import os
-from mock import patch
+from mock import patch, MagicMock
 import logging
+from datetime import datetime
 
 # How the logging module defines loglevels.
 #
@@ -55,6 +56,22 @@ class TestGnunetLog(TestCase):
     def setUp(self):
         clean_env()
 
+    # This function tests whether GNUNET_FORCE_LOGFILE
+    # is correctly interpreted.
+    @patch("logging.Logger.addHandler")
+    @patch("logging.FileHandler")
+    def test_force_logfile(self, mocked_FileHandler, mocked_addHandler):
+        os.environ["GNUNET_FORCE_LOGFILE"] = "/tmp/{}-[]-%Y_%m_%d.log"
+        unused_mock = MagicMock()
+        mocked_FileHandler.return_value = unused_mock
+        gl = GL("gnunet-pylog")
+        gl.log("msg", gl.DEBUG)
+
+        today = datetime.now()
+        expected_filename = "/tmp/gnunet-pylog-%s-%s.log" % (str(os.getpid()), 
today.strftime("%Y_%m_%d"))
+        mocked_FileHandler.assert_called_with(expected_filename)
+        mocked_addHandler.assert_called_with(unused_mock)
+
     # This function tests the very basic case, where no
     # env variable is set and no explicit loglevel is given
     # via the "setup()" method.  The expected result is that
@@ -77,7 +94,7 @@ class TestGnunetLog(TestCase):
     @patch("logging.basicConfig")
     def test_non_forced_env(self, mocked_basicConfig, mocked_setLevel):
         assert None == os.environ.get("GNUNET_FORCE_LOG")
-        os.environ["GNUNET_LOG"] = 
"gnunet-pylog;test.py;test_non_forced_env;60-90;ERROR"
+        os.environ["GNUNET_LOG"] = 
"gnunet-pylog;test.py;test_non_forced_env;80-150;ERROR"
         gl = GL("gnunet-pylog")
         gl.log("msg", gl.DEBUG)
         mocked_setLevel.assert_called_with(level=logging.ERROR)
@@ -89,7 +106,7 @@ class TestGnunetLog(TestCase):
     @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.py;test_only_forced_env;70-100;ERROR"
+        os.environ["GNUNET_FORCE_LOG"] = 
"gnunet-pylog;test.py;test_only_forced_env;90-200;ERROR"
         gl = GL("gnunet-pylog")
         gl.log("msg", gl.DEBUG)
         mocked_setLevel.assert_called_with(level=logging.ERROR)

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]