summaryrefslogtreecommitdiff
path: root/testall.py
diff options
context:
space:
mode:
authorNathan Fritz <fritzy@netflint.net>2010-01-08 07:01:19 +0000
committerNathan Fritz <fritzy@netflint.net>2010-01-08 07:01:19 +0000
commit218c7318e040cd8acb90dfc445b7388a37756d8b (patch)
tree41aa0dcd3927632e11117357b440ece7f7814252 /testall.py
parent137ef61523d178a12c08da3f544e81a3135f3cf7 (diff)
downloadslixmpp-218c7318e040cd8acb90dfc445b7388a37756d8b.tar.gz
slixmpp-218c7318e040cd8acb90dfc445b7388a37756d8b.tar.bz2
slixmpp-218c7318e040cd8acb90dfc445b7388a37756d8b.tar.xz
slixmpp-218c7318e040cd8acb90dfc445b7388a37756d8b.zip
* added tests
Diffstat (limited to 'testall.py')
-rw-r--r--testall.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/testall.py b/testall.py
new file mode 100644
index 00000000..982ad642
--- /dev/null
+++ b/testall.py
@@ -0,0 +1,65 @@
+#!/usr/bin/python2.6
+import unittest
+import logging
+import sys
+import os
+
+class testoverall(unittest.TestCase):
+
+ def testModules(self):
+ """Testing all modules by compiling them"""
+ import compileall
+ import re
+ self.failUnless(compileall.compile_dir('.' + os.sep + 'sleekxmpp', rx=re.compile('/[.]svn'), quiet=True))
+
+ def testTabNanny(self):
+ """Invoking the tabnanny"""
+ import tabnanny
+ self.failIf(tabnanny.check("." + os.sep + 'sleekxmpp'))
+
+ def testMethodLength(self):
+ """Testing for excessive method lengths"""
+ import re
+ dirs = os.walk(sys.path[0] + os.sep + 'sleekxmpp')
+ offenders = []
+ for d in dirs:
+ if not '.svn' in d[0]:
+ for filename in d[2]:
+ if filename.endswith('.py') and d[0].find("template%stemplates" % os.sep) == -1:
+ with open("%s%s%s" % (d[0],os.sep,filename), "r") as fp:
+ cur = None
+ methodline = lineno = methodlen = methodindent = 0
+ for line in fp:
+ indentlevel = re.compile("^[\t ]*").search(line).end()
+ line = line.expandtabs()
+ lineno += 1
+ 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
+ if cur: #existing method needs final evaluation
+ if methodlen > 50 and not cur.strip().startswith("def setupUi"):
+ 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))
+ methodlen = 0
+ cur = line
+ methodindent = indentlevel
+ methodline = lineno
+ 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
+ methodlen += 1
+ self.failIf(offenders,"\n".join(offenders))
+
+
+if __name__ == '__main__':
+ logging.basicConfig(level=100)
+ logging.disable(100)
+ #this doesn't need to be very clean
+ alltests = [unittest.TestLoader().loadTestsFromTestCase(testoverall)]
+ rootp = sys.path[0] + os.sep + 'tests'
+ dirs = os.walk(rootp)
+ for d in dirs:
+ if not '.svn' in d[0]:
+ for filename in d[2]:
+ if filename.startswith('test_') and filename.endswith('.py'):
+ modname = ('tests' + "." + filename)[:-3].replace(os.sep,'.')
+ __import__(modname)
+ #sys.modules[modname].config = moduleconfig
+ alltests.append(sys.modules[modname].suite)
+ alltests_suite = unittest.TestSuite(alltests)
+ unittest.TextTestRunner(verbosity=2).run(alltests_suite)