comparison tests/run-tests.py @ 21346:02087bc4f143

run-tests: move PYTHONDIR out of a global
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 19 Apr 2014 23:26:15 -0700
parents 8e7b0f4d6ac7
children 5b1b31137f95
comparison
equal deleted inserted replaced
21345:8e7b0f4d6ac7 21346:02087bc4f143
458 ' build %(compiler)s --build-base="%(base)s"' 458 ' build %(compiler)s --build-base="%(base)s"'
459 ' install --force --prefix="%(prefix)s" --install-lib="%(libdir)s"' 459 ' install --force --prefix="%(prefix)s" --install-lib="%(libdir)s"'
460 ' --install-scripts="%(bindir)s" %(nohome)s >%(logfile)s 2>&1' 460 ' --install-scripts="%(bindir)s" %(nohome)s >%(logfile)s 2>&1'
461 % {'exe': sys.executable, 'py3': py3, 'pure': pure, 461 % {'exe': sys.executable, 'py3': py3, 'pure': pure,
462 'compiler': compiler, 'base': os.path.join(runner.hgtmp, "build"), 462 'compiler': compiler, 'base': os.path.join(runner.hgtmp, "build"),
463 'prefix': runner.inst, 'libdir': PYTHONDIR, 463 'prefix': runner.inst, 'libdir': runner.pythondir,
464 'bindir': runner.bindir, 464 'bindir': runner.bindir,
465 'nohome': nohome, 'logfile': installerrs}) 465 'nohome': nohome, 'logfile': installerrs})
466 vlog("# Running", cmd) 466 vlog("# Running", cmd)
467 if os.system(cmd) == 0: 467 if os.system(cmd) == 0:
468 if not options.verbose: 468 if not options.verbose:
504 else: 504 else:
505 print 'WARNING: cannot fix hg.bat reference to python.exe' 505 print 'WARNING: cannot fix hg.bat reference to python.exe'
506 506
507 if options.anycoverage: 507 if options.anycoverage:
508 custom = os.path.join(runner.testdir, 'sitecustomize.py') 508 custom = os.path.join(runner.testdir, 'sitecustomize.py')
509 target = os.path.join(PYTHONDIR, 'sitecustomize.py') 509 target = os.path.join(runner.pythondir, 'sitecustomize.py')
510 vlog('# Installing coverage trigger to %s' % target) 510 vlog('# Installing coverage trigger to %s' % target)
511 shutil.copyfile(custom, target) 511 shutil.copyfile(custom, target)
512 rc = os.path.join(runner.testdir, '.coveragerc') 512 rc = os.path.join(runner.testdir, '.coveragerc')
513 vlog('# Installing coverage rc to %s' % rc) 513 vlog('# Installing coverage rc to %s' % rc)
514 os.environ['COVERAGE_PROCESS_START'] = rc 514 os.environ['COVERAGE_PROCESS_START'] = rc
524 print cols % (timetaken, test) 524 print cols % (timetaken, test)
525 525
526 def outputcoverage(runner, options): 526 def outputcoverage(runner, options):
527 527
528 vlog('# Producing coverage report') 528 vlog('# Producing coverage report')
529 os.chdir(PYTHONDIR) 529 os.chdir(runner.pythondir)
530 530
531 def covrun(*args): 531 def covrun(*args):
532 cmd = 'coverage %s' % ' '.join(args) 532 cmd = 'coverage %s' % ' '.join(args)
533 vlog('# Running: %s' % cmd) 533 vlog('# Running: %s' % cmd)
534 os.system(cmd) 534 os.system(cmd)
1168 _hgpath = pipe.read().strip() 1168 _hgpath = pipe.read().strip()
1169 finally: 1169 finally:
1170 pipe.close() 1170 pipe.close()
1171 return _hgpath 1171 return _hgpath
1172 1172
1173 def _checkhglib(verb): 1173 def _checkhglib(runner, verb):
1174 """Ensure that the 'mercurial' package imported by python is 1174 """Ensure that the 'mercurial' package imported by python is
1175 the one we expect it to be. If not, print a warning to stderr.""" 1175 the one we expect it to be. If not, print a warning to stderr."""
1176 expecthg = os.path.join(PYTHONDIR, 'mercurial') 1176 expecthg = os.path.join(runner.pythondir, 'mercurial')
1177 actualhg = _gethgpath() 1177 actualhg = _gethgpath()
1178 if os.path.abspath(actualhg) != os.path.abspath(expecthg): 1178 if os.path.abspath(actualhg) != os.path.abspath(expecthg):
1179 sys.stderr.write('warning: %s with unexpected mercurial lib: %s\n' 1179 sys.stderr.write('warning: %s with unexpected mercurial lib: %s\n'
1180 ' (expected %s)\n' 1180 ' (expected %s)\n'
1181 % (verb, actualhg, expecthg)) 1181 % (verb, actualhg, expecthg))
1227 1227
1228 def runtests(runner, options, tests): 1228 def runtests(runner, options, tests):
1229 try: 1229 try:
1230 if runner.inst: 1230 if runner.inst:
1231 installhg(runner, options) 1231 installhg(runner, options)
1232 _checkhglib("Testing") 1232 _checkhglib(runner, "Testing")
1233 else: 1233 else:
1234 usecorrectpython(runner) 1234 usecorrectpython(runner)
1235 1235
1236 if options.restart: 1236 if options.restart:
1237 orig = list(tests) 1237 orig = list(tests)
1257 print "Skipped %s: %s" % s 1257 print "Skipped %s: %s" % s
1258 for s in results['~']: 1258 for s in results['~']:
1259 print "Warned %s: %s" % s 1259 print "Warned %s: %s" % s
1260 for s in results['!']: 1260 for s in results['!']:
1261 print "Failed %s: %s" % s 1261 print "Failed %s: %s" % s
1262 _checkhglib("Tested") 1262 _checkhglib(runner, "Tested")
1263 print "# Ran %d tests, %d skipped, %d warned, %d failed." % ( 1263 print "# Ran %d tests, %d skipped, %d warned, %d failed." % (
1264 tested, skipped + ignored, warned, failed) 1264 tested, skipped + ignored, warned, failed)
1265 if results['!']: 1265 if results['!']:
1266 print 'python hash seed:', os.environ['PYTHONHASHSEED'] 1266 print 'python hash seed:', os.environ['PYTHONHASHSEED']
1267 if options.time: 1267 if options.time:
1290 self.testdir = None 1290 self.testdir = None
1291 self.hgtmp = None 1291 self.hgtmp = None
1292 self.inst = None 1292 self.inst = None
1293 self.bindir = None 1293 self.bindir = None
1294 self.tmpbinddir = None 1294 self.tmpbinddir = None
1295 self.pythondir = None
1295 1296
1296 def main(args, parser=None): 1297 def main(args, parser=None):
1297 runner = TestRunner() 1298 runner = TestRunner()
1298 1299
1299 parser = parser or getparser() 1300 parser = parser or getparser()
1337 if 'PYTHONHASHSEED' not in os.environ: 1338 if 'PYTHONHASHSEED' not in os.environ:
1338 # use a random python hash seed all the time 1339 # use a random python hash seed all the time
1339 # we do the randomness ourself to know what seed is used 1340 # we do the randomness ourself to know what seed is used
1340 os.environ['PYTHONHASHSEED'] = str(random.getrandbits(32)) 1341 os.environ['PYTHONHASHSEED'] = str(random.getrandbits(32))
1341 1342
1342 global PYTHONDIR, COVERAGE_FILE 1343 global COVERAGE_FILE
1343 runner.testdir = os.environ['TESTDIR'] = os.getcwd() 1344 runner.testdir = os.environ['TESTDIR'] = os.getcwd()
1344 if options.tmpdir: 1345 if options.tmpdir:
1345 options.keep_tmpdir = True 1346 options.keep_tmpdir = True
1346 tmpdir = options.tmpdir 1347 tmpdir = options.tmpdir
1347 if os.path.exists(tmpdir): 1348 if os.path.exists(tmpdir):
1375 # This looks redundant with how Python initializes sys.path from 1376 # This looks redundant with how Python initializes sys.path from
1376 # the location of the script being executed. Needed because the 1377 # the location of the script being executed. Needed because the
1377 # "hg" specified by --with-hg is not the only Python script 1378 # "hg" specified by --with-hg is not the only Python script
1378 # executed in the test suite that needs to import 'mercurial' 1379 # executed in the test suite that needs to import 'mercurial'
1379 # ... which means it's not really redundant at all. 1380 # ... which means it's not really redundant at all.
1380 PYTHONDIR = runner.bindir 1381 runner.pythondir = runner.bindir
1381 else: 1382 else:
1382 runner.inst = os.path.join(runner.hgtmp, "install") 1383 runner.inst = os.path.join(runner.hgtmp, "install")
1383 runner.bindir = os.environ["BINDIR"] = os.path.join(runner.inst, 1384 runner.bindir = os.environ["BINDIR"] = os.path.join(runner.inst,
1384 "bin") 1385 "bin")
1385 runner.tmpbindir = runner.bindir 1386 runner.tmpbindir = runner.bindir
1386 PYTHONDIR = os.path.join(runner.inst, "lib", "python") 1387 runner.pythondir = os.path.join(runner.inst, "lib", "python")
1387 1388
1388 os.environ["BINDIR"] = runner.bindir 1389 os.environ["BINDIR"] = runner.bindir
1389 os.environ["PYTHON"] = PYTHON 1390 os.environ["PYTHON"] = PYTHON
1390 1391
1391 path = [runner.bindir] + os.environ["PATH"].split(os.pathsep) 1392 path = [runner.bindir] + os.environ["PATH"].split(os.pathsep)
1395 1396
1396 # Include TESTDIR in PYTHONPATH so that out-of-tree extensions 1397 # Include TESTDIR in PYTHONPATH so that out-of-tree extensions
1397 # can run .../tests/run-tests.py test-foo where test-foo 1398 # can run .../tests/run-tests.py test-foo where test-foo
1398 # adds an extension to HGRC. Also include run-test.py directory to import 1399 # adds an extension to HGRC. Also include run-test.py directory to import
1399 # modules like heredoctest. 1400 # modules like heredoctest.
1400 pypath = [PYTHONDIR, runner.testdir, 1401 pypath = [runner.pythondir, runner.testdir,
1401 os.path.abspath(os.path.dirname(__file__))] 1402 os.path.abspath(os.path.dirname(__file__))]
1402 # We have to augment PYTHONPATH, rather than simply replacing 1403 # We have to augment PYTHONPATH, rather than simply replacing
1403 # it, in case external libraries are only available via current 1404 # it, in case external libraries are only available via current
1404 # PYTHONPATH. (In particular, the Subversion bindings on OS X 1405 # PYTHONPATH. (In particular, the Subversion bindings on OS X
1405 # are in /opt/subversion.) 1406 # are in /opt/subversion.)