@@ -85,8 +85,8 @@ def getTestList(self, white, black):
85
85
return set (res )
86
86
87
87
def isTest (self , fullpath ):
88
- if fullpath == " java" :
89
- return True
88
+ if fullpath in [ ' java' , 'python2' , 'python3' ] :
89
+ return self . options . mode == 'test'
90
90
if not os .path .isfile (fullpath ):
91
91
return False
92
92
if self .cache .getOS () == "nt" and not fullpath .endswith (".exe" ):
@@ -102,13 +102,37 @@ def wrapInValgrind(self, cmd = []):
102
102
return res + cmd
103
103
return cmd
104
104
105
+ def tryCommand (self , cmd ):
106
+ try :
107
+ if 0 == execute (cmd , cwd = workingDir ):
108
+ return True
109
+ except :
110
+ pass
111
+ return False
112
+
105
113
def runTest (self , path , logfile , workingDir , args = []):
106
114
args = args [:]
107
115
exe = os .path .abspath (path )
108
116
if path == "java" :
109
117
cmd = [self .cache .ant_executable , "-Dopencv.build.type=%s" % self .cache .build_type , "buildAndTest" ]
110
118
ret = execute (cmd , cwd = self .cache .java_test_binary_dir + "/.build" )
111
119
return None , ret
120
+ elif path in ['python2' , 'python3' ]:
121
+ executable = os .getenv ('OPENCV_PYTHON_BINARY' , None )
122
+ if executable is None :
123
+ executable = path
124
+ if not self .tryCommand ([executable , '--version' ]):
125
+ executable = 'python'
126
+ cmd = [executable , self .cache .opencv_home + '/modules/python/test/test.py' , '--repo' , self .cache .opencv_home , '-v' ] + args
127
+ module_suffix = '' if not 'Visual Studio' in self .cache .cmake_generator else '/' + self .cache .build_type
128
+ env = {}
129
+ env ['PYTHONPATH' ] = self .cache .opencv_build + '/lib' + module_suffix + os .pathsep + os .getenv ('PYTHONPATH' , '' )
130
+ if self .cache .getOS () == 'nt' :
131
+ env ['PATH' ] = self .cache .opencv_build + '/bin' + module_suffix + os .pathsep + os .getenv ('PATH' , '' )
132
+ else :
133
+ env ['LD_LIBRARY_PATH' ] = self .cache .opencv_build + '/bin' + os .pathsep + os .getenv ('LD_LIBRARY_PATH' , '' )
134
+ ret = execute (cmd , cwd = workingDir , env = env )
135
+ return None , ret
112
136
else :
113
137
if isColorEnabled (args ):
114
138
args .append ("--gtest_color=yes" )
@@ -140,12 +164,15 @@ def runTests(self, tests, black, workingDir, args = []):
140
164
more_args = []
141
165
exe = self .getTest (test )
142
166
143
- userlog = [a for a in args if a .startswith ("--gtest_output=" )]
144
- if len (userlog ) == 0 :
145
- logname = self .getLogName (exe , date )
146
- more_args .append ("--gtest_output=xml:" + logname )
167
+ if exe in ["java" , "python2" , "python3" ]:
168
+ logname = None
147
169
else :
148
- logname = userlog [0 ][userlog [0 ].find (":" )+ 1 :]
170
+ userlog = [a for a in args if a .startswith ("--gtest_output=" )]
171
+ if len (userlog ) == 0 :
172
+ logname = self .getLogName (exe , date )
173
+ more_args .append ("--gtest_output=xml:" + logname )
174
+ else :
175
+ logname = userlog [0 ][userlog [0 ].find (":" )+ 1 :]
149
176
150
177
log .debug ("Running the test: %s (%s) ==> %s in %s" , exe , args + more_args , logname , workingDir )
151
178
if self .options .dry_run :
0 commit comments