diff src/test/helpers.py @ 780:9810f22ba733

test: store the constants in constants.py + better PEP8 compliance
author souliane <souliane@mailoo.org>
date Sat, 04 Jan 2014 15:45:08 +0100
parents bfabeedbf32e
children 80ab2b58e205
line wrap: on
line diff
--- a/src/test/helpers.py	Sat Jan 04 21:13:51 2014 +0100
+++ b/src/test/helpers.py	Sat Jan 04 15:45:08 2014 +0100
@@ -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 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 @@
     """
     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 @@
     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 @@
         """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 @@
     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 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 @@
             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 @@
             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__['_'] = _