1- # Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
1+ # Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
22# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33#
44# The Universal Permissive License (UPL), Version 1.0
@@ -106,8 +106,7 @@ def fun(self):
106106 import re
107107
108108 executable = sys .executable .split (" " ) # HACK: our sys.executable on Java is a cmdline
109- re_success = re .compile ("(test\S+) \(([^\s]+)\) \.\.\. ok$" , re .MULTILINE )
110- re_failure = re .compile ("(test\S+) \(([^\s]+)\) \.\.\. (?:ERROR|FAIL)$" , re .MULTILINE )
109+ re_test_result = re .compile (r"""(test\S+) \(([^\s]+)\)(?:\n.*?)? \.\.\. \b(ok|skipped(?: ["'][^\n]+)?|ERROR|FAIL)$""" , re .MULTILINE | re .DOTALL )
111110 kwargs = {"stdout" : subprocess .PIPE , "stderr" : subprocess .PIPE , "text" : True , "check" : False }
112111
113112 glob_pattern = os .path .join (os .path .dirname (test .__file__ ), "test_*.py" )
@@ -123,7 +122,7 @@ def fun(self):
123122 else :
124123 glob_pattern = os .path .join (os .path .dirname (test .__file__ ), arg )
125124
126- p = subprocess .run (["/usr/bin/which" , "timeout" ], ** kwargs )
125+ p = subprocess .run (["/usr/bin/which" , "timeout" if sys . platform != 'darwin' else 'gtimeout' ], ** kwargs )
127126 if p .returncode != 0 :
128127 print ("Cannot find the 'timeout' GNU tool. Do you have coreutils installed?" )
129128 sys .exit (1 )
@@ -140,9 +139,9 @@ def fun(self):
140139 # entirely
141140 testfile_stem = os .path .splitext (os .path .basename (testfile ))[0 ]
142141 testmod = "test." + testfile_stem
143- cmd = [timeout , "-s" , "9" , "60 " ] + executable + ["-S" , "-m" ]
142+ cmd = [timeout , "-s" , "9" , "120 " ] + executable + ["-S" , "-m" ]
144143 tagfile = os .path .join (TAGS_DIR , testfile_stem + ".txt" )
145- if retag :
144+ if retag and repeat == 0 :
146145 test_selectors = []
147146 else :
148147 test_selectors = working_selectors (tagfile )
@@ -165,64 +164,59 @@ def fun(self):
165164 print ("*stderr*" )
166165 print (p .stderr )
167166
168- if p .returncode == 0 and not os .path .exists (tagfile ):
169- # if we're re-tagging a test without tags, all passed
170- with open (tagfile , "w" ) as f :
167+ passing_tests = []
168+ failed_tests = []
169+
170+ def get_pass_name (funcname , classname ):
171+ try :
172+ imported_test_module = __import__ (testmod )
173+ except Exception :
171174 pass
172- break
173- elif p .returncode == 0 :
174- # we ran the tagged tests and they were fine
175- break
176- elif repeat < maxrepeats :
177- # we failed the first run, create a tag file with the passing
178- # tests (if any)
179- passing_tests = []
180- failed_tests = []
181-
182- def get_pass_name (funcname , classname ):
183- try :
184- imported_test_module = __import__ (testmod )
185- except :
186- imported_test_module = None
187- else :
188- # try hard to get a most specific pattern
189- classname = "" .join (classname .rpartition (testmod )[1 :])
190- clazz = imported_test_module
191- path_to_class = classname .split ("." )[1 :]
192- for part in path_to_class :
193- clazz = getattr (clazz , part , None )
194- if clazz :
195- func = getattr (clazz , funcname , None )
196- if func :
197- return func .__qualname__
198- return funcname
199-
200- # n.b.: we add a '*' in the front, so that unittests doesn't add
201- # its own asterisks, because now this is already a pattern
202-
203- for funcname ,classname in re_failure .findall (p .stdout ):
204- failed_tests .append ("*" + get_pass_name (funcname , classname ))
205- for funcname ,classname in re_failure .findall (p .stderr ):
175+ else :
176+ # try hard to get a most specific pattern
177+ classname = "" .join (classname .rpartition (testmod )[1 :])
178+ clazz = imported_test_module
179+ path_to_class = classname .split ("." )[1 :]
180+ for part in path_to_class :
181+ clazz = getattr (clazz , part , None )
182+ if clazz :
183+ func = getattr (clazz , funcname , None )
184+ if func :
185+ return func .__qualname__
186+ return funcname
187+
188+ stderr = p .stderr .replace ("Please note: This Python implementation is in the very early stages, and can run little more than basic benchmarks at this point.\n " , '' )
189+
190+ # n.b.: we add a '*' in the front, so that unittests doesn't add
191+ # its own asterisks, because now this is already a pattern
192+ for funcname , classname , result in re_test_result .findall (stderr ):
193+ # We consider skipped tests as passing in order to avoid a situation where a Linux run
194+ # untags a Darwin-only test and vice versa
195+ if result == 'ok' or result .startswith ('skipped' ):
196+ passing_tests .append ("*" + get_pass_name (funcname , classname ))
197+ else :
206198 failed_tests .append ("*" + get_pass_name (funcname , classname ))
207199
208- for funcname ,classname in re_success .findall (p .stdout ):
209- passing_tests .append ("*" + get_pass_name (funcname , classname ))
210- for funcname ,classname in re_success .findall (p .stderr ):
211- passing_tests .append ("*" + get_pass_name (funcname , classname ))
200+ # n.b.: unittests uses the __qualname__ of the function as
201+ # pattern, which we're trying to do as well. however, sometimes
202+ # the same function is shared in multiple test classes, and
203+ # fails in some. so we always subtract the failed patterns from
204+ # the passed patterns
205+ passing_only_patterns = set (passing_tests ) - set (failed_tests )
206+ with open (tagfile , "w" ) as f :
207+ for passing_test in sorted (passing_only_patterns ):
208+ f .write (passing_test )
209+ f .write ("\n " )
210+ if not passing_only_patterns :
211+ os .unlink (tagfile )
212212
213- # n.b.: unittests uses the __qualname__ of the function as
214- # pattern, which we're trying to do as well. however, sometimes
215- # the same function is shared in multiple test classes, and
216- # fails in some. so we always subtract the failed patterns from
217- # the passed patterns
218- passing_only_patterns = set (passing_tests ) - set (failed_tests )
219- with open (tagfile , "w" ) as f :
220- for passing_test in passing_only_patterns :
221- f .write (passing_test )
222- f .write ("\n " )
223- if not passing_only_patterns :
224- os .unlink (tagfile )
225- else :
226- # we tried the last time and failed, so our tags don't work for
227- # some reason
213+ if p .returncode == 0 :
214+ break
215+
216+ else :
217+ # we tried the last time and failed, so our tags don't work for
218+ # some reason
219+ try :
228220 os .unlink (tagfile )
221+ except Exception :
222+ pass
0 commit comments