Mercurial > hg
comparison tests/run-tests.py @ 21299:7861de61583b
run-tests: move createenv() into Test
createenv() is consulting lots of test-specific variables. It makes
sense to attach it to the Test class.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 19 Apr 2014 13:07:05 -0700 |
parents | ba4750352180 |
children | a2774731a51a |
comparison
equal
deleted
inserted
replaced
21298:ba4750352180 | 21299:7861de61583b |
---|---|
362 assert '=' in key, ('extra config opt %s must ' | 362 assert '=' in key, ('extra config opt %s must ' |
363 'have an = for assignment' % opt) | 363 'have an = for assignment' % opt) |
364 hgrc.write('[%s]\n%s\n' % (section, key)) | 364 hgrc.write('[%s]\n%s\n' % (section, key)) |
365 hgrc.close() | 365 hgrc.close() |
366 | 366 |
367 def createenv(options, testtmp, threadtmp, port): | |
368 env = os.environ.copy() | |
369 env['TESTTMP'] = testtmp | |
370 env['HOME'] = testtmp | |
371 env["HGPORT"] = str(port) | |
372 env["HGPORT1"] = str(port + 1) | |
373 env["HGPORT2"] = str(port + 2) | |
374 env["HGRCPATH"] = os.path.join(threadtmp, '.hgrc') | |
375 env["DAEMON_PIDS"] = os.path.join(threadtmp, 'daemon.pids') | |
376 env["HGEDITOR"] = sys.executable + ' -c "import sys; sys.exit(0)"' | |
377 env["HGMERGE"] = "internal:merge" | |
378 env["HGUSER"] = "test" | |
379 env["HGENCODING"] = "ascii" | |
380 env["HGENCODINGMODE"] = "strict" | |
381 | |
382 # Reset some environment variables to well-known values so that | |
383 # the tests produce repeatable output. | |
384 env['LANG'] = env['LC_ALL'] = env['LANGUAGE'] = 'C' | |
385 env['TZ'] = 'GMT' | |
386 env["EMAIL"] = "Foo Bar <foo.bar@example.com>" | |
387 env['COLUMNS'] = '80' | |
388 env['TERM'] = 'xterm' | |
389 | |
390 for k in ('HG HGPROF CDPATH GREP_OPTIONS http_proxy no_proxy ' + | |
391 'NO_PROXY').split(): | |
392 if k in env: | |
393 del env[k] | |
394 | |
395 # unset env related to hooks | |
396 for k in env.keys(): | |
397 if k.startswith('HG_'): | |
398 del env[k] | |
399 | |
400 return env | |
401 | |
402 def checktools(): | 367 def checktools(): |
403 # Before we go any further, check for pre-requisite tools | 368 # Before we go any further, check for pre-requisite tools |
404 # stuff from coreutils (cat, rm, etc) are not tested | 369 # stuff from coreutils (cat, rm, etc) are not tested |
405 for p in requiredtools: | 370 for p in requiredtools: |
406 if os.name == 'nt' and not p.endswith('.exe'): | 371 if os.name == 'nt' and not p.endswith('.exe'): |
583 """Encapsulates a single, runnable test.""" | 548 """Encapsulates a single, runnable test.""" |
584 | 549 |
585 def __init__(self, path, options, threadtmp): | 550 def __init__(self, path, options, threadtmp): |
586 self._path = path | 551 self._path = path |
587 self._options = options | 552 self._options = options |
553 self._threadtmp = threadtmp | |
588 | 554 |
589 self.testtmp = os.path.join(threadtmp, os.path.basename(path)) | 555 self.testtmp = os.path.join(threadtmp, os.path.basename(path)) |
590 os.mkdir(self.testtmp) | 556 os.mkdir(self.testtmp) |
591 | 557 |
592 def run(self, replacements, env): | 558 def run(self, replacements, env): |
610 for c in self.testtmp), '$TESTTMP')) | 576 for c in self.testtmp), '$TESTTMP')) |
611 else: | 577 else: |
612 r.append((re.escape(self.testtmp), '$TESTTMP')) | 578 r.append((re.escape(self.testtmp), '$TESTTMP')) |
613 | 579 |
614 return r, port | 580 return r, port |
581 | |
582 def getenv(self, port): | |
583 env = os.environ.copy() | |
584 env['TESTTMP'] = self.testtmp | |
585 env['HOME'] = self.testtmp | |
586 env["HGPORT"] = str(port) | |
587 env["HGPORT1"] = str(port + 1) | |
588 env["HGPORT2"] = str(port + 2) | |
589 env["HGRCPATH"] = os.path.join(self._threadtmp, '.hgrc') | |
590 env["DAEMON_PIDS"] = os.path.join(self._threadtmp, 'daemon.pids') | |
591 env["HGEDITOR"] = sys.executable + ' -c "import sys; sys.exit(0)"' | |
592 env["HGMERGE"] = "internal:merge" | |
593 env["HGUSER"] = "test" | |
594 env["HGENCODING"] = "ascii" | |
595 env["HGENCODINGMODE"] = "strict" | |
596 | |
597 # Reset some environment variables to well-known values so that | |
598 # the tests produce repeatable output. | |
599 env['LANG'] = env['LC_ALL'] = env['LANGUAGE'] = 'C' | |
600 env['TZ'] = 'GMT' | |
601 env["EMAIL"] = "Foo Bar <foo.bar@example.com>" | |
602 env['COLUMNS'] = '80' | |
603 env['TERM'] = 'xterm' | |
604 | |
605 for k in ('HG HGPROF CDPATH GREP_OPTIONS http_proxy no_proxy ' + | |
606 'NO_PROXY').split(): | |
607 if k in env: | |
608 del env[k] | |
609 | |
610 # unset env related to hooks | |
611 for k in env.keys(): | |
612 if k.startswith('HG_'): | |
613 del env[k] | |
614 | |
615 return env | |
615 | 616 |
616 def pytest(test, wd, options, replacements, env): | 617 def pytest(test, wd, options, replacements, env): |
617 py3kswitch = options.py3k_warnings and ' -3' or '' | 618 py3kswitch = options.py3k_warnings and ' -3' or '' |
618 cmd = '%s%s "%s"' % (PYTHON, py3kswitch, test) | 619 cmd = '%s%s "%s"' % (PYTHON, py3kswitch, test) |
619 vlog("# Running", cmd) | 620 vlog("# Running", cmd) |
1016 threadtmp = os.path.join(HGTMP, "child%d" % count) | 1017 threadtmp = os.path.join(HGTMP, "child%d" % count) |
1017 os.mkdir(threadtmp) | 1018 os.mkdir(threadtmp) |
1018 | 1019 |
1019 t = runner(testpath, options, threadtmp) | 1020 t = runner(testpath, options, threadtmp) |
1020 replacements, port = t.getreplacements(count) | 1021 replacements, port = t.getreplacements(count) |
1021 env = createenv(options, t.testtmp, threadtmp, port) | 1022 env = t.getenv(port) |
1022 createhgrc(env['HGRCPATH'], options) | 1023 createhgrc(env['HGRCPATH'], options) |
1023 | 1024 |
1024 starttime = time.time() | 1025 starttime = time.time() |
1025 try: | 1026 try: |
1026 ret, out = t.run(replacements, env) | 1027 ret, out = t.run(replacements, env) |