summaryrefslogtreecommitdiff
path: root/testall.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2011-08-24 21:54:36 -0700
committerLance Stout <lancestout@gmail.com>2011-08-24 22:09:02 -0700
commitede59ab40e896293adba1278c42463fd8a5ba0fa (patch)
tree674d619648a97ea2bfea3d77199392d4ed750435 /testall.py
parent2a8082407656bf78a487afcf20017b10ca6475cc (diff)
downloadslixmpp-ede59ab40e896293adba1278c42463fd8a5ba0fa.tar.gz
slixmpp-ede59ab40e896293adba1278c42463fd8a5ba0fa.tar.bz2
slixmpp-ede59ab40e896293adba1278c42463fd8a5ba0fa.tar.xz
slixmpp-ede59ab40e896293adba1278c42463fd8a5ba0fa.zip
Clean and get setup.py working once and for all.
Fixes: README.rst now included Double line spacing removed from long_description Source package now includes tests, examples, etc using Manifest.in README.rst typos fixed Added README.rst section on installing dnspython for Python3 Version bumped to RC2 Version is now taken from sleekxmpp.version.__version__ without having to pull in the entire library Added 'test' command for setup.py Simplified testall.py Docs build cleanly from source package after installation
Diffstat (limited to 'testall.py')
-rwxr-xr-x[-rw-r--r--]testall.py123
1 files changed, 58 insertions, 65 deletions
diff --git a/testall.py b/testall.py
index 2f980654..65c4a85f 100644..100755
--- a/testall.py
+++ b/testall.py
@@ -1,70 +1,63 @@
#!/usr/bin/env python
-import unittest
-import logging
-import sys
+
import os
+import sys
+import logging
+import unittest
+import distutils.core
+
+from glob import glob
+from os.path import splitext, basename, join as pjoin, walk
+
+
+def run_tests():
+ """
+ Find and run all tests in the tests/ directory.
+
+ Excludes live tests (tests/live_*).
+ """
+ testfiles = ['tests.test_overall']
+ exclude = ['__init__.py', 'test_overall.py']
+ for t in glob(pjoin('.', 'tests', '*.py')):
+ if True not in [t.endswith(ex) for ex in exclude]:
+ if basename(t).startswith('test_'):
+ testfiles.append('tests.%s' % splitext(basename(t))[0])
+
+ suites = []
+ for file in testfiles:
+ __import__(file)
+ suites.append(sys.modules[file].suite)
+
+ tests = unittest.TestSuite(suites)
+ runner = unittest.TextTestRunner(verbosity=2)
+
+ # Disable logging output
+ logging.basicConfig(level=100)
+ logging.disable(100)
+
+ result = runner.run(tests)
+ return result
+
+
+# Add a 'test' command for setup.py
+
+class TestCommand(distutils.core.Command):
+
+ user_options = [ ]
+
+ def initialize_options(self):
+ self._dir = os.getcwd()
+
+ def finalize_options(self):
+ pass
+
+ def run(self):
+ run_tests()
-class testoverall(unittest.TestCase):
-
- def testModules(self):
- """Testing all modules by compiling them"""
- import compileall
- import re
- if sys.version_info < (3,0):
- self.failUnless(compileall.compile_dir('.' + os.sep + 'sleekxmpp', rx=re.compile('/[.]svn'), quiet=True))
- else:
- self.failUnless(compileall.compile_dir('.' + os.sep + 'sleekxmpp', rx=re.compile('/[.]svn|.*26.*'), quiet=True))
-
- def testTabNanny(self):
- """Invoking the tabnanny"""
- import tabnanny
- self.failIf(tabnanny.check("." + os.sep + 'sleekxmpp'))
- #raise "Help!"
-
- def disabled_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)
- result = unittest.TextTestRunner(verbosity=2).run(alltests_suite)
- 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()))
+ result = run_tests()
+ print("<tests %s ran='%s' errors='%s' fails='%s' success='%s' />" % (
+ "xmlns='http//andyet.net/protocol/tests'",
+ result.testsRun, len(result.errors),
+ len(result.failures), result.wasSuccessful()))