Mercurial > hg
comparison tests/run-tests.py @ 28582:cdbc25306696
run-tests: add --with-python3 to define a Python 3 interpreter
Currently, very few parts of Mercurial run under Python 3, notably the
test harness.
We want to write tests that run Python 3. For example, we want to
extend test-check-py3-compat.t to parse and load Python files.
However, we have a problem: finding appropriate files requires
running `hg files` and this requires Python 2 until `hg` works
with Python 3.
As a temporary workaround, we add --with-python3 to the test harness
to allow us to define the path to a Python 3 interpreter. This
interpreter is made available to the test environment via $PYTHON3 so
tests can run things with Python 3 while the test harness and `hg`
invocations continue to run from Python 2. To round out the feature,
a "py3exe" hghave check has been added.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Fri, 18 Mar 2016 16:17:56 -0700 |
parents | 1ad0ddf8cccc |
children | 9949950664cd |
comparison
equal
deleted
inserted
replaced
28581:3c8f0a605504 | 28582:cdbc25306696 |
---|---|
253 help="install and use chg wrapper in place of hg") | 253 help="install and use chg wrapper in place of hg") |
254 parser.add_option("--with-chg", metavar="CHG", | 254 parser.add_option("--with-chg", metavar="CHG", |
255 help="use specified chg wrapper in place of hg") | 255 help="use specified chg wrapper in place of hg") |
256 parser.add_option("-3", "--py3k-warnings", action="store_true", | 256 parser.add_option("-3", "--py3k-warnings", action="store_true", |
257 help="enable Py3k warnings on Python 2.6+") | 257 help="enable Py3k warnings on Python 2.6+") |
258 # This option should be deleted once test-check-py3-compat.t and other | |
259 # Python 3 tests run with Python 3. | |
260 parser.add_option("--with-python3", metavar="PYTHON3", | |
261 help="Python 3 interpreter (if running under Python 2)" | |
262 " (TEMPORARY)") | |
258 parser.add_option('--extra-config-opt', action="append", | 263 parser.add_option('--extra-config-opt', action="append", |
259 help='set the given config opt in the test hgrc') | 264 help='set the given config opt in the test hgrc') |
260 parser.add_option('--random', action="store_true", | 265 parser.add_option('--random', action="store_true", |
261 help='run tests in random order') | 266 help='run tests in random order') |
262 parser.add_option('--profile-runner', action='store_true', | 267 parser.add_option('--profile-runner', action='store_true', |
351 options.slowtimeout = 0 | 356 options.slowtimeout = 0 |
352 if options.py3k_warnings: | 357 if options.py3k_warnings: |
353 if PYTHON3: | 358 if PYTHON3: |
354 parser.error( | 359 parser.error( |
355 '--py3k-warnings can only be used on Python 2.6 and 2.7') | 360 '--py3k-warnings can only be used on Python 2.6 and 2.7') |
361 if options.with_python3: | |
362 if PYTHON3: | |
363 parser.error('--with-python3 cannot be used when executing with ' | |
364 'Python 3') | |
365 | |
366 # Verify Python3 executable is acceptable. | |
367 proc = subprocess.Popen([options.with_python3, b'--version'], | |
368 stdout=subprocess.PIPE, | |
369 stderr=subprocess.STDOUT) | |
370 out, _err = proc.communicate() | |
371 ret = proc.wait() | |
372 if ret != 0: | |
373 parser.error('could not determine version of python 3') | |
374 if not out.startswith('Python '): | |
375 parser.error('unexpected output from python3 --version: %s' % | |
376 out) | |
377 vers = version.LooseVersion(out[len('Python '):]) | |
378 if vers < version.LooseVersion('3.5.0'): | |
379 parser.error('--with-python3 version must be 3.5.0 or greater; ' | |
380 'got %s' % out) | |
381 | |
356 if options.blacklist: | 382 if options.blacklist: |
357 options.blacklist = parselistfiles(options.blacklist, 'blacklist') | 383 options.blacklist = parselistfiles(options.blacklist, 'blacklist') |
358 if options.whitelist: | 384 if options.whitelist: |
359 options.whitelisted = parselistfiles(options.whitelist, 'whitelist') | 385 options.whitelisted = parselistfiles(options.whitelist, 'whitelist') |
360 else: | 386 else: |
1985 self._hgcommand = os.path.basename(self.options.with_chg) | 2011 self._hgcommand = os.path.basename(self.options.with_chg) |
1986 | 2012 |
1987 osenvironb[b"BINDIR"] = self._bindir | 2013 osenvironb[b"BINDIR"] = self._bindir |
1988 osenvironb[b"PYTHON"] = PYTHON | 2014 osenvironb[b"PYTHON"] = PYTHON |
1989 | 2015 |
2016 if self.options.with_python3: | |
2017 osenvironb[b'PYTHON3'] = self.options.with_python3 | |
2018 | |
1990 fileb = _bytespath(__file__) | 2019 fileb = _bytespath(__file__) |
1991 runtestdir = os.path.abspath(os.path.dirname(fileb)) | 2020 runtestdir = os.path.abspath(os.path.dirname(fileb)) |
1992 osenvironb[b'RUNTESTDIR'] = runtestdir | 2021 osenvironb[b'RUNTESTDIR'] = runtestdir |
1993 if PYTHON3: | 2022 if PYTHON3: |
1994 sepb = _bytespath(os.pathsep) | 2023 sepb = _bytespath(os.pathsep) |