From 02d931a53e567870bb1c53dd34ee5d070a49e194 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Sun, 27 Aug 2017 16:03:45 -0700 Subject: [PATCH] tools: Fix running full-stack tests from tools/ directory. Previously these tests required you to run them with the root of the Zulip repository as the current working directory, just due to sloppiness. We clean this up, while also making the path handling more consistent and involving less fragile code. Fixes #4169. --- frontend_tests/run-casper | 11 ++++++----- tools/test-api | 6 +++--- tools/test-help-documentation.py | 6 +++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/frontend_tests/run-casper b/frontend_tests/run-casper index a27125b492..1c2b8c1989 100755 --- a/frontend_tests/run-casper +++ b/frontend_tests/run-casper @@ -14,8 +14,10 @@ import glob # on how to use remote debugging # +ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + os.environ["CASPER_TESTS"] = "1" -os.environ["PHANTOMJS_EXECUTABLE"] = os.path.join(os.path.dirname(__file__), "../node_modules/.bin/phantomjs") +os.environ["PHANTOMJS_EXECUTABLE"] = os.path.join(ZULIP_PATH, "node_modules/.bin/phantomjs") os.environ["http_proxy"] = "" os.environ["https_proxy"] = "" @@ -39,8 +41,7 @@ parser.add_option('--remote-debug', default=False) (options, args) = parser.parse_args() -TOOLS_DIR = os.path.dirname(os.path.abspath(__file__)) -sys.path.insert(0, os.path.dirname(TOOLS_DIR)) +sys.path.insert(0, ZULIP_PATH) # check for the venv from tools.lib import sanity_check @@ -58,7 +59,7 @@ if not options.force: print('If you really know what you are doing, use --force to run anyway.') sys.exit(1) -os.chdir(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')) +os.chdir(ZULIP_PATH) subprocess.check_call('tools/setup/generate-test-credentials') @@ -70,7 +71,7 @@ LOG_FILE = 'var/casper/server.log' def run_tests(files, external_host): # type: (Iterable[str], str) -> None - test_dir = os.path.join(os.path.dirname(__file__), '../frontend_tests/casper_tests') + test_dir = os.path.join(ZULIP_PATH, 'frontend_tests/casper_tests') test_files = [] for file in files: for file_name in os.listdir(test_dir): diff --git a/tools/test-api b/tools/test-api index aa2aed4503..86a9103245 100755 --- a/tools/test-api +++ b/tools/test-api @@ -9,9 +9,9 @@ from lib import sanity_check sanity_check.check_venv(__file__) import django -TOOLS_DIR = os.path.dirname(__file__) -ROOT_DIR = os.path.dirname(TOOLS_DIR) -sys.path.insert(0, ROOT_DIR) +ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +sys.path.insert(0, ZULIP_PATH) +os.chdir(ZULIP_PATH) from zulip import Client diff --git a/tools/test-help-documentation.py b/tools/test-help-documentation.py index 56623ae8ab..70239601da 100755 --- a/tools/test-help-documentation.py +++ b/tools/test-help-documentation.py @@ -8,6 +8,7 @@ import subprocess import time +ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # check for the venv from lib import sanity_check @@ -21,9 +22,8 @@ parser.add_option('--force', default=False, help='Run tests despite possible problems.') (options, args) = parser.parse_args() -TOOLS_DIR = os.path.dirname(os.path.abspath(__file__)) -sys.path.insert(0, os.path.dirname(TOOLS_DIR)) - +os.chdir(ZULIP_PATH) +sys.path.insert(0, ZULIP_PATH) from tools.lib.test_server import test_server_running subprocess.check_call(['mkdir', '-p', 'var/help-documentation'])