From 601d191c37c7edcaca8a6176eae736982f750a89 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Thu, 22 May 2014 15:49:31 -0400 Subject: [PATCH] 2752: Move Python tests to dedicated subdirectory. This better follows Python convention, and will let us build out our test frameworks without cluttering the root source directories. This change brings a small change to the way we run tests. Pass the directory name to the discover command: $ python -m unittest discover tests --- .../arvados.org/keepclient/keepclient_test.go | 2 +- .../data}/1000G_ref_manifest | 0 .../{testdata => tests/data}/jlake_manifest | 0 sdk/python/{ => tests}/run_test_server.py | 42 ++++++++++++------- sdk/python/{ => tests}/test_collections.py | 11 ++++- sdk/python/{ => tests}/test_keep_client.py | 0 .../{ => tests}/test_pipeline_template.py | 0 sdk/python/{ => tests}/test_util.py | 0 sdk/python/{ => tests}/test_websockets.py | 0 services/fuse/run_test_server.py | 1 - services/fuse/tests/run_test_server.py | 1 + services/fuse/{ => tests}/test_mount.py | 0 .../arvados.org/keepproxy/keepproxy_test.go | 2 +- 13 files changed, 38 insertions(+), 21 deletions(-) rename sdk/python/{testdata => tests/data}/1000G_ref_manifest (100%) rename sdk/python/{testdata => tests/data}/jlake_manifest (100%) rename sdk/python/{ => tests}/run_test_server.py (91%) rename sdk/python/{ => tests}/test_collections.py (98%) rename sdk/python/{ => tests}/test_keep_client.py (100%) rename sdk/python/{ => tests}/test_pipeline_template.py (100%) rename sdk/python/{ => tests}/test_util.py (100%) rename sdk/python/{ => tests}/test_websockets.py (100%) delete mode 120000 services/fuse/run_test_server.py create mode 120000 services/fuse/tests/run_test_server.py rename services/fuse/{ => tests}/test_mount.py (100%) diff --git a/sdk/go/src/arvados.org/keepclient/keepclient_test.go b/sdk/go/src/arvados.org/keepclient/keepclient_test.go index 8eedadd64b..753a0ace28 100644 --- a/sdk/go/src/arvados.org/keepclient/keepclient_test.go +++ b/sdk/go/src/arvados.org/keepclient/keepclient_test.go @@ -36,7 +36,7 @@ type StandaloneSuite struct{} func pythonDir() string { gopath := os.Getenv("GOPATH") - return fmt.Sprintf("%s/../python", strings.Split(gopath, ":")[0]) + return fmt.Sprintf("%s/../python/tests", strings.Split(gopath, ":")[0]) } func (s *ServerRequiredSuite) SetUpSuite(c *C) { diff --git a/sdk/python/testdata/1000G_ref_manifest b/sdk/python/tests/data/1000G_ref_manifest similarity index 100% rename from sdk/python/testdata/1000G_ref_manifest rename to sdk/python/tests/data/1000G_ref_manifest diff --git a/sdk/python/testdata/jlake_manifest b/sdk/python/tests/data/jlake_manifest similarity index 100% rename from sdk/python/testdata/jlake_manifest rename to sdk/python/tests/data/jlake_manifest diff --git a/sdk/python/run_test_server.py b/sdk/python/tests/run_test_server.py similarity index 91% rename from sdk/python/run_test_server.py rename to sdk/python/tests/run_test_server.py index bdfdea9734..dc95d8a9a5 100644 --- a/sdk/python/run_test_server.py +++ b/sdk/python/tests/run_test_server.py @@ -1,17 +1,27 @@ -import subprocess -import time +#!/usr/bin/env python + +import argparse import os +import shutil import signal -import yaml +import subprocess import sys -import argparse -import arvados.config -import arvados.api -import shutil import tempfile +import time +import yaml + +MY_DIRNAME = os.path.dirname(os.path.realpath(__file__)) +if __name__ == '__main__' and os.path.exists( + os.path.join(MY_DIRNAME, '..', 'arvados', '__init__.py')): + # We're being launched to support another test suite. + # Add the Python SDK source to the library path. + sys.path.insert(1, os.path.dirname(MY_DIRNAME)) + +import arvados.api +import arvados.config -ARV_API_SERVER_DIR = '../../services/api' -KEEP_SERVER_DIR = '../../services/keep' +ARV_API_SERVER_DIR = '../../../services/api' +KEEP_SERVER_DIR = '../../../services/keep' SERVER_PID_PATH = 'tmp/pids/webrick-test.pid' WEBSOCKETS_SERVER_PID_PATH = 'tmp/pids/passenger-test.pid' @@ -54,7 +64,7 @@ def kill_server_pid(PID_PATH, wait=10): def run(websockets=False, reuse_server=False): cwd = os.getcwd() - os.chdir(os.path.join(os.path.dirname(__file__), ARV_API_SERVER_DIR)) + os.chdir(os.path.join(MY_DIRNAME, ARV_API_SERVER_DIR)) if websockets: pid_file = WEBSOCKETS_SERVER_PID_PATH @@ -106,7 +116,7 @@ def run(websockets=False, reuse_server=False): def stop(): cwd = os.getcwd() - os.chdir(os.path.join(os.path.dirname(__file__), ARV_API_SERVER_DIR)) + os.chdir(os.path.join(MY_DIRNAME, ARV_API_SERVER_DIR)) kill_server_pid(WEBSOCKETS_SERVER_PID_PATH, 0) kill_server_pid(SERVER_PID_PATH, 0) @@ -144,7 +154,7 @@ def run_keep(blob_signing_key=None, enforce_permissions=False): stop_keep() cwd = os.getcwd() - os.chdir(os.path.join(os.path.dirname(__file__), KEEP_SERVER_DIR)) + os.chdir(os.path.join(MY_DIRNAME, KEEP_SERVER_DIR)) if os.environ.get('GOPATH') == None: os.environ["GOPATH"] = os.getcwd() else: @@ -194,7 +204,7 @@ def _stop_keep(n): def stop_keep(): cwd = os.getcwd() - os.chdir(os.path.join(os.path.dirname(__file__), KEEP_SERVER_DIR)) + os.chdir(os.path.join(MY_DIRNAME, KEEP_SERVER_DIR)) _stop_keep(0) _stop_keep(1) @@ -205,7 +215,7 @@ def run_keep_proxy(auth): stop_keep_proxy() cwd = os.getcwd() - os.chdir(os.path.join(os.path.dirname(__file__), KEEP_SERVER_DIR)) + os.chdir(os.path.join(MY_DIRNAME, KEEP_SERVER_DIR)) if os.environ.get('GOPATH') == None: os.environ["GOPATH"] = os.getcwd() else: @@ -232,13 +242,13 @@ def run_keep_proxy(auth): def stop_keep_proxy(): cwd = os.getcwd() - os.chdir(os.path.join(os.path.dirname(__file__), KEEP_SERVER_DIR)) + os.chdir(os.path.join(MY_DIRNAME, KEEP_SERVER_DIR)) kill_server_pid("tmp/keepproxy.pid", 0) os.chdir(cwd) def fixture(fix): '''load a fixture yaml file''' - with open(os.path.join(os.path.dirname(__file__), ARV_API_SERVER_DIR, "test", "fixtures", + with open(os.path.join(MY_DIRNAME, ARV_API_SERVER_DIR, "test", "fixtures", fix + ".yml")) as f: return yaml.load(f.read()) diff --git a/sdk/python/test_collections.py b/sdk/python/tests/test_collections.py similarity index 98% rename from sdk/python/test_collections.py rename to sdk/python/tests/test_collections.py index d8cf8e93b1..f260b4ec93 100644 --- a/sdk/python/test_collections.py +++ b/sdk/python/tests/test_collections.py @@ -219,6 +219,13 @@ class ArvadosCollectionsTest(unittest.TestCase): n_lines_in, "decompression returned %d lines instead of %d" % (got, n_lines_in)) + def data_file(self, filename): + try: + basedir = os.path.dirname(__file__) + except NameError: + basedir = '.' + return open(os.path.join(basedir, 'data', filename)) + def test_normalized_collection(self): m1 = """. 5348b82a029fd9e971a811ce1f71360b+43 0:43:md5sum.txt . 085c37f02916da1cad16f93c54d899b7+41 0:41:md5sum.txt @@ -254,11 +261,11 @@ class ArvadosCollectionsTest(unittest.TestCase): ./zzz 204e43b8a1185621ca55a94839582e6f+67108864 0:999:zzz """) - with open('testdata/1000G_ref_manifest') as f6: + with self.data_file('1000G_ref_manifest') as f6: m6 = f6.read() self.assertEqual(arvados.CollectionReader(m6).manifest_text(), m6) - with open('testdata/jlake_manifest') as f7: + with self.data_file('jlake_manifest') as f7: m7 = f7.read() self.assertEqual(arvados.CollectionReader(m7).manifest_text(), m7) diff --git a/sdk/python/test_keep_client.py b/sdk/python/tests/test_keep_client.py similarity index 100% rename from sdk/python/test_keep_client.py rename to sdk/python/tests/test_keep_client.py diff --git a/sdk/python/test_pipeline_template.py b/sdk/python/tests/test_pipeline_template.py similarity index 100% rename from sdk/python/test_pipeline_template.py rename to sdk/python/tests/test_pipeline_template.py diff --git a/sdk/python/test_util.py b/sdk/python/tests/test_util.py similarity index 100% rename from sdk/python/test_util.py rename to sdk/python/tests/test_util.py diff --git a/sdk/python/test_websockets.py b/sdk/python/tests/test_websockets.py similarity index 100% rename from sdk/python/test_websockets.py rename to sdk/python/tests/test_websockets.py diff --git a/services/fuse/run_test_server.py b/services/fuse/run_test_server.py deleted file mode 120000 index 8d0a3b1c13..0000000000 --- a/services/fuse/run_test_server.py +++ /dev/null @@ -1 +0,0 @@ -../../sdk/python/run_test_server.py \ No newline at end of file diff --git a/services/fuse/tests/run_test_server.py b/services/fuse/tests/run_test_server.py new file mode 120000 index 0000000000..76bcc16222 --- /dev/null +++ b/services/fuse/tests/run_test_server.py @@ -0,0 +1 @@ +../../../sdk/python/tests/run_test_server.py \ No newline at end of file diff --git a/services/fuse/test_mount.py b/services/fuse/tests/test_mount.py similarity index 100% rename from services/fuse/test_mount.py rename to services/fuse/tests/test_mount.py diff --git a/services/keep/src/arvados.org/keepproxy/keepproxy_test.go b/services/keep/src/arvados.org/keepproxy/keepproxy_test.go index 9e78223596..47c33b4e1b 100644 --- a/services/keep/src/arvados.org/keepproxy/keepproxy_test.go +++ b/services/keep/src/arvados.org/keepproxy/keepproxy_test.go @@ -31,7 +31,7 @@ type ServerRequiredSuite struct{} func pythonDir() string { gopath := os.Getenv("GOPATH") - return fmt.Sprintf("%s/../../sdk/python", strings.Split(gopath, ":")[0]) + return fmt.Sprintf("%s/../../sdk/python/tests", strings.Split(gopath, ":")[0]) } func (s *ServerRequiredSuite) SetUpSuite(c *C) { -- 2.30.2