2014-02-13 13:44:49 +01:00
|
|
|
#!/usr/bin/env python
|
2015-11-09 13:04:50 +01:00
|
|
|
|
2016-10-27 08:48:39 +02:00
|
|
|
from __future__ import absolute_import, unicode_literals
|
|
|
|
|
|
|
|
import argparse
|
2014-02-17 12:03:41 +01:00
|
|
|
import os
|
|
|
|
import shutil
|
2016-10-27 08:48:39 +02:00
|
|
|
import sys
|
2014-07-23 15:48:42 +02:00
|
|
|
import warnings
|
2014-02-13 13:44:49 +01:00
|
|
|
|
|
|
|
from django.core.management import execute_from_command_line
|
|
|
|
|
2014-06-30 16:08:09 +02:00
|
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'wagtail.tests.settings'
|
2014-02-13 13:44:49 +01:00
|
|
|
|
|
|
|
|
2016-03-23 06:46:01 +01:00
|
|
|
def make_parser():
|
|
|
|
parser = argparse.ArgumentParser()
|
2016-10-27 08:48:39 +02:00
|
|
|
parser.add_argument('--deprecation', choices=['all', 'pending', 'imminent', 'none'], default='imminent')
|
2016-03-23 06:46:01 +01:00
|
|
|
parser.add_argument('--postgres', action='store_true')
|
|
|
|
parser.add_argument('--elasticsearch', action='store_true')
|
2016-05-06 12:23:31 +02:00
|
|
|
parser.add_argument('--elasticsearch2', action='store_true')
|
2016-11-08 10:21:24 +01:00
|
|
|
parser.add_argument('--elasticsearch5', action='store_true')
|
2016-03-23 06:46:01 +01:00
|
|
|
parser.add_argument('rest', nargs='*')
|
|
|
|
return parser
|
|
|
|
|
2014-07-23 15:48:42 +02:00
|
|
|
|
2016-03-23 06:46:01 +01:00
|
|
|
def parse_args(args=None):
|
|
|
|
return make_parser().parse_args(args)
|
2015-11-09 13:04:50 +01:00
|
|
|
|
2016-03-23 06:46:01 +01:00
|
|
|
|
|
|
|
def runtests():
|
|
|
|
args = parse_args()
|
|
|
|
|
|
|
|
only_wagtail = r'^wagtail(\.|$)'
|
|
|
|
if args.deprecation == 'all':
|
|
|
|
# Show all deprecation warnings from all packages
|
|
|
|
warnings.simplefilter('default', DeprecationWarning)
|
|
|
|
warnings.simplefilter('default', PendingDeprecationWarning)
|
|
|
|
elif args.deprecation == 'pending':
|
|
|
|
# Show all deprecation warnings from wagtail
|
|
|
|
warnings.filterwarnings('default', category=DeprecationWarning, module=only_wagtail)
|
|
|
|
warnings.filterwarnings('default', category=PendingDeprecationWarning, module=only_wagtail)
|
|
|
|
elif args.deprecation == 'imminent':
|
|
|
|
# Show only imminent deprecation warnings from wagtail
|
|
|
|
warnings.filterwarnings('default', category=DeprecationWarning, module=only_wagtail)
|
|
|
|
elif args.deprecation == 'none':
|
|
|
|
# Deprecation warnings are ignored by default
|
|
|
|
pass
|
|
|
|
|
|
|
|
if args.postgres:
|
2015-11-09 13:04:50 +01:00
|
|
|
os.environ['DATABASE_ENGINE'] = 'django.db.backends.postgresql_psycopg2'
|
|
|
|
|
2016-03-23 06:46:01 +01:00
|
|
|
if args.elasticsearch:
|
2015-11-09 13:13:07 +01:00
|
|
|
os.environ.setdefault('ELASTICSEARCH_URL', 'http://localhost:9200')
|
2016-05-06 12:23:31 +02:00
|
|
|
os.environ.setdefault('ELASTICSEARCH_VERSION', '1')
|
|
|
|
|
|
|
|
if args.elasticsearch2:
|
|
|
|
raise RuntimeError("You cannot test both Elasticsearch 1 and 2 together")
|
|
|
|
elif args.elasticsearch2:
|
|
|
|
os.environ.setdefault('ELASTICSEARCH_URL', 'http://localhost:9200')
|
|
|
|
os.environ.setdefault('ELASTICSEARCH_VERSION', '2')
|
2016-11-08 10:21:24 +01:00
|
|
|
elif args.elasticsearch5:
|
|
|
|
os.environ.setdefault('ELASTICSEARCH_URL', 'http://localhost:9200')
|
|
|
|
os.environ.setdefault('ELASTICSEARCH_VERSION', '5')
|
2016-05-03 18:19:29 +02:00
|
|
|
elif 'ELASTICSEARCH_URL' in os.environ:
|
|
|
|
# forcibly delete the ELASTICSEARCH_URL setting to skip those tests
|
|
|
|
del os.environ['ELASTICSEARCH_URL']
|
2015-11-09 13:13:07 +01:00
|
|
|
|
2016-03-23 06:46:01 +01:00
|
|
|
argv = [sys.argv[0], 'test'] + args.rest
|
2014-02-13 13:53:52 +01:00
|
|
|
try:
|
|
|
|
execute_from_command_line(argv)
|
|
|
|
finally:
|
2015-11-09 13:04:50 +01:00
|
|
|
from wagtail.tests.settings import STATIC_ROOT, MEDIA_ROOT
|
2014-02-13 13:53:52 +01:00
|
|
|
shutil.rmtree(STATIC_ROOT, ignore_errors=True)
|
2014-02-23 15:57:33 +01:00
|
|
|
shutil.rmtree(MEDIA_ROOT, ignore_errors=True)
|
2014-02-13 13:44:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
runtests()
|