7 class testoverall(unittest
.TestCase
):
10 """Testing all modules by compiling them"""
13 if sys
.version_info
< (3,0):
14 self
.failUnless(compileall
.compile_dir('.' + os
.sep
+ 'sleekxmpp', rx
=re
.compile('/[.]svn'), quiet
=True))
16 self
.failUnless(compileall
.compile_dir('.' + os
.sep
+ 'sleekxmpp', rx
=re
.compile('/[.]svn|.*26.*'), quiet
=True))
18 def testTabNanny(self
):
19 """Invoking the tabnanny"""
21 self
.failIf(tabnanny
.check("." + os
.sep
+ 'sleekxmpp'))
24 def disabled_testMethodLength(self
):
25 """Testing for excessive method lengths"""
27 dirs
= os
.walk(sys
.path
[0] + os
.sep
+ 'sleekxmpp')
30 if not '.svn' in d
[0]:
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
:
35 methodline
= lineno
= methodlen
= methodindent
= 0
37 indentlevel
= re
.compile("^[\t ]*").search(line
).end()
38 line
= line
.expandtabs()
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
))
46 methodindent
= indentlevel
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
50 self
.failIf(offenders
,"\n".join(offenders
))
53 if __name__
== '__main__':
54 logging
.basicConfig(level
=100)
56 #this doesn't need to be very clean
57 alltests
= [unittest
.TestLoader().loadTestsFromTestCase(testoverall
)]
58 rootp
= sys
.path
[0] + os
.sep
+ 'tests'
61 if not '.svn' in d
[0]:
63 if filename
.startswith('test_') and filename
.endswith('.py'):
64 modname
= ('tests' + "." + filename
)[:-3].replace(os
.sep
,'.')
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()))