Skip to content

Commit

Permalink
tools: Fix running full-stack tests from tools/ directory.
Browse files Browse the repository at this point in the history
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 zulip#4169.
  • Loading branch information
timabbott committed Sep 17, 2017
1 parent bd7d9da commit 02d931a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
11 changes: 6 additions & 5 deletions frontend_tests/run-casper
Original file line number Diff line number Diff line change
Expand Up @@ -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"] = ""

Expand All @@ -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
Expand All @@ -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')

Expand All @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions tools/test-api
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions tools/test-help-documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import time

ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# check for the venv
from lib import sanity_check
Expand All @@ -21,9 +22,8 @@
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'])
Expand Down

0 comments on commit 02d931a

Please sign in to comment.