diff --git a/test_elasticsearch/test_server/__init__.py b/test_elasticsearch/test_server/__init__.py index cf1b4ffc..0d8932b0 100644 --- a/test_elasticsearch/test_server/__init__.py +++ b/test_elasticsearch/test_server/__init__.py @@ -29,9 +29,21 @@ CMD = """ server = None pidfile = tempfile.mktemp() +from os import environ +from os.path import join, dirname, pardir, exists + +YAML_DIR = environ.get( + 'YAML_TEST_DIR', + join( + dirname(__file__), + pardir, pardir, pardir, + 'elasticsearch-rest-api-spec', 'test' + ) +) + def setup(): # no integration tests, skip starting the server - if 'YAML_TEST_DIR' not in os.environ: + if not exists(YAML_DIR): raise SkipTest('') global server diff --git a/test_elasticsearch/test_server/test_common.py b/test_elasticsearch/test_server/test_common.py index 474720b8..69cb90d5 100644 --- a/test_elasticsearch/test_server/test_common.py +++ b/test_elasticsearch/test_server/test_common.py @@ -4,12 +4,14 @@ some integration tests. These files are shared among all official Elasticsearch clients. """ from os import walk, environ -from os.path import join +from os.path import exists, join import yaml from unittest import TestCase, SkipTest from elasticsearch import Elasticsearch +from test_elasticsearch.test_server import YAML_DIR + # some params had to be changed in python, keep track of them so we can rename # those in the tests accordingly PARAMS_RENAMES = { @@ -189,16 +191,15 @@ def construct_case(filename, name): return type(name, (YamlTestCase, ), attrs) -yaml_dir = environ.get('YAML_TEST_DIR', None) -if yaml_dir: +if exists(YAML_DIR): # find all the test definitions in yaml files ... - for (path, dirs, files) in walk(yaml_dir): + for (path, dirs, files) in walk(YAML_DIR): for filename in files: if not filename.endswith('.yaml'): continue # ... parse them - name = ('Test' + ''.join(s.title() for s in path[len(yaml_dir) + 1:].split('/')) + filename.rsplit('.', 1)[0].title()).replace('_', '').replace('.', '') + name = ('Test' + ''.join(s.title() for s in path[len(YAML_DIR) + 1:].split('/')) + filename.rsplit('.', 1)[0].title()).replace('_', '').replace('.', '') # and insert them into locals for test runner to find them locals()[name] = construct_case(join(path, filename), name)