Added __repr__ for JIDs.
[slixmpp.git] / testall.py
blob2f980654c7d51094750bdf6f6a107ca1ad6687d4
1 #!/usr/bin/env python
2 import unittest
3 import logging
4 import sys
5 import os
7 class testoverall(unittest.TestCase):
9 def testModules(self):
10 """Testing all modules by compiling them"""
11 import compileall
12 import re
13 if sys.version_info < (3,0):
14 self.failUnless(compileall.compile_dir('.' + os.sep + 'sleekxmpp', rx=re.compile('/[.]svn'), quiet=True))
15 else:
16 self.failUnless(compileall.compile_dir('.' + os.sep + 'sleekxmpp', rx=re.compile('/[.]svn|.*26.*'), quiet=True))
18 def testTabNanny(self):
19 """Invoking the tabnanny"""
20 import tabnanny
21 self.failIf(tabnanny.check("." + os.sep + 'sleekxmpp'))
22 #raise "Help!"
24 def disabled_testMethodLength(self):
25 """Testing for excessive method lengths"""
26 import re
27 dirs = os.walk(sys.path[0] + os.sep + 'sleekxmpp')
28 offenders = []
29 for d in dirs:
30 if not '.svn' in d[0]:
31 for filename in d[2]:
32 if filename.endswith('.py') and d[0].find("template%stemplates" % os.sep) == -1:
33 with open("%s%s%s" % (d[0],os.sep,filename), "r") as fp:
34 cur = None
35 methodline = lineno = methodlen = methodindent = 0
36 for line in fp:
37 indentlevel = re.compile("^[\t ]*").search(line).end()
38 line = line.expandtabs()
39 lineno += 1
40 if line.strip().startswith("def ") or line.strip().startswith("except") or (line.strip() and methodindent > indentlevel) or (line.strip() and methodindent == indentlevel): #new method found or old one ended
41 if cur: #existing method needs final evaluation
42 if methodlen > 50 and not cur.strip().startswith("def setupUi"):
43 offenders.append("Method '%s' on line %s of %s/%s is longer than 50 lines (%s)" % (cur.strip(),methodline,d[0][len(rootp):],filename,methodlen))
44 methodlen = 0
45 cur = line
46 methodindent = indentlevel
47 methodline = lineno
48 if line and cur and not line.strip().startswith("#") and not (cur.strip().startswith("try:") and methodindent == 0): #if we weren't all whitespace and weren't a comment
49 methodlen += 1
50 self.failIf(offenders,"\n".join(offenders))
53 if __name__ == '__main__':
54 logging.basicConfig(level=100)
55 logging.disable(100)
56 #this doesn't need to be very clean
57 alltests = [unittest.TestLoader().loadTestsFromTestCase(testoverall)]
58 rootp = sys.path[0] + os.sep + 'tests'
59 dirs = os.walk(rootp)
60 for d in dirs:
61 if not '.svn' in d[0]:
62 for filename in d[2]:
63 if filename.startswith('test_') and filename.endswith('.py'):
64 modname = ('tests' + "." + filename)[:-3].replace(os.sep,'.')
65 __import__(modname)
66 #sys.modules[modname].config = moduleconfig
67 alltests.append(sys.modules[modname].suite)
68 alltests_suite = unittest.TestSuite(alltests)
69 result = unittest.TextTestRunner(verbosity=2).run(alltests_suite)
70 print("""<tests xmlns='http://andyet.net/protocol/tests' ran='%s' errors='%s' fails='%s' success='%s' />""" % (result.testsRun, len(result.errors), len(result.failures), result.wasSuccessful()))