##// END OF EJS Templates
run-tests: factor out _checkhglib() to check import path of 'mercurial'....
Greg Ward -
r8672:d6b24373 default
parent child Browse files
Show More
@@ -205,7 +205,6 b' def usecorrectpython():'
205 205 shutil.copymode(sys.executable, mypython)
206 206
207 207 def installhg(options):
208 global PYTHON
209 208 vlog("# Performing temporary installation of HG")
210 209 installerrs = os.path.join("tests", "install.err")
211 210 pure = options.pure and "--pure" or ""
@@ -239,8 +238,6 b' def installhg(options):'
239 238 os.environ["PYTHONPATH"] = pythonpath
240 239
241 240 usecorrectpython()
242 global hgpkg
243 hgpkg = _hgpath()
244 241
245 242 vlog("# Installing dummy diffstat")
246 243 f = open(os.path.join(BINDIR, 'diffstat'), 'w')
@@ -269,15 +266,6 b' def installhg(options):'
269 266 os.path.join(BINDIR, '_hg.py')))
270 267 f.close()
271 268 os.chmod(os.path.join(BINDIR, 'hg'), 0700)
272 PYTHON = '"%s" "%s" -x -p' % (sys.executable,
273 os.path.join(TESTDIR, 'coverage.py'))
274
275 def _hgpath():
276 cmd = '%s -c "import mercurial; print mercurial.__path__[0]"'
277 hgpath = os.popen(cmd % PYTHON)
278 path = hgpath.read().strip()
279 hgpath.close()
280 return path
281 269
282 270 def outputcoverage(options):
283 271
@@ -496,11 +484,35 b' def runone(options, test, skips, fails):'
496 484 return None
497 485 return ret == 0
498 486
499 def runchildren(options, expecthg, tests):
487 _hgpath = None
488
489 def _gethgpath():
490 """Return the path to the mercurial package that is actually found by
491 the current Python interpreter."""
492 global _hgpath
493 if _hgpath is not None:
494 return _hgpath
495
496 cmd = '%s -c "import mercurial; print mercurial.__path__[0]"'
497 pipe = os.popen(cmd % PYTHON)
498 try:
499 _hgpath = pipe.read().strip()
500 finally:
501 pipe.close()
502 return _hgpath
503
504 def _checkhglib(verb):
505 """Ensure that the 'mercurial' package imported by python is
506 the one we expect it to be. If not, print a message to stdout."""
507 expecthg = os.path.join(HGTMP, 'install', 'lib', 'python', 'mercurial')
508 actualhg = _gethgpath()
509 if actualhg != expecthg:
510 print '# %s unexpected mercurial: %s' % (verb, actualhg)
511
512 def runchildren(options, tests):
500 513 if not options.with_hg:
501 514 installhg(options)
502 if hgpkg != expecthg:
503 print '# Testing unexpected mercurial: %s' % hgpkg
515 _checkhglib("Testing")
504 516
505 517 optcopy = dict(options.__dict__)
506 518 optcopy['jobs'] = 1
@@ -554,13 +566,12 b' def runchildren(options, expecthg, tests'
554 566 for s in fails:
555 567 print "Failed %s: %s" % (s[0], s[1])
556 568
557 if hgpkg != expecthg:
558 print '# Tested unexpected mercurial: %s' % hgpkg
569 _checkhglib("Tested")
559 570 print "# Ran %d tests, %d skipped, %d failed." % (
560 571 tested, skipped, failed)
561 572 sys.exit(failures != 0)
562 573
563 def runtests(options, expecthg, tests):
574 def runtests(options, tests):
564 575 global DAEMON_PIDS, HGRCPATH
565 576 DAEMON_PIDS = os.environ["DAEMON_PIDS"] = os.path.join(HGTMP, 'daemon.pids')
566 577 HGRCPATH = os.environ["HGRCPATH"] = os.path.join(HGTMP, '.hgrc')
@@ -568,9 +579,7 b' def runtests(options, expecthg, tests):'
568 579 try:
569 580 if not options.with_hg:
570 581 installhg(options)
571
572 if hgpkg != expecthg:
573 print '# Testing unexpected mercurial: %s' % hgpkg
582 _checkhglib("Testing")
574 583
575 584 if options.timeout > 0:
576 585 try:
@@ -632,8 +641,7 b' def runtests(options, expecthg, tests):'
632 641 print "Skipped %s: %s" % s
633 642 for s in fails:
634 643 print "Failed %s: %s" % s
635 if hgpkg != expecthg:
636 print '# Tested unexpected mercurial: %s' % hgpkg
644 _checkhglib("Tested")
637 645 print "# Ran %d tests, %d skipped, %d failed." % (
638 646 tested, skipped, failed)
639 647
@@ -684,8 +692,6 b' def main():'
684 692 PYTHONDIR = os.path.join(INST, "lib", "python")
685 693 COVERAGE_FILE = os.path.join(TESTDIR, ".coverage")
686 694
687 expecthg = os.path.join(HGTMP, 'install', 'lib', 'python', 'mercurial')
688
689 695 if len(args) == 0:
690 696 args = os.listdir(".")
691 697 args.sort()
@@ -705,9 +711,9 b' def main():'
705 711
706 712 try:
707 713 if len(tests) > 1 and options.jobs > 1:
708 runchildren(options, expecthg, tests)
714 runchildren(options, tests)
709 715 else:
710 runtests(options, expecthg, tests)
716 runtests(options, tests)
711 717 finally:
712 718 cleanup(options)
713 719
General Comments 0
You need to be logged in to leave comments. Login now