321 """ |
321 """ |
322 shutil.copy(src, dst) |
322 shutil.copy(src, dst) |
323 os.remove(src) |
323 os.remove(src) |
324 |
324 |
325 _unified_diff = difflib.unified_diff |
325 _unified_diff = difflib.unified_diff |
326 if sys.version_info[0] > 2: |
326 if PYTHON3: |
327 import functools |
327 import functools |
328 _unified_diff = functools.partial(difflib.diff_bytes, difflib.unified_diff) |
328 _unified_diff = functools.partial(difflib.diff_bytes, difflib.unified_diff) |
329 |
329 |
330 def getdiff(expected, output, ref, err): |
330 def getdiff(expected, output, ref, err): |
331 servefail = False |
331 servefail = False |
829 re.compile(br'^moving \S+/.*[^)]$'), |
829 re.compile(br'^moving \S+/.*[^)]$'), |
830 re.compile(br'^pulling from \$TESTTMP/.*[^)]$') |
830 re.compile(br'^pulling from \$TESTTMP/.*[^)]$') |
831 ] |
831 ] |
832 |
832 |
833 bchr = chr |
833 bchr = chr |
834 if sys.version_info[0] == 3: |
834 if PYTHON3: |
835 bchr = lambda x: bytes([x]) |
835 bchr = lambda x: bytes([x]) |
836 |
836 |
837 class TTest(Test): |
837 class TTest(Test): |
838 """A "t test" is a test backed by a .t file.""" |
838 """A "t test" is a test backed by a .t file.""" |
839 |
839 |
1116 def linematch(el, l): |
1116 def linematch(el, l): |
1117 if el == l: # perfect match (fast) |
1117 if el == l: # perfect match (fast) |
1118 return True |
1118 return True |
1119 if el: |
1119 if el: |
1120 if el.endswith(b" (esc)\n"): |
1120 if el.endswith(b" (esc)\n"): |
1121 if sys.version_info[0] == 3: |
1121 if PYTHON3: |
1122 el = el[:-7].decode('unicode_escape') + '\n' |
1122 el = el[:-7].decode('unicode_escape') + '\n' |
1123 el = el.encode('utf-8') |
1123 el = el.encode('utf-8') |
1124 else: |
1124 else: |
1125 el = el[:-7].decode('string-escape') + '\n' |
1125 el = el[:-7].decode('string-escape') + '\n' |
1126 if el == l or os.name == 'nt' and el[:-1] + b'\r\n' == l: |
1126 if el == l or os.name == 'nt' and el[:-1] + b'\r\n' == l: |
1276 with iolock: |
1276 with iolock: |
1277 if self._options.nodiff: |
1277 if self._options.nodiff: |
1278 pass |
1278 pass |
1279 elif self._options.view: |
1279 elif self._options.view: |
1280 v = self._options.view |
1280 v = self._options.view |
1281 if sys.version_info[0] == 3: |
1281 if PYTHON3: |
1282 v = v.encode('utf-8') |
1282 v = v.encode('utf-8') |
1283 os.system(b"%s %s %s" % |
1283 os.system(b"%s %s %s" % |
1284 (v, test.refpath, test.errpath)) |
1284 (v, test.refpath, test.errpath)) |
1285 else: |
1285 else: |
1286 servefail, lines = getdiff(expected, got, |
1286 servefail, lines = getdiff(expected, got, |
1290 test, |
1290 test, |
1291 'server failed to start (HGPORT=%s)' % test._startport) |
1291 'server failed to start (HGPORT=%s)' % test._startport) |
1292 else: |
1292 else: |
1293 self.stream.write('\n') |
1293 self.stream.write('\n') |
1294 for line in lines: |
1294 for line in lines: |
1295 if sys.version_info[0] > 2: |
1295 if PYTHON3: |
1296 self.stream.flush() |
1296 self.stream.flush() |
1297 self.stream.buffer.write(line) |
1297 self.stream.buffer.write(line) |
1298 self.stream.buffer.flush() |
1298 self.stream.buffer.flush() |
1299 else: |
1299 else: |
1300 self.stream.write(line) |
1300 self.stream.write(line) |
1734 self._installdir = None |
1734 self._installdir = None |
1735 whg = self.options.with_hg |
1735 whg = self.options.with_hg |
1736 # If --with-hg is not specified, we have bytes already, |
1736 # If --with-hg is not specified, we have bytes already, |
1737 # but if it was specified in python3 we get a str, so we |
1737 # but if it was specified in python3 we get a str, so we |
1738 # have to encode it back into a bytes. |
1738 # have to encode it back into a bytes. |
1739 if sys.version_info[0] == 3: |
1739 if PYTHON3: |
1740 if not isinstance(whg, bytes): |
1740 if not isinstance(whg, bytes): |
1741 whg = whg.encode('utf-8') |
1741 whg = whg.encode('utf-8') |
1742 self._bindir = os.path.dirname(os.path.realpath(whg)) |
1742 self._bindir = os.path.dirname(os.path.realpath(whg)) |
1743 assert isinstance(self._bindir, bytes) |
1743 assert isinstance(self._bindir, bytes) |
1744 self._tmpbindir = os.path.join(self._hgtmp, b'install', b'bin') |
1744 self._tmpbindir = os.path.join(self._hgtmp, b'install', b'bin') |
1760 osenvironb[b"BINDIR"] = self._bindir |
1760 osenvironb[b"BINDIR"] = self._bindir |
1761 osenvironb[b"PYTHON"] = PYTHON |
1761 osenvironb[b"PYTHON"] = PYTHON |
1762 |
1762 |
1763 fileb = __file__.encode('utf-8') |
1763 fileb = __file__.encode('utf-8') |
1764 runtestdir = os.path.abspath(os.path.dirname(fileb)) |
1764 runtestdir = os.path.abspath(os.path.dirname(fileb)) |
1765 if sys.version_info[0] == 3: |
1765 if PYTHON3: |
1766 sepb = os.pathsep.encode('utf-8') |
1766 sepb = os.pathsep.encode('utf-8') |
1767 else: |
1767 else: |
1768 sepb = os.pathsep |
1768 sepb = os.pathsep |
1769 path = [self._bindir, runtestdir] + osenvironb[b"PATH"].split(sepb) |
1769 path = [self._bindir, runtestdir] + osenvironb[b"PATH"].split(sepb) |
1770 if os.path.islink(__file__): |
1770 if os.path.islink(__file__): |
1846 tests = [self._gettest(t, i) for i, t in enumerate(tests)] |
1846 tests = [self._gettest(t, i) for i, t in enumerate(tests)] |
1847 |
1847 |
1848 failed = False |
1848 failed = False |
1849 warned = False |
1849 warned = False |
1850 kws = self.options.keywords |
1850 kws = self.options.keywords |
1851 if kws is not None and sys.version_info[0] == 3: |
1851 if kws is not None and PYTHON3: |
1852 kws = kws.encode('utf-8') |
1852 kws = kws.encode('utf-8') |
1853 |
1853 |
1854 suite = TestSuite(self._testdir, |
1854 suite = TestSuite(self._testdir, |
1855 jobs=self.options.jobs, |
1855 jobs=self.options.jobs, |
1856 whitelist=self.options.whitelisted, |
1856 whitelist=self.options.whitelisted, |
1993 py3 = '' |
1993 py3 = '' |
1994 |
1994 |
1995 # Run installer in hg root |
1995 # Run installer in hg root |
1996 script = os.path.realpath(sys.argv[0]) |
1996 script = os.path.realpath(sys.argv[0]) |
1997 exe = sys.executable |
1997 exe = sys.executable |
1998 if sys.version_info[0] == 3: |
1998 if PYTHON3: |
1999 py3 = b'--c2to3' |
1999 py3 = b'--c2to3' |
2000 compiler = compiler.encode('utf-8') |
2000 compiler = compiler.encode('utf-8') |
2001 script = script.encode('utf-8') |
2001 script = script.encode('utf-8') |
2002 exe = exe.encode('utf-8') |
2002 exe = exe.encode('utf-8') |
2003 hgroot = os.path.dirname(os.path.dirname(script)) |
2003 hgroot = os.path.dirname(os.path.dirname(script)) |
2037 if not self.options.verbose: |
2037 if not self.options.verbose: |
2038 os.remove(installerrs) |
2038 os.remove(installerrs) |
2039 else: |
2039 else: |
2040 f = open(installerrs, 'rb') |
2040 f = open(installerrs, 'rb') |
2041 for line in f: |
2041 for line in f: |
2042 if sys.version_info[0] > 2: |
2042 if PYTHON3: |
2043 sys.stdout.buffer.write(line) |
2043 sys.stdout.buffer.write(line) |
2044 else: |
2044 else: |
2045 sys.stdout.write(line) |
2045 sys.stdout.write(line) |
2046 f.close() |
2046 f.close() |
2047 sys.exit(1) |
2047 sys.exit(1) |
2113 if self._hgpath is not None: |
2113 if self._hgpath is not None: |
2114 return self._hgpath |
2114 return self._hgpath |
2115 |
2115 |
2116 cmd = b'%s -c "import mercurial; print (mercurial.__path__[0])"' |
2116 cmd = b'%s -c "import mercurial; print (mercurial.__path__[0])"' |
2117 cmd = cmd % PYTHON |
2117 cmd = cmd % PYTHON |
2118 if sys.version_info[0] > 2: |
2118 if PYTHON3: |
2119 cmd = cmd.decode('utf-8') |
2119 cmd = cmd.decode('utf-8') |
2120 pipe = os.popen(cmd) |
2120 pipe = os.popen(cmd) |
2121 try: |
2121 try: |
2122 self._hgpath = pipe.read().strip() |
2122 self._hgpath = pipe.read().strip() |
2123 if sys.version_info[0] == 3: |
2123 if PYTHON3: |
2124 self._hgpath = self._hgpath.encode('utf-8') |
2124 self._hgpath = self._hgpath.encode('utf-8') |
2125 finally: |
2125 finally: |
2126 pipe.close() |
2126 pipe.close() |
2127 |
2127 |
2128 return self._hgpath |
2128 return self._hgpath |
2155 os.mkdir(adir) |
2155 os.mkdir(adir) |
2156 cov.annotate(directory=adir, omit=omit) |
2156 cov.annotate(directory=adir, omit=omit) |
2157 |
2157 |
2158 def _findprogram(self, program): |
2158 def _findprogram(self, program): |
2159 """Search PATH for a executable program""" |
2159 """Search PATH for a executable program""" |
2160 if sys.version_info[0] > 2: |
2160 if PYTHON3: |
2161 dpb = os.defpath.encode('utf-8') |
2161 dpb = os.defpath.encode('utf-8') |
2162 sepb = os.pathsep.encode('utf-8') |
2162 sepb = os.pathsep.encode('utf-8') |
2163 else: |
2163 else: |
2164 dpb = os.defpath |
2164 dpb = os.defpath |
2165 sepb = os.pathsep |
2165 sepb = os.pathsep |