1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# This file is part of TALER
# (C) 2019 TALER SYSTEMS
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later
# version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#
# @author Marcello Stanisci
# @version 0.0
# @repository https://git.taler.net/copylib.git/
# This code is "copylib", it is versioned under the Git repository
# mentioned above, and it is meant to be manually copied into any
# project which might need it.
from unittest import TestCase
from gnunet_log import GnunetLogger as GL
import os
from mock import patch
import logging
def clean_env():
if os.environ.get("GNUNET_FORCE_LOG"):
del os.environ["GNUNET_FORCE_LOG"]
if os.environ.get("GNUNET_LOG"):
del os.environ["GNUNET_LOG"]
if os.environ.get("GNUNET_FORCE_LOGFILE"):
del os.environ["GNUNET_FORCE_LOGFILE"]
class TestGnunetLog(TestCase):
def setUp(self):
clean_env()
# 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
# 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):
# Double-check no env variable gets in the way.
assert None == os.environ.get("GNUNET_FORCE_LOG")
assert None == os.environ.get("GNUNET_LOG")
gl = GL("mock-style")
gl.log("msg", gl.INFO)
mocked_setLevel.assert_called_with(level=logging.INFO)
|