2019-08-15 21:31:48 +03:00
|
|
|
# Copyright (c) Facebook, Inc. and its affiliates.
|
2018-02-02 23:17:58 +03:00
|
|
|
#
|
|
|
|
# This software may be used and distributed according to the terms of the
|
2019-08-15 21:31:48 +03:00
|
|
|
# GNU General Public License version 2.
|
|
|
|
|
|
|
|
# Translate run-tests.py tests to Python standard unittests
|
2018-02-02 23:17:58 +03:00
|
|
|
|
|
|
|
import contextlib
|
|
|
|
import glob
|
|
|
|
import os
|
2018-02-05 23:15:55 +03:00
|
|
|
import random
|
2018-02-02 23:17:58 +03:00
|
|
|
import re
|
2018-04-12 14:08:23 +03:00
|
|
|
import shlex
|
2018-02-02 23:17:58 +03:00
|
|
|
import subprocess
|
2018-06-15 07:21:16 +03:00
|
|
|
import sys
|
2018-02-02 23:17:58 +03:00
|
|
|
import unittest
|
|
|
|
|
2021-03-12 20:01:03 +03:00
|
|
|
import libfb.py.parutil as parutil
|
2021-03-17 14:23:38 +03:00
|
|
|
import libfb.py.parutil as parutil
|
2021-03-12 20:01:03 +03:00
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2018-06-15 07:21:16 +03:00
|
|
|
try:
|
2019-12-10 02:24:31 +03:00
|
|
|
# Used by :run_tests binary target
|
2018-06-15 07:21:16 +03:00
|
|
|
import libfb.py.pathutils as pathutils
|
|
|
|
|
2021-03-17 00:21:26 +03:00
|
|
|
hgpath = parutil.get_file_path("hg.sh", pkg=__package__)
|
|
|
|
pythonbinpath = parutil.get_file_path("hgpython.sh", pkg=__package__)
|
2021-03-12 20:01:03 +03:00
|
|
|
watchman = parutil.get_file_path("watchman", pkg=__package__)
|
|
|
|
mononoke_server = parutil.get_file_path("mononoke", pkg=__package__)
|
|
|
|
mononoke_hgcli = parutil.get_file_path("hgcli", pkg=__package__)
|
|
|
|
edenapi_server = parutil.get_file_path("edenapi_server", pkg=__package__)
|
|
|
|
dummyssh = parutil.get_file_path("dummyssh3.par", pkg=__package__)
|
|
|
|
get_free_socket = parutil.get_file_path("get_free_socket.par", pkg=__package__)
|
2018-06-15 07:21:16 +03:00
|
|
|
except ImportError:
|
2019-12-10 02:24:31 +03:00
|
|
|
# Used by :hg_run_tests and :hg_watchman_run_tests unittest target
|
2018-06-15 07:21:16 +03:00
|
|
|
hgpath = os.environ.get("HGTEST_HG")
|
|
|
|
pythonbinpath = os.environ.get("HGTEST_PYTHON", "python2")
|
2018-06-21 05:27:18 +03:00
|
|
|
watchman = os.environ.get("HGTEST_WATCHMAN")
|
2019-05-29 11:27:22 +03:00
|
|
|
mononoke_server = os.environ.get("HGTEST_MONONOKE_SERVER")
|
|
|
|
mononoke_hgcli = os.environ.get("HGTEST_MONONOKE_HGCLI")
|
2020-06-23 01:16:49 +03:00
|
|
|
edenapi_server = os.environ.get("HGTEST_EDENAPI_SERVER")
|
2020-08-17 12:40:58 +03:00
|
|
|
dummyssh = os.environ.get("HGTEST_DUMMYSSH")
|
|
|
|
get_free_socket = os.environ.get("HGTEST_GET_FREE_SOCKET")
|
2018-06-15 07:21:16 +03:00
|
|
|
|
|
|
|
|
2019-12-21 03:09:56 +03:00
|
|
|
if watchman is not None and not os.path.exists(str(watchman)):
|
|
|
|
watchman = None
|
|
|
|
|
|
|
|
os.environ["PYTHON_SYS_EXECUTABLE"] = pythonbinpath
|
|
|
|
|
2018-04-12 14:08:23 +03:00
|
|
|
try:
|
|
|
|
shlex_quote = shlex.quote # Python 3.3 and up
|
|
|
|
except AttributeError:
|
2020-05-22 05:31:01 +03:00
|
|
|
# pyre-fixme[9]: shlex_quote has type `(s: str) -> str`; used as `(seq:
|
|
|
|
# Sequence[str]) -> str`.
|
|
|
|
# pyre-fixme[9]: shlex_quote has type `(s: str) -> str`; used as `(seq:
|
|
|
|
# Sequence[str]) -> str`.
|
2018-04-12 14:08:23 +03:00
|
|
|
shlex_quote = subprocess.list2cmdline
|
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2018-02-02 23:17:58 +03:00
|
|
|
@contextlib.contextmanager
|
|
|
|
def chdir(path):
|
|
|
|
oldpwd = os.getcwd()
|
|
|
|
try:
|
|
|
|
os.chdir(path)
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
os.chdir(oldpwd)
|
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2018-06-15 07:21:16 +03:00
|
|
|
def prepareargsenv(runtestsdir, port=None):
|
|
|
|
"""return (args, env) for running run-tests.py"""
|
|
|
|
if not os.path.exists(os.path.join(runtestsdir, "run-tests.py")):
|
|
|
|
raise SystemExit("cannot find run-tests.py from %s" % runtestsdir)
|
|
|
|
env = os.environ.copy()
|
2018-09-15 05:00:39 +03:00
|
|
|
args = [pythonbinpath, "run-tests.py", "--maxdifflines=1000"]
|
2018-06-15 07:21:16 +03:00
|
|
|
if port:
|
|
|
|
args += ["--port", "%s" % port]
|
|
|
|
|
|
|
|
if hgpath:
|
|
|
|
args.append("--with-hg=%s" % hgpath)
|
2018-06-21 05:27:18 +03:00
|
|
|
if watchman:
|
|
|
|
args += ["--with-watchman", watchman]
|
2018-06-15 07:21:16 +03:00
|
|
|
# set HGDATAPATH
|
2019-01-29 05:29:48 +03:00
|
|
|
datapath = os.path.join(runtestsdir, "../edenscm/mercurial")
|
2018-06-15 07:21:16 +03:00
|
|
|
env["HGDATAPATH"] = datapath
|
|
|
|
# set HGPYTHONPATH since PYTHONPATH might be discarded
|
|
|
|
pythonpath = os.pathsep.join([runtestsdir])
|
|
|
|
env["HGPYTHONPATH"] = pythonpath
|
|
|
|
# set other environments useful for buck testing
|
|
|
|
env["HGTEST_NORMAL_LAYOUT"] = "0"
|
2020-08-17 12:40:58 +03:00
|
|
|
if dummyssh is not None:
|
|
|
|
env["DUMMYSSH"] = dummyssh
|
2019-05-29 11:27:22 +03:00
|
|
|
|
|
|
|
# Variables needed for mononoke integration
|
|
|
|
if os.environ.get("USE_MONONOKE"):
|
|
|
|
env["MONONOKE_SERVER"] = mononoke_server
|
|
|
|
env["MONONOKE_HGCLI"] = mononoke_hgcli
|
2020-06-23 01:16:49 +03:00
|
|
|
env["EDENAPI_SERVER"] = edenapi_server
|
2020-08-17 12:40:58 +03:00
|
|
|
env["GET_FREE_SOCKET"] = get_free_socket
|
2019-05-29 11:27:22 +03:00
|
|
|
|
2018-06-15 07:21:16 +03:00
|
|
|
return args, env
|
|
|
|
|
|
|
|
|
2018-02-02 23:17:58 +03:00
|
|
|
def gettestmethod(name, port):
|
|
|
|
def runsingletest(self):
|
2018-10-27 01:44:49 +03:00
|
|
|
reportskips = os.getenv("HGTEST_REPORT_SKIPS")
|
2018-02-02 23:17:58 +03:00
|
|
|
with chdir(self._runtests_dir):
|
2018-06-15 19:57:48 +03:00
|
|
|
args, env = prepareargsenv(self._runtests_dir, port)
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
args += os.getenv("HGTEST_RUNTESTS_ARGS", "").split()
|
2018-02-02 23:17:58 +03:00
|
|
|
# run run-tests.py for a single test
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
p = subprocess.Popen(
|
|
|
|
args + [name], env=env, stderr=subprocess.PIPE, stdout=subprocess.PIPE
|
|
|
|
)
|
|
|
|
out, err = p.communicate("")
|
2019-12-07 08:00:00 +03:00
|
|
|
message = err + out
|
2018-02-02 23:17:58 +03:00
|
|
|
returncode = p.returncode
|
2020-01-29 21:05:29 +03:00
|
|
|
if b"Lost connection to MySQL server" in message:
|
2019-12-07 08:00:00 +03:00
|
|
|
raise unittest.SkipTest("MySQL is unavailable")
|
2018-02-02 23:17:58 +03:00
|
|
|
if returncode == 80:
|
2018-10-27 01:44:49 +03:00
|
|
|
if not reportskips:
|
|
|
|
return
|
2018-02-02 23:17:58 +03:00
|
|
|
# Extract skipped reason from output
|
2020-01-31 04:21:17 +03:00
|
|
|
match = re.search(b"Skipped [^:]*: (.*)", message)
|
2018-02-02 23:17:58 +03:00
|
|
|
if match:
|
|
|
|
reason = match.group(1)
|
|
|
|
else:
|
2020-01-31 04:21:17 +03:00
|
|
|
reason = b"skipped by run-tests.py"
|
2018-02-02 23:17:58 +03:00
|
|
|
raise unittest.SkipTest(reason)
|
|
|
|
elif returncode != 0:
|
2020-10-04 14:49:10 +03:00
|
|
|
raise self.failureException(
|
|
|
|
message.decode("utf-8", errors="surrogateescape")
|
|
|
|
)
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2018-02-02 23:17:58 +03:00
|
|
|
return runsingletest
|
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2018-02-02 23:17:58 +03:00
|
|
|
class hgtests(unittest.TestCase):
|
|
|
|
@classmethod
|
|
|
|
def collecttests(cls, path):
|
|
|
|
"""scan tests in path and add them as test methods"""
|
2020-06-20 01:31:58 +03:00
|
|
|
if os.environ.get("HGTEST_IGNORE_INCLUDED") == "1":
|
|
|
|
included = None
|
2019-05-28 13:12:27 +03:00
|
|
|
else:
|
2020-06-20 01:31:58 +03:00
|
|
|
included = re.compile(r"\A%s\Z" % os.environ.get("HGTEST_INCLUDED", ".*"))
|
2019-05-28 13:12:27 +03:00
|
|
|
|
2020-06-20 01:31:58 +03:00
|
|
|
if os.environ.get("HGTEST_IGNORE_EXCLUDED") == "1":
|
|
|
|
excluded = None
|
2018-02-02 23:17:58 +03:00
|
|
|
else:
|
2020-06-20 01:31:58 +03:00
|
|
|
excluded = re.compile(r"\A%s\Z" % os.environ.get("HGTEST_EXCLUDED", ""))
|
2018-02-05 23:15:55 +03:00
|
|
|
# Randomize the port so a stress run of a single test would be fine
|
|
|
|
port = random.randint(10000, 60000)
|
2018-02-02 23:17:58 +03:00
|
|
|
with chdir(path):
|
|
|
|
cls._runtests_dir = os.getcwd()
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
for name in glob.glob("test-*.t") + glob.glob("test-*.py"):
|
|
|
|
method_name = name.replace(".", "_").replace("-", "_")
|
2020-06-20 01:31:58 +03:00
|
|
|
if included and not included.match(method_name):
|
2019-05-28 13:12:27 +03:00
|
|
|
continue
|
2020-06-20 01:31:58 +03:00
|
|
|
if excluded and excluded.match(method_name):
|
2018-02-02 23:17:58 +03:00
|
|
|
continue
|
|
|
|
# Running a lot run-tests.py in parallel will trigger race
|
|
|
|
# condition of the original port detection logic. So allocate
|
|
|
|
# ports here. run-tests.py could do adjustments.
|
|
|
|
# A test needs 3 ports at most. See portneeded in run-tests.py
|
|
|
|
port += 3
|
|
|
|
setattr(cls, method_name, gettestmethod(name, port))
|
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2018-06-15 07:21:16 +03:00
|
|
|
if __name__ == "__main__":
|
|
|
|
args, env = prepareargsenv(os.getcwd())
|
|
|
|
os.execvpe(args[0], args + sys.argv[1:], env)
|
|
|
|
else:
|
|
|
|
hgtests.collecttests(os.environ.get("HGTEST_DIR", "."))
|