test: store the constants in constants.py + better PEP8 compliance

This commit is contained in:
souliane 2014-01-04 15:45:08 +01:00
commit a21e3c2783

View file

@ -18,8 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
import __builtin__
from twisted.words.protocols.jabber.jid import JID
from constants import Const
from wokkel.xmppim import RosterItem
from sat.core.xmpp import SatRosterProtocol
from twisted.trial.unittest import FailTest
@ -27,9 +26,6 @@ from twisted.trial import unittest
from xml.etree import cElementTree as etree
import re
TEST_JID_STR = u"test@example.org/SàT"
TEST_JID = JID(u"test@example.org/SàT")
TEST_PROFILE = 'test_profile'
def b2s(value):
"""Convert a bool to a unicode string used in bridge
@ -39,12 +35,15 @@ def b2s(value):
"""
return u"True" if value else u"False"
class DifferentArgsException(FailTest):
pass
class DifferentXMLException(FailTest):
pass
class FakeSAT(object):
"""Class to simulate a SAT instance"""
@ -91,7 +90,7 @@ class FakeMemory(object):
def setPresenceStatus(self, contact_jid, show, priority, statuses, profile_key='@DEFAULT@'):
pass
def addWaitingSub(self, type, contact_jid, profile_key):
def addWaitingSub(self, type_, contact_jid, profile_key):
pass
def delWaitingSub(self, contact_jid, profile_key):
@ -109,12 +108,13 @@ class FakeTriggerManager(object):
"""We always return true to continue the action"""
return True
class FakeRosterProtocol(SatRosterProtocol):
def __init__(self, host, parent):
SatRosterProtocol.__init__(self, host)
self.parent = parent
self.addItem(TEST_JID)
self.addItem(Const.TEST_JID)
def addItem(self, jid, *args, **kwargs):
if not args and not kwargs:
@ -133,7 +133,7 @@ class FakeClient(object):
def __init__(self, host):
self.host = host
self.profile = 'test_profile'
self.jid = TEST_JID
self.jid = Const.TEST_JID
self.roster = FakeRosterProtocol(host, self)
def send(self, obj):
@ -142,11 +142,11 @@ class FakeClient(object):
class SatTestCase(unittest.TestCase):
def assertEqualXML(self, xml, expected, ignore_blank = False):
def assertEqualXML(self, xml, expected, ignore_blank=False):
def equalElt(got_elt, exp_elt):
if ignore_blank:
for elt in got_elt, exp_elt:
for attr in ('text','tail'):
for attr in ('text', 'tail'):
value = getattr(elt, attr)
try:
value = value.strip() or None
@ -176,7 +176,7 @@ class SatTestCase(unittest.TestCase):
return True
def remove_blank(xml):
lines = [line.strip() for line in re.sub(r'[ \t\r\f\v]+',' ',xml).split('\n')]
lines = [line.strip() for line in re.sub(r'[ \t\r\f\v]+', ' ', xml).split('\n')]
return '\n'.join([line for line in lines if line])
xml_elt = etree.fromstring(remove_blank(xml) if ignore_blank else xml)
@ -189,9 +189,3 @@ class SatTestCase(unittest.TestCase):
print "was expecting:\n-\n%s\n-\n\n" % etree.tostring(expected_elt, encoding='utf-8')
print "---"
raise DifferentXMLException
def _(text):
return text
__builtin__.__dict__['_'] = _