comparison src/test/helpers.py @ 1909:0681d69cbe0a

test: add helpers methods muteLogging and unmuteLogging
author souliane <souliane@mailoo.org>
date Fri, 11 Mar 2016 16:41:44 +0100
parents d17772b0fe22
children 55440ee00905
comparison
equal deleted inserted replaced
1908:ffcd7904b655 1909:0681d69cbe0a
20 20
21 ## logging configuration for tests ## 21 ## logging configuration for tests ##
22 from sat.core import log_config 22 from sat.core import log_config
23 log_config.satConfigure() 23 log_config.satConfigure()
24 24
25 import logging
26 from sat.core.log import getLogger
27 getLogger().setLevel(logging.WARNING) # put this to DEBUG when needed
28
25 from sat.core import exceptions 29 from sat.core import exceptions
30 from sat.tools import config as tools_config
26 from constants import Const as C 31 from constants import Const as C
27 from wokkel.xmppim import RosterItem 32 from wokkel.xmppim import RosterItem
28 from wokkel.generic import parseXml 33 from wokkel.generic import parseXml
29 from sat.core.xmpp import SatRosterProtocol 34 from sat.core.xmpp import SatRosterProtocol
30 from sat.memory.memory import Params, Memory 35 from sat.memory.memory import Params, Memory
45 50
46 """ 51 """
47 return u"True" if value else u"False" 52 return u"True" if value else u"False"
48 53
49 54
55 def muteLogging():
56 """Temporarily set the logging level to CRITICAL to not pollute the output with expected errors."""
57 logger = getLogger()
58 logger.original_level = logger.getEffectiveLevel()
59 logger.setLevel(logging.CRITICAL)
60
61
62 def unmuteLogging():
63 """Restore the logging level after it has been temporarily disabled."""
64 logger = getLogger()
65 logger.setLevel(logger.original_level)
66
67
50 class DifferentArgsException(FailTest): 68 class DifferentArgsException(FailTest):
51 pass 69 pass
52 70
53 71
54 class DifferentXMLException(FailTest): 72 class DifferentXMLException(FailTest):
338 356
339 def __init__(self, host, parent): 357 def __init__(self, host, parent):
340 SatRosterProtocol.__init__(self, host) 358 SatRosterProtocol.__init__(self, host)
341 self.parent = parent 359 self.parent = parent
342 self._jids = {} 360 self._jids = {}
343 self.addItem(parent.jid) 361 self.addItem(parent.jid.userhostJID())
344 362
345 def addItem(self, jid, *args, **kwargs): 363 def addItem(self, jid, *args, **kwargs):
346 if not args and not kwargs: 364 if not args and not kwargs:
347 # defaults values setted for the tests only 365 # defaults values setted for the tests only
348 kwargs["subscriptionTo"] = True 366 kwargs["subscriptionTo"] = True