Remove TestLogger and associated unit test

This is not used anywhere. In current python versions, basicConfig
is called automatically when there is no root handler. It is easy
to add a FileHandler if required.
This commit is contained in:
Nick Hall 2017-05-11 17:13:34 +01:00
parent 0d704f03d8
commit 1b18b652bb
2 changed files with 0 additions and 67 deletions

View File

@ -184,29 +184,6 @@ class Test3(U.TestCase):
else: else:
self.fail("Skip deltree constraint test, no '$HOME' var") self.fail("Skip deltree constraint test, no '$HOME' var")
# logging (& misc?)
class Test4(U.TestCase):
logf = "/tmp/__tu__log__"
def test4a(self):
wmsg = "a warning message"
emsg = "an error message"
import logging
# file logging helps with file capture of log-messages
tl = tu.TestLogger()
for i in (1,2):
# 2 passes to test clearing old file
tl.logfile_init(self.logf)
logging.warn(wmsg)
logging.info("nada")
logging.error(emsg)
ll = tl.logfile_getlines()
nl = len(ll)
print(repr(ll))
self.assertEquals(nl,2,
tu.msg(nl,2, "pass %d: expected line count" % i))
#del tl
if __name__ == "__main__": if __name__ == "__main__":
U.main() U.main()

View File

@ -172,50 +172,6 @@ def delete_tree(dir):
% (dir, here, tmp)) % (dir, here, tmp))
shutil.rmtree(sdir) shutil.rmtree(sdir)
# simplified logging
# gramps-independent but gramps-compatible
#
# I don't see any need to inherit from logging.Logger
# (at present, test code needs nothing fancy)
# but that might be considered for future needs
# NB: current code reflects limited expertise on the
# uses of the logging module
# ---------------------------------------------------------
class TestLogger:
"""this class mainly just encapsulates some globals
namely lfname, lfh for a file log name and handle
provides simplified logging setup for test modules
that need to setup logging for modules under test
(just instantiate a TestLogger to avoid error
messages about logging handlers not available)
There is also a simple logfile capability, to allow
test modules to capture gramps logging output
Note that existing logging will still occur, possibly
resulting in console messages and popup dialogs
"""
def __init__(self, lvl=logging.WARN):
logging.basicConfig(level=lvl)
def logfile_init(self, lfname):
"""init or re-init a logfile"""
if getattr(self, "lfh", None):
logging.getLogger().handlers.remove(self.lfh)
if os.path.isfile(lfname):
os.unlink(lfname)
self.lfh = logging.FileHandler(lfname)
logging.getLogger().addHandler(self.lfh)
self.lfname = lfname
def logfile_getlines(self):
"""get current content of logfile as list of lines"""
txt = []
if self.lfname and os.path.isfile(self.lfname):
txt = open(self.lfname).readlines()
return txt
### Support for testing CLI ### Support for testing CLI
def new_exit(edit_code=None): def new_exit(edit_code=None):