Commit bb673bb9 authored by Ghislain MARY's avatar Ghislain MARY

Improve logging in the Python module unit tests.

parent 13ca8e0e
......@@ -11,19 +11,6 @@ test_password = "secret"
test_route = "sip2.linphone.org"
def log_handler(level, msg):
method = getattr(logging, level)
if not msg.strip().startswith('[PYLINPHONE]'):
msg = '[CORE] ' + msg
method(msg)
def setup_logging(filename):
format = "%(asctime)s.%(msecs)03d %(levelname)s: %(message)s"
datefmt = "%H:%M:%S"
logging.basicConfig(filename=filename, level=logging.INFO, format=format, datefmt=datefmt)
linphone.set_log_handler(log_handler)
def create_address(domain):
addr = linphone.Address.new(None)
assert addr != None
......@@ -39,6 +26,25 @@ def create_address(domain):
return addr
class Logger(logging.Logger):
def __init__(self, filename):
logging.Logger.__init__(self, filename)
self.setLevel(logging.INFO)
handler = logging.FileHandler(filename)
handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s.%(msecs)03d %(levelname)s: %(message)s', '%H:%M:%S')
handler.setFormatter(formatter)
self.addHandler(handler)
linphone.set_log_handler(self.log_handler)
def log_handler(self, level, msg):
method = getattr(self, level)
if not msg.strip().startswith('[PYLINPHONE]'):
msg = '[CORE] ' + msg
method(msg)
class CoreManagerStats:
def __init__(self):
self.reset()
......
......@@ -78,7 +78,7 @@ class TestRegister:
@classmethod
def setup_class(cls):
base, ext = os.path.splitext(os.path.basename(__file__))
linphonetester.setup_logging(base + '.log')
cls.logger = linphonetester.Logger(base + '.log')
def test_simple_register(self):
cm = RegisterCoreManager()
......
from nose.tools import assert_equals
import linphone
import linphonetester
import os
class TestSetup:
@classmethod
def setup_class(cls):
base, ext = os.path.splitext(os.path.basename(__file__))
cls.logger = linphonetester.Logger(base + '.log')
def test_address(self):
linphonetester.create_address(None)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment