diff --git a/src/test/helpers.py b/src/test/helpers.py index 630d732e..c09e4e47 100644 --- a/src/test/helpers.py +++ b/src/test/helpers.py @@ -22,7 +22,12 @@ from sat.core import log_config log_config.satConfigure() +import logging +from sat.core.log import getLogger +getLogger().setLevel(logging.WARNING) # put this to DEBUG when needed + from sat.core import exceptions +from sat.tools import config as tools_config from constants import Const as C from wokkel.xmppim import RosterItem from wokkel.generic import parseXml @@ -47,6 +52,19 @@ def b2s(value): return u"True" if value else u"False" +def muteLogging(): + """Temporarily set the logging level to CRITICAL to not pollute the output with expected errors.""" + logger = getLogger() + logger.original_level = logger.getEffectiveLevel() + logger.setLevel(logging.CRITICAL) + + +def unmuteLogging(): + """Restore the logging level after it has been temporarily disabled.""" + logger = getLogger() + logger.setLevel(logger.original_level) + + class DifferentArgsException(FailTest): pass @@ -340,7 +358,7 @@ class FakeRosterProtocol(SatRosterProtocol): SatRosterProtocol.__init__(self, host) self.parent = parent self._jids = {} - self.addItem(parent.jid) + self.addItem(parent.jid.userhostJID()) def addItem(self, jid, *args, **kwargs): if not args and not kwargs: diff --git a/src/test/test_memory.py b/src/test/test_memory.py index d7a69542..61082203 100644 --- a/src/test/test_memory.py +++ b/src/test/test_memory.py @@ -21,8 +21,6 @@ from sat.core.i18n import _ from sat.test import helpers from twisted.trial import unittest import traceback -from sat.core.log import getLogger -from logging import INFO from constants import Const from xml.dom import minidom @@ -205,11 +203,9 @@ class MemoryTest(unittest.TestCase): @param security_limit: -1 means no security, 0 is the maximum security then the higher the less secure @param app: name of the frontend registering the parameters """ - logger = getLogger() - level = logger.getEffectiveLevel() - logger.setLevel(INFO) + helpers.muteLogging() self.host.memory.paramsRegisterApp(xml, security_limit, app) - logger.setLevel(level) + helpers.unmuteLogging() # tests with no security level on the parameter (most secure) params = self._getParamXML() diff --git a/src/test/test_plugin_misc_radiocol.py b/src/test/test_plugin_misc_radiocol.py index 219e4e90..58d97e68 100644 --- a/src/test/test_plugin_misc_radiocol.py +++ b/src/test/test_plugin_misc_radiocol.py @@ -21,7 +21,6 @@ """ Tests for the plugin radiocol """ from sat.core import exceptions -from sat.core.log import getLogger from sat.test import helpers, helpers_plugins from sat.plugins import plugin_misc_radiocol as plugin from sat.plugins import plugin_misc_room_game as plugin_room_game diff --git a/src/test/test_plugin_misc_room_game.py b/src/test/test_plugin_misc_room_game.py index cb9c7100..0a504707 100644 --- a/src/test/test_plugin_misc_room_game.py +++ b/src/test/test_plugin_misc_room_game.py @@ -21,7 +21,6 @@ """ Tests for the plugin room game (base class for MUC games) """ from sat.core.i18n import _ -from sat.core.log import getLogger from constants import Const from sat.test import helpers, helpers_plugins from sat.plugins import plugin_misc_room_game as plugin @@ -430,7 +429,9 @@ class RoomGameTest(helpers.SatTestCase): def test__checkCreateGameAndInit(self): self.reinit() - self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE)) # print internal error + helpers.muteLogging() + self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE)) + helpers.unmuteLogging() nick = self.plugin_0045.joinRoom(0, 0) self.assertEqual((True, False), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE)) @@ -438,7 +439,9 @@ class RoomGameTest(helpers.SatTestCase): self.assertFalse(self.plugin._gameExists(ROOM_JID, True)) self.assertTrue(self.plugin.isReferee(ROOM_JID, nick)) - self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, OTHER_PROFILE)) # print internal error + helpers.muteLogging() + self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, OTHER_PROFILE)) + helpers.unmuteLogging() self.plugin_0045.joinRoom(0, 1) self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, OTHER_PROFILE)) diff --git a/src/test/test_plugin_xep_0033.py b/src/test/test_plugin_xep_0033.py index 941c6d6e..9baf5e83 100644 --- a/src/test/test_plugin_xep_0033.py +++ b/src/test/test_plugin_xep_0033.py @@ -24,7 +24,6 @@ from constants import Const from sat.test import helpers from sat.plugins import plugin_xep_0033 as plugin from sat.core.exceptions import CancelError -from sat.core.log import getLogger from twisted.internet import defer from wokkel.generic import parseXml from twisted.words.protocols.jabber.jid import JID @@ -108,7 +107,7 @@ class XEP_0033Test(helpers.SatTestCase): stored = [] d_list = [] - def cb(entities, to_jid, logger, level): + def cb(entities, to_jid): if host in entities: if host not in sent: # send the message to the entity offering the feature sent.append(host) @@ -117,16 +116,14 @@ class XEP_0033Test(helpers.SatTestCase): else: # feature not supported, use normal behavior sent.append(to_jid) stored.append(to_jid) - logger.setLevel(level) + helpers.unmuteLogging() for to_s in (JID_STR_X_TO, JID_STR_X_CC, JID_STR_X_BCC): to_jid = JID(to_s) host = JID(to_jid.host) - logger = getLogger() - level = logger.getEffectiveLevel() - logger.setLevel(ERROR) # remove log.warning pollution - d = self.host.findFeaturesSet([plugin.NS_ADDRESS], jid_=host, profile_key=PROFILE) - d.addCallback(cb, to_jid, logger, level) + helpers.muteLogging() + d = self.host.findFeaturesSet([plugin.NS_ADDRESS], jid_=host, profile=PROFILE) + d.addCallback(cb, to_jid) d_list.append(d) def cb_list(dummy): @@ -144,14 +141,12 @@ class XEP_0033Test(helpers.SatTestCase): addressing information to the stanza. @param data: the data to be processed by self.plugin.sendMessageTrigger """ - logger = getLogger() - level = logger.getEffectiveLevel() - logger.setLevel(ERROR) # remove log.warning pollution pre_treatments = defer.Deferred() post_treatments = defer.Deferred() + helpers.muteLogging() self.plugin.sendMessageTrigger(data, pre_treatments, post_treatments, PROFILE) post_treatments.callback(data) - logger.setLevel(level) + helpers.unmuteLogging() post_treatments.addCallbacks(self._assertAddresses, lambda failure: failure.trap(CancelError)) return post_treatments