Mercurial > hg
comparison tests/run-tests.py @ 21385:28414e5ac9ec
run-tests: move _gethgpath() into TestRunner
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 20 Apr 2014 11:04:25 -0700 |
parents | a36cc85a5b7b |
children | 3b0c522f04aa |
comparison
equal
deleted
inserted
replaced
21384:a36cc85a5b7b | 21385:28414e5ac9ec |
---|---|
967 | 967 |
968 for s, r in replacements: | 968 for s, r in replacements: |
969 output = re.sub(s, r, output) | 969 output = re.sub(s, r, output) |
970 return ret, output.splitlines(True) | 970 return ret, output.splitlines(True) |
971 | 971 |
972 _hgpath = None | |
973 | |
974 def _gethgpath(): | |
975 """Return the path to the mercurial package that is actually found by | |
976 the current Python interpreter.""" | |
977 global _hgpath | |
978 if _hgpath is not None: | |
979 return _hgpath | |
980 | |
981 cmd = '%s -c "import mercurial; print (mercurial.__path__[0])"' | |
982 pipe = os.popen(cmd % PYTHON) | |
983 try: | |
984 _hgpath = pipe.read().strip() | |
985 finally: | |
986 pipe.close() | |
987 return _hgpath | |
988 | |
989 iolock = threading.Lock() | 972 iolock = threading.Lock() |
990 | 973 |
991 class TestRunner(object): | 974 class TestRunner(object): |
992 """Holds context for executing tests. | 975 """Holds context for executing tests. |
993 | 976 |
1026 's': [], | 1009 's': [], |
1027 'i': [], | 1010 'i': [], |
1028 } | 1011 } |
1029 self.abort = [False] | 1012 self.abort = [False] |
1030 self._createdfiles = [] | 1013 self._createdfiles = [] |
1014 self._hgpath = None | |
1031 | 1015 |
1032 def run(self, args, parser=None): | 1016 def run(self, args, parser=None): |
1033 """Run the test suite.""" | 1017 """Run the test suite.""" |
1034 oldmask = os.umask(022) | 1018 oldmask = os.umask(022) |
1035 try: | 1019 try: |
1377 | 1361 |
1378 def _checkhglib(self, verb): | 1362 def _checkhglib(self, verb): |
1379 """Ensure that the 'mercurial' package imported by python is | 1363 """Ensure that the 'mercurial' package imported by python is |
1380 the one we expect it to be. If not, print a warning to stderr.""" | 1364 the one we expect it to be. If not, print a warning to stderr.""" |
1381 expecthg = os.path.join(self.pythondir, 'mercurial') | 1365 expecthg = os.path.join(self.pythondir, 'mercurial') |
1382 actualhg = _gethgpath() | 1366 actualhg = self._gethgpath() |
1383 if os.path.abspath(actualhg) != os.path.abspath(expecthg): | 1367 if os.path.abspath(actualhg) != os.path.abspath(expecthg): |
1384 sys.stderr.write('warning: %s with unexpected mercurial lib: %s\n' | 1368 sys.stderr.write('warning: %s with unexpected mercurial lib: %s\n' |
1385 ' (expected %s)\n' | 1369 ' (expected %s)\n' |
1386 % (verb, actualhg, expecthg)) | 1370 % (verb, actualhg, expecthg)) |
1371 def _gethgpath(self): | |
1372 """Return the path to the mercurial package that is actually found by | |
1373 the current Python interpreter.""" | |
1374 if self._hgpath is not None: | |
1375 return self._hgpath | |
1376 | |
1377 cmd = '%s -c "import mercurial; print (mercurial.__path__[0])"' | |
1378 pipe = os.popen(cmd % PYTHON) | |
1379 try: | |
1380 self._hgpath = pipe.read().strip() | |
1381 finally: | |
1382 pipe.close() | |
1383 | |
1384 return self._hgpath | |
1387 | 1385 |
1388 def _outputtimes(self): | 1386 def _outputtimes(self): |
1389 vlog('# Producing time report') | 1387 vlog('# Producing time report') |
1390 self.times.sort(key=lambda t: (t[1], t[0]), reverse=True) | 1388 self.times.sort(key=lambda t: (t[1], t[0]), reverse=True) |
1391 cols = '%7.3f %s' | 1389 cols = '%7.3f %s' |