-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_all.py
executable file
·83 lines (64 loc) · 2.25 KB
/
test_all.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
# Skapat av Christian Davén 2004
import os
import os.path
import sys
import inspect
class ClassAndMethodAnalyser:
def analyse(self, module):
self.analyseClasses(module)
def analyseClass(self, classtuple):
methods = self.getMethods(classtuple[1])
print "\n= " + classtuple[0] + " (" + str(len(methods)) + " metoder)"
if len(methods) > 10:
print " * VARNING! Klassen innehåller många metoder"
for method in methods:
self.analyseMethod(method)
def countLines(self, lines):
count = 0
for line in lines:
line = line.strip()
if line == "" or line.startswith("#") or line.startswith("class") or line.startswith("def"):
continue
count += 1
return count
def analyseMethod(self, methodtuple):
try:
code = inspect.getsourcelines(methodtuple[1])[0]
except TypeError:
return
print " - " + methodtuple[0] + " (" + str(self.countLines(code)) + " rader)"
if self.countLines(code) > 10:
print " * VARNING! Metoden är lång"
def analyseClasses(self, module):
module = __import__(module)
members = inspect.getmembers(module)
for member in members:
if inspect.isclass(member[1]):
self.analyseClass(member)
def getMethods(self, classname):
# returnerar även superklassernas metoder ...
members = inspect.getmembers(classname)
methods = []
for member in members:
if inspect.ismethod(member[1]):
print member
methods.append(member)
return methods
analyser = ClassAndMethodAnalyser()
def runfile(file):
if os.system("python " + file):
sys.exit(1)
for file in os.listdir(os.getcwd()):
if os.path.isdir(file):
continue
file = os.path.split(file)[1]
if file == __file__:
continue
if file.startswith("test_") and file.endswith(".py"):
print "=== " + file
runfile(file)
# elif file.endswith(".py") or file.endswith(".pyw"):
# print "=== " + file
# analyser.analyse(os.path.splitext(file)[0])