Files
opensearch-pyd/test_elasticsearch/run_tests.py
T

74 lines
2.2 KiB
Python
Raw Normal View History

2013-05-01 16:37:32 +02:00
#!/usr/bin/env python
2014-01-18 21:08:15 +01:00
from __future__ import print_function
2013-05-01 16:37:32 +02:00
import sys
2014-01-18 21:08:15 +01:00
from os import environ
from os.path import dirname, join, pardir, abspath, exists
import subprocess
2013-05-01 16:37:32 +02:00
import nose
2014-01-18 21:08:15 +01:00
def fetch_es_repo():
# user is manually setting YAML dir, don't tamper with it
if 'TEST_ES_YAML_DIR' in environ:
return
repo_path = environ.get(
'TEST_ES_REPO',
abspath(join(dirname(__file__), pardir, pardir, 'elasticsearch'))
)
# no repo
if not exists(repo_path) or not exists(join(repo_path, '.git')):
print('No elasticsearch repo found...')
# set YAML DIR to empty to skip yaml tests
environ['TEST_ES_YAML_DIR'] = ''
return
# set YAML test dir
2015-08-25 01:09:54 +02:00
environ['TEST_ES_YAML_DIR'] = join(repo_path, 'rest-api-spec', 'src', 'main', 'resources', 'rest-api-spec', 'test')
2014-01-18 21:08:15 +01:00
# fetching of yaml tests disabled, we'll run with what's there
if environ.get('TEST_ES_NOFETCH', False):
return
from test_elasticsearch.test_server import get_client
from test_elasticsearch.test_cases import SkipTest
2014-01-18 21:08:15 +01:00
# find out the sha of the running es
try:
es = get_client()
sha = es.info()['version']['build_hash']
except (SkipTest, KeyError):
print('No running elasticsearch >1.X server...')
return
# fetch new commits to be sure...
print('Fetching elasticsearch repo...')
subprocess.check_call('cd %s && git fetch https://github.com/elasticsearch/elasticsearch.git' % repo_path, shell=True)
# reset to the version fron info()
subprocess.check_call('cd %s && git reset --hard %s' % (repo_path, sha), shell=True)
2014-01-18 21:08:15 +01:00
2013-05-01 16:37:32 +02:00
def run_all(argv=None):
sys.exitfunc = lambda: sys.stderr.write('Shutting down....\n')
2014-01-18 21:08:15 +01:00
# fetch yaml tests
fetch_es_repo()
# always insert coverage when running tests
2013-05-01 16:37:32 +02:00
if argv is None:
argv = [
'nosetests', '--with-xunit',
'--with-xcoverage', '--cover-package=elasticsearch', '--cover-erase',
2013-11-19 04:10:34 +01:00
'--logging-filter=elasticsearch', '--logging-level=DEBUG',
'--verbose', '--with-id',
2013-05-01 16:37:32 +02:00
]
nose.run_exit(
argv=argv,
2014-01-18 21:08:15 +01:00
defaultTest=abspath(dirname(__file__))
2013-05-01 16:37:32 +02:00
)
if __name__ == '__main__':
run_all(sys.argv)