tools: Move registration of --force to test-scripts.py.

This commit moves --force option used with various tests to
test-scripts.py to have it alongside the logic that does provisioning
status assertion.
This is a step towards providing more clarity over use of this
argument with tests as asked in issue #17455.
This commit is contained in:
m-e-l-u-h-a-n 2021-03-03 09:30:15 +05:30 committed by Tim Abbott
parent b1a871f2e0
commit ca515e5583
10 changed files with 52 additions and 36 deletions

View File

@ -7,12 +7,13 @@ tools_dir = os.path.dirname(os.path.abspath(__file__))
root_dir = os.path.dirname(tools_dir) root_dir = os.path.dirname(tools_dir)
sys.path.insert(0, root_dir) sys.path.insert(0, root_dir)
from tools.lib.test_script import assert_provisioning_status_ok from tools.lib.test_script import add_provision_check_override_param, assert_provisioning_status_ok
def run() -> None: def run() -> None:
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("--force", action="store_true", help="Run tests despite possible problems.") add_provision_check_override_param(parser)
options = parser.parse_args() options = parser.parse_args()
assert_provisioning_status_ok(options.force) assert_provisioning_status_ok(options.force)

View File

@ -2,6 +2,7 @@ import glob
import os import os
import subprocess import subprocess
import sys import sys
from argparse import ArgumentParser
from distutils.version import LooseVersion from distutils.version import LooseVersion
from typing import Iterable, List, Optional, Tuple from typing import Iterable, List, Optional, Tuple
@ -88,6 +89,13 @@ def assert_provisioning_status_ok(force: bool) -> None:
sys.exit(1) sys.exit(1)
def add_provision_check_override_param(parser: ArgumentParser) -> None:
"""
Registers --force argument to be used with various commands/tests in our tools.
"""
parser.add_argument("--force", action="store_true", help="Run tests despite possible problems.")
def find_js_test_files(test_dir: str, files: Iterable[str]) -> List[str]: def find_js_test_files(test_dir: str, files: Iterable[str]) -> List[str]:
test_files = [] test_files = []
for file in files: for file in files:

View File

@ -16,21 +16,24 @@ from linter_lib.custom_check import non_py_rules, python_rules
def run() -> None: def run() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--force", action="store_true", help="Run tests despite possible problems.")
parser.add_argument("--full", action="store_true", help="Check some things we typically ignore")
add_default_linter_arguments(parser)
args = parser.parse_args()
tools_dir = os.path.dirname(os.path.abspath(__file__)) tools_dir = os.path.dirname(os.path.abspath(__file__))
root_dir = os.path.dirname(tools_dir) root_dir = os.path.dirname(tools_dir)
sys.path.insert(0, root_dir) sys.path.insert(0, root_dir)
from tools.lib.test_script import assert_provisioning_status_ok from tools.lib.test_script import (
add_provision_check_override_param,
assert_provisioning_status_ok,
)
from tools.linter_lib.exclude import EXCLUDED_FILES, PUPPET_CHECK_RULES_TO_EXCLUDE from tools.linter_lib.exclude import EXCLUDED_FILES, PUPPET_CHECK_RULES_TO_EXCLUDE
from tools.linter_lib.pep8 import check_pep8 from tools.linter_lib.pep8 import check_pep8
from tools.linter_lib.pyflakes import check_pyflakes from tools.linter_lib.pyflakes import check_pyflakes
parser = argparse.ArgumentParser()
add_provision_check_override_param(parser)
parser.add_argument("--full", action="store_true", help="Check some things we typically ignore")
add_default_linter_arguments(parser)
args = parser.parse_args()
os.chdir(root_dir) os.chdir(root_dir)
assert_provisioning_status_ok(args.force) assert_provisioning_status_ok(args.force)

View File

@ -19,7 +19,7 @@ from tornado.ioloop import IOLoop
TOOLS_DIR = os.path.dirname(os.path.abspath(__file__)) TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.dirname(TOOLS_DIR)) sys.path.insert(0, os.path.dirname(TOOLS_DIR))
from tools.lib.test_script import assert_provisioning_status_ok from tools.lib.test_script import add_provision_check_override_param, assert_provisioning_status_ok
if "posix" in os.name and os.geteuid() == 0: if "posix" in os.name and os.geteuid() == 0:
raise RuntimeError("run-dev.py should not be run as root.") raise RuntimeError("run-dev.py should not be run as root.")
@ -51,12 +51,12 @@ parser.add_argument(
help="Do not clear memcached on startup", help="Do not clear memcached on startup",
) )
parser.add_argument("--streamlined", action="store_true", help="Avoid thumbor, etc.") parser.add_argument("--streamlined", action="store_true", help="Avoid thumbor, etc.")
parser.add_argument("--force", action="store_true", help="Run command despite possible problems.")
parser.add_argument( parser.add_argument(
"--enable-tornado-logging", "--enable-tornado-logging",
action="store_true", action="store_true",
help="Enable access logs from tornado proxy server.", help="Enable access logs from tornado proxy server.",
) )
add_provision_check_override_param(parser)
options = parser.parse_args() options = parser.parse_args()
assert_provisioning_status_ok(options.force) assert_provisioning_status_ok(options.force)

View File

@ -11,7 +11,7 @@ TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
os.chdir(os.path.dirname(TOOLS_DIR)) os.chdir(os.path.dirname(TOOLS_DIR))
sys.path.append(os.path.dirname(TOOLS_DIR)) sys.path.append(os.path.dirname(TOOLS_DIR))
from lib.test_script import assert_provisioning_status_ok from tools.lib.test_script import add_provision_check_override_param, assert_provisioning_status_ok
exclude = """ exclude = """
stubs/ stubs/
@ -27,9 +27,7 @@ parser.add_argument(
parser.add_argument( parser.add_argument(
"-a", "--all", action="store_true", help="check all files, bypassing the default exclude list" "-a", "--all", action="store_true", help="check all files, bypassing the default exclude list"
) )
parser.add_argument( add_provision_check_override_param(parser)
"--force", action="store_true", help="run tests despite possible provisioning problems"
)
parser.add_argument("--quiet", action="store_true", help="suppress mypy summary output") parser.add_argument("--quiet", action="store_true", help="suppress mypy summary output")
args = parser.parse_args() args = parser.parse_args()

View File

@ -16,14 +16,12 @@ os.chdir(ZULIP_PATH)
from zulip import Client from zulip import Client
from tools.lib.test_script import assert_provisioning_status_ok from tools.lib.test_script import add_provision_check_override_param, assert_provisioning_status_ok
from tools.lib.test_server import test_server_running from tools.lib.test_server import test_server_running
usage = """test-api [options]""" usage = """test-api [options]"""
parser = argparse.ArgumentParser(usage) parser = argparse.ArgumentParser(usage)
parser.add_argument( add_provision_check_override_param(parser)
"--force", action="store_true", help="Run tests despite possible provisioning problems."
)
options = parser.parse_args() options = parser.parse_args()
assert_provisioning_status_ok(options.force) assert_provisioning_status_ok(options.force)

View File

@ -192,7 +192,10 @@ def main() -> None:
os.environ.pop("http_proxy", "") os.environ.pop("http_proxy", "")
os.environ.pop("https_proxy", "") os.environ.pop("https_proxy", "")
from tools.lib.test_script import assert_provisioning_status_ok from tools.lib.test_script import (
add_provision_check_override_param,
assert_provisioning_status_ok,
)
from zerver.lib.test_fixtures import ( from zerver.lib.test_fixtures import (
remove_test_run_directories, remove_test_run_directories,
update_test_databases_if_required, update_test_databases_if_required,
@ -239,7 +242,7 @@ def main() -> None:
"tests in. Default is the number of logical CPUs", "tests in. Default is the number of logical CPUs",
) )
parser.add_argument("--profile", action="store_true", help="Profile test runtime.") parser.add_argument("--profile", action="store_true", help="Profile test runtime.")
parser.add_argument("--force", action="store_true", help="Run tests despite possible problems.") add_provision_check_override_param(parser)
parser.add_argument( parser.add_argument(
"--no-shallow", "--no-shallow",
action="store_true", action="store_true",

View File

@ -13,8 +13,13 @@ from lib import sanity_check
sanity_check.check_venv(__file__) sanity_check.check_venv(__file__)
os.chdir(ZULIP_PATH)
sys.path.insert(0, ZULIP_PATH)
from tools.lib.test_script import add_provision_check_override_param
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("--force", action="store_true", help="Run tests despite possible problems.") add_provision_check_override_param(parser)
parser.add_argument( parser.add_argument(
"--skip-external-links", "--skip-external-links",
dest="skip_external_link_check", dest="skip_external_link_check",
@ -23,8 +28,6 @@ parser.add_argument(
) )
options = parser.parse_args() options = parser.parse_args()
os.chdir(ZULIP_PATH)
sys.path.insert(0, ZULIP_PATH)
from tools.lib.test_server import test_server_running from tools.lib.test_server import test_server_running
os.makedirs("var/help-documentation", exist_ok=True) os.makedirs("var/help-documentation", exist_ok=True)

View File

@ -167,15 +167,15 @@ EXEMPT_FILES = {
"static/js/zulip_test.js", "static/js/zulip_test.js",
} }
from tools.lib.test_script import add_provision_check_override_param, assert_provisioning_status_ok
parser = argparse.ArgumentParser(USAGE) parser = argparse.ArgumentParser(USAGE)
parser.add_argument("--coverage", action="store_true", help="Get coverage report") parser.add_argument("--coverage", action="store_true", help="Get coverage report")
parser.add_argument("--force", action="store_true", help="Run tests despite possible problems.") add_provision_check_override_param(parser)
parser.add_argument("args", nargs=argparse.REMAINDER) parser.add_argument("args", nargs=argparse.REMAINDER)
options = parser.parse_args() options = parser.parse_args()
individual_files = options.args individual_files = options.args
from tools.lib.test_script import assert_provisioning_status_ok
assert_provisioning_status_ok(options.force) assert_provisioning_status_ok(options.force)

View File

@ -25,15 +25,6 @@ usage = """test-js-with-puppeteer [options]
test-js-with-puppeteer 09 # Run a single test file 09-navigation.js test-js-with-puppeteer 09 # Run a single test file 09-navigation.js
test-js-with-puppeteer 01-login.js 03-narrow.js # Run a few test files test-js-with-puppeteer 01-login.js 03-narrow.js # Run a few test files
test-js-with-puppeteer 01 03 # Run a few test files, 01-login.js and 03-narrow.js here""" test-js-with-puppeteer 01 03 # Run a few test files, 01-login.js and 03-narrow.js here"""
parser = argparse.ArgumentParser(usage)
parser.add_argument("--interactive", action="store_true", help="Run tests interactively")
parser.add_argument("--force", action="store_true", help="Run tests despite possible problems.")
parser.add_argument(
"tests", nargs=argparse.REMAINDER, help="Specific tests to run; by default, runs all tests"
)
options = parser.parse_args()
sys.path.insert(0, ZULIP_PATH) sys.path.insert(0, ZULIP_PATH)
@ -45,12 +36,23 @@ sanity_check.check_venv(__file__)
from typing import Iterable, Tuple from typing import Iterable, Tuple
from tools.lib.test_script import ( from tools.lib.test_script import (
add_provision_check_override_param,
assert_provisioning_status_ok, assert_provisioning_status_ok,
find_js_test_files, find_js_test_files,
prepare_puppeteer_run, prepare_puppeteer_run,
) )
from tools.lib.test_server import test_server_running from tools.lib.test_server import test_server_running
parser = argparse.ArgumentParser(usage)
parser.add_argument("--interactive", action="store_true", help="Run tests interactively")
add_provision_check_override_param(parser)
parser.add_argument(
"tests", nargs=argparse.REMAINDER, help="Specific tests to run; by default, runs all tests"
)
options = parser.parse_args()
def run_tests(files: Iterable[str], external_host: str) -> None: def run_tests(files: Iterable[str], external_host: str) -> None:
test_dir = os.path.join(ZULIP_PATH, "frontend_tests/puppeteer_tests") test_dir = os.path.join(ZULIP_PATH, "frontend_tests/puppeteer_tests")