Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
check-tests.py
1
#!/usr/bin/env python
2
3
from
__future__
import
print_function
4
import
sys, os, re
5
6
classes_ignore_list = (
7
'ViSP(Test)?Case'
,
8
'ViSP(Test)?Runner'
,
9
'VpException'
,
10
)
11
12
# TODO: By akshay. The functions below aren't needed in visp
13
funcs_ignore_list = (
14
'\w+--HashCode'
,
15
'Mat--MatLong'
,
16
'\w+--Equals'
,
17
'Core--MinMaxLocResult'
,
18
)
19
20
class
JavaParser
:
21
def
__init__
(self):
22
self.
clear
()
23
24
def
clear
(self):
25
self.
mdict
= {}
26
self.
tdict
= {}
27
self.
mwhere
= {}
28
self.
twhere
= {}
29
self.
empty_stubs_cnt
= 0
30
self.
r1
= re.compile(
"\s*public\s+(?:static\s+)?(\w+)\(([^)]*)\)"
)
# c-tor
31
self.
r2
= re.compile(
"\s*(?:(?:public|static|final)\s+){1,3}\S+\s+(\w+)\(([^)]*)\)"
)
32
self.
r3
= re.compile(
'\s*fail\("Not yet implemented"\);'
)
# empty test stub
33
34
35
def
dict2set
(self, d):
36
s = set()
37
for
f
in
d.keys():
38
if
len(d[f]) == 1:
39
s.add(f)
40
else
:
41
s |= set(d[f])
42
return
s
43
44
45
def
get_tests_count
(self):
46
return
len(self.
tdict
)
47
48
def
get_empty_stubs_count
(self):
49
return
self.
empty_stubs_cnt
50
51
def
get_funcs_count
(self):
52
return
len(self.
dict2set
(self.
mdict
)), len(self.
mdict
)
53
54
def
get_not_tested
(self):
55
mset = self.
dict2set
(self.
mdict
)
56
tset = self.
dict2set
(self.
tdict
)
57
nottested = mset - tset
58
out = set()
59
60
for
name
in
nottested:
61
out.add(name +
" "
+ self.
mwhere
[name])
62
63
return
out
64
65
66
def
parse
(self, path):
67
if
".svn"
in
path:
68
return
69
if
os.path.isfile(path):
70
if
path.endswith(
"FeatureDetector.java"
):
71
for
prefix1
in
(
""
,
"Grid"
,
"Pyramid"
,
"Dynamic"
):
72
for
prefix2
in
(
"FAST"
,
"STAR"
,
"MSER"
,
"ORB"
,
"SIFT"
,
"SURF"
,
"GFTT"
,
"HARRIS"
,
"SIMPLEBLOB"
,
"DENSE"
):
73
parser.parse_file(path,prefix1+prefix2)
74
elif
path.endswith(
"DescriptorExtractor.java"
):
75
for
prefix1
in
(
""
,
"Opponent"
):
76
for
prefix2
in
(
"BRIEF"
,
"ORB"
,
"SIFT"
,
"SURF"
):
77
parser.parse_file(path,prefix1+prefix2)
78
elif
path.endswith(
"GenericDescriptorMatcher.java"
):
79
for
prefix
in
(
"OneWay"
,
"Fern"
):
80
parser.parse_file(path,prefix)
81
elif
path.endswith(
"DescriptorMatcher.java"
):
82
for
prefix
in
(
"BruteForce"
,
"BruteForceHamming"
,
"BruteForceHammingLUT"
,
"BruteForceL1"
,
"FlannBased"
,
"BruteForceSL2"
):
83
parser.parse_file(path,prefix)
84
else
:
85
parser.parse_file(path)
86
elif
os.path.isdir(path):
87
for
x
in
os.listdir(path):
88
self.
parse
(path +
"/"
+ x)
89
return
90
91
92
def
parse_file
(self, fname, prefix = ""):
93
istest = fname.endswith(
"Test.java"
)
94
clsname = os.path.basename(fname).replace(
"Test"
,
""
).replace(
".java"
,
""
)
95
clsname = prefix + clsname[0].upper() + clsname[1:]
96
for
cls
in
classes_ignore_list:
97
if
re.match(cls, clsname):
98
return
99
f = open(fname,
"rt"
)
100
linenum = 0
101
for
line
in
f:
102
linenum += 1
103
m1 = self.
r1
.match(line)
104
m2 = self.
r2
.match(line)
105
m3 = self.
r3
.match(line)
106
func =
''
107
args_str =
''
108
if
m1:
109
func = m1.group(1)
110
args_str = m1.group(2)
111
elif
m2:
112
if
"public"
not
in
line:
113
continue
114
func = m2.group(1)
115
args_str = m2.group(2)
116
elif
m3:
117
self.
empty_stubs_cnt
+= 1
118
continue
119
else
:
120
#if "public" in line:
121
#print "UNRECOGNIZED: " + line
122
continue
123
d = (self.
mdict
, self.
tdict
)[istest]
124
w = (self.
mwhere
, self.
twhere
)[istest]
125
func = re.sub(
r"^test"
,
""
, func)
126
func = clsname +
"--"
+ func[0].upper() + func[1:]
127
args_str = args_str.replace(
"[]"
,
"Array"
).replace(
"..."
,
"Array "
)
128
args_str = re.sub(
r"List<(\w+)>"
,
"ListOf\g<1>"
, args_str)
129
args_str = re.sub(
r"List<(\w+)>"
,
"ListOf\g<1>"
, args_str)
130
args = [a.split()[0]
for
a
in
args_str.split(
","
)
if
a]
131
func_ex = func +
""
.join([a[0].upper() + a[1:]
for
a
in
args])
132
func_loc = fname +
" (line: "
+ str(linenum) +
")"
133
skip =
False
134
for
fi
in
funcs_ignore_list:
135
if
re.match(fi, func_ex):
136
skip =
True
137
break
138
if
skip:
139
continue
140
if
func
in
d:
141
d[func].append(func_ex)
142
else
:
143
d[func] = [func_ex]
144
w[func_ex] = func_loc
145
w[func] = func_loc
146
147
f.close()
148
return
149
150
151
if
__name__ ==
'__main__'
:
152
if
len(sys.argv) < 2:
153
print(
"Usage:\n"
, \
154
os.path.basename(sys.argv[0]), \
155
"<Classes/Tests dir1/file1> [<Classes/Tests dir2/file2> ...]\n"
,
"Not tested methods are loggedto stdout."
)
156
exit(0)
157
parser =
JavaParser
()
158
for
x
in
sys.argv[1:]:
159
parser.parse(x)
160
funcs = parser.get_not_tested()
161
if
funcs:
162
print
(
'{} {}'
.format(
"NOT TESTED methods:\n\t"
,
"\n\t"
.join(sorted(funcs))))
163
print
(
"Total methods found: %i (%i)"
% parser.get_funcs_count())
164
print
(
'{} {}'
.format(
"Not tested methods found:"
, len(funcs)))
165
print
(
'{} {}'
.format(
"Total tests found:"
, parser.get_tests_count()))
166
print
(
'{} {}'
.format(
"Empty test stubs found:"
, parser.get_empty_stubs_count()))
check-tests.JavaParser
Definition
check-tests.py:20
check-tests.JavaParser.parse_file
parse_file(self, fname, prefix="")
Definition
check-tests.py:92
check-tests.JavaParser.get_funcs_count
get_funcs_count(self)
Definition
check-tests.py:51
check-tests.JavaParser.twhere
dict twhere
Definition
check-tests.py:28
check-tests.JavaParser.r1
r1
Definition
check-tests.py:30
check-tests.JavaParser.empty_stubs_cnt
int empty_stubs_cnt
Definition
check-tests.py:29
check-tests.JavaParser.__init__
__init__(self)
Definition
check-tests.py:21
check-tests.JavaParser.get_tests_count
get_tests_count(self)
Definition
check-tests.py:45
check-tests.JavaParser.r2
r2
Definition
check-tests.py:31
check-tests.JavaParser.get_empty_stubs_count
get_empty_stubs_count(self)
Definition
check-tests.py:48
check-tests.JavaParser.parse
parse(self, path)
Definition
check-tests.py:66
check-tests.JavaParser.r3
r3
Definition
check-tests.py:32
check-tests.JavaParser.get_not_tested
get_not_tested(self)
Definition
check-tests.py:54
check-tests.JavaParser.clear
clear(self)
Definition
check-tests.py:24
check-tests.JavaParser.mwhere
dict mwhere
Definition
check-tests.py:27
check-tests.JavaParser.tdict
dict tdict
Definition
check-tests.py:26
check-tests.JavaParser.dict2set
dict2set(self, d)
Definition
check-tests.py:35
check-tests.JavaParser.mdict
dict mdict
Definition
check-tests.py:25
modules
java
check-tests.py
Generated by
1.17.0