##// END OF EJS Templates
tests: collapse some more trivial if PYTHON3 blocks...
Gregory Szorc -
r49712:41c552a2 default
parent child Browse files
Show More
@@ -362,18 +362,10 b' def canonpath(path):'
362 362
363 363
364 364 def which(exe):
365 if PYTHON3:
366 # shutil.which only accept bytes from 3.8
367 cmd = _bytes2sys(exe)
368 real_exec = shutil.which(cmd)
369 return _sys2bytes(real_exec)
370 else:
371 # let us do the os work
372 for p in osenvironb[b'PATH'].split(os.pathsep):
373 f = os.path.join(p, exe)
374 if os.path.isfile(f):
375 return f
376 return None
365 # shutil.which only accept bytes from 3.8
366 cmd = _bytes2sys(exe)
367 real_exec = shutil.which(cmd)
368 return _sys2bytes(real_exec)
377 369
378 370
379 371 def parselistfiles(files, listtype, warn=True):
@@ -1864,11 +1856,8 b' class TTest(Test):'
1864 1856 script.append(b'alias pwd="pwd -W"\n')
1865 1857
1866 1858 if hgcatapult and hgcatapult != os.devnull:
1867 if PYTHON3:
1868 hgcatapult = hgcatapult.encode('utf8')
1869 cataname = self.name.encode('utf8')
1870 else:
1871 cataname = self.name
1859 hgcatapult = hgcatapult.encode('utf8')
1860 cataname = self.name.encode('utf8')
1872 1861
1873 1862 # Kludge: use a while loop to keep the pipe from getting
1874 1863 # closed by our echo commands. The still-running file gets
@@ -2173,11 +2162,8 b' class TTest(Test):'
2173 2162 return "retry", False
2174 2163
2175 2164 if el.endswith(b" (esc)\n"):
2176 if PYTHON3:
2177 el = el[:-7].decode('unicode_escape') + '\n'
2178 el = el.encode('latin-1')
2179 else:
2180 el = el[:-7].decode('string-escape') + '\n'
2165 el = el[:-7].decode('unicode_escape') + '\n'
2166 el = el.encode('latin-1')
2181 2167 if el == l or WINDOWS and el[:-1] + b'\r\n' == l:
2182 2168 return True, True
2183 2169 if el.endswith(b" (re)\n"):
@@ -2225,10 +2211,7 b' iolock = threading.RLock()'
2225 2211 firstlock = threading.RLock()
2226 2212 firsterror = False
2227 2213
2228 if PYTHON3:
2229 base_class = unittest.TextTestResult
2230 else:
2231 base_class = unittest._TextTestResult
2214 base_class = unittest.TextTestResult
2232 2215
2233 2216
2234 2217 class TestResult(base_class):
@@ -2352,13 +2335,9 b' class TestResult(base_class):'
2352 2335 self.stream.write('\n')
2353 2336 for line in lines:
2354 2337 line = highlightdiff(line, self.color)
2355 if PYTHON3:
2356 self.stream.flush()
2357 self.stream.buffer.write(line)
2358 self.stream.buffer.flush()
2359 else:
2360 self.stream.write(line)
2361 self.stream.flush()
2338 self.stream.flush()
2339 self.stream.buffer.write(line)
2340 self.stream.buffer.flush()
2362 2341
2363 2342 if servefail:
2364 2343 raise test.failureException(
@@ -3247,10 +3226,7 b' class TestRunner(object):'
3247 3226 fileb = _sys2bytes(__file__)
3248 3227 runtestdir = os.path.abspath(os.path.dirname(fileb))
3249 3228 osenvironb[b'RUNTESTDIR'] = runtestdir
3250 if PYTHON3:
3251 sepb = _sys2bytes(os.pathsep)
3252 else:
3253 sepb = os.pathsep
3229 sepb = _sys2bytes(os.pathsep)
3254 3230 path = [self._bindir, runtestdir] + osenvironb[b"PATH"].split(sepb)
3255 3231 if os.path.islink(__file__):
3256 3232 # test helper will likely be at the end of the symlink
@@ -3598,10 +3574,8 b' class TestRunner(object):'
3598 3574 pyexe_names = [b'python', b'python3', b'python.exe']
3599 3575 elif WINDOWS:
3600 3576 pyexe_names = [b'python', b'python.exe']
3601 elif PYTHON3:
3577 else:
3602 3578 pyexe_names = [b'python', b'python3']
3603 else:
3604 pyexe_names = [b'python', b'python2']
3605 3579
3606 3580 # os.symlink() is a thing with py3 on Windows, but it requires
3607 3581 # Administrator rights.
@@ -3766,10 +3740,7 b' class TestRunner(object):'
3766 3740 else:
3767 3741 with open(installerrs, 'rb') as f:
3768 3742 for line in f:
3769 if PYTHON3:
3770 sys.stdout.buffer.write(line)
3771 else:
3772 sys.stdout.write(line)
3743 sys.stdout.buffer.write(line)
3773 3744 sys.exit(1)
3774 3745 os.chdir(self._testdir)
3775 3746
@@ -3862,10 +3833,7 b' class TestRunner(object):'
3862 3833 )
3863 3834 out, _err = proc.communicate()
3864 3835 if proc.returncode != 0:
3865 if PYTHON3:
3866 sys.stdout.buffer.write(out)
3867 else:
3868 sys.stdout.write(out)
3836 sys.stdout.buffer.write(out)
3869 3837 sys.exit(1)
3870 3838
3871 3839 def _installrhg(self):
@@ -3889,10 +3857,7 b' class TestRunner(object):'
3889 3857 )
3890 3858 out, _err = proc.communicate()
3891 3859 if proc.returncode != 0:
3892 if PYTHON3:
3893 sys.stdout.buffer.write(out)
3894 else:
3895 sys.stdout.write(out)
3860 sys.stdout.buffer.write(out)
3896 3861 sys.exit(1)
3897 3862
3898 3863 def _build_pyoxidized(self):
@@ -3920,10 +3885,7 b' class TestRunner(object):'
3920 3885 )
3921 3886 out, _err = proc.communicate()
3922 3887 if proc.returncode != 0:
3923 if PYTHON3:
3924 sys.stdout.buffer.write(out)
3925 else:
3926 sys.stdout.write(out)
3888 sys.stdout.buffer.write(out)
3927 3889 sys.exit(1)
3928 3890
3929 3891 def _outputcoverage(self):
General Comments 0
You need to be logged in to leave comments. Login now