2014-02-13 12:44:49 +00:00
|
|
|
#!/usr/bin/env python
|
2015-11-09 12:04:50 +00:00
|
|
|
|
2016-10-27 06:48:39 +00:00
|
|
|
import argparse
|
2014-02-17 11:03:41 +00:00
|
|
|
import os
|
|
|
|
import shutil
|
2016-10-27 06:48:39 +00:00
|
|
|
import sys
|
2014-07-23 13:48:42 +00:00
|
|
|
import warnings
|
2014-02-13 12:44:49 +00:00
|
|
|
|
|
|
|
from django.core.management import execute_from_command_line
|
|
|
|
|
2014-06-30 14:08:09 +00:00
|
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'wagtail.tests.settings'
|
2014-02-13 12:44:49 +00:00
|
|
|
|
|
|
|
|
2016-03-23 05:46:01 +00:00
|
|
|
def make_parser():
|
|
|
|
parser = argparse.ArgumentParser()
|
2016-10-27 06:48:39 +00:00
|
|
|
parser.add_argument('--deprecation', choices=['all', 'pending', 'imminent', 'none'], default='imminent')
|
2016-03-23 05:46:01 +00:00
|
|
|
parser.add_argument('--postgres', action='store_true')
|
2016-05-06 10:23:31 +00:00
|
|
|
parser.add_argument('--elasticsearch2', action='store_true')
|
2016-11-08 09:21:24 +00:00
|
|
|
parser.add_argument('--elasticsearch5', action='store_true')
|
2017-12-14 14:20:20 +00:00
|
|
|
parser.add_argument('--elasticsearch6', action='store_true')
|
2019-10-10 10:00:14 +00:00
|
|
|
parser.add_argument('--elasticsearch7', action='store_true')
|
2017-02-09 15:06:50 +00:00
|
|
|
parser.add_argument('--bench', action='store_true')
|
2016-03-23 05:46:01 +00:00
|
|
|
return parser
|
|
|
|
|
2014-07-23 13:48:42 +00:00
|
|
|
|
2016-03-23 05:46:01 +00:00
|
|
|
def parse_args(args=None):
|
2017-10-12 13:36:55 +00:00
|
|
|
return make_parser().parse_known_args(args)
|
2015-11-09 12:04:50 +00:00
|
|
|
|
2016-03-23 05:46:01 +00:00
|
|
|
|
|
|
|
def runtests():
|
2017-10-12 13:36:55 +00:00
|
|
|
args, rest = parse_args()
|
2016-03-23 05:46:01 +00:00
|
|
|
|
|
|
|
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:
|
2017-10-18 20:10:49 +00:00
|
|
|
os.environ['DATABASE_ENGINE'] = 'django.db.backends.postgresql'
|
2015-11-09 12:04:50 +00:00
|
|
|
|
2017-11-06 10:51:31 +00:00
|
|
|
if args.elasticsearch2:
|
2016-05-06 10:23:31 +00:00
|
|
|
os.environ.setdefault('ELASTICSEARCH_URL', 'http://localhost:9200')
|
|
|
|
os.environ.setdefault('ELASTICSEARCH_VERSION', '2')
|
2016-11-08 09:21:24 +00:00
|
|
|
elif args.elasticsearch5:
|
|
|
|
os.environ.setdefault('ELASTICSEARCH_URL', 'http://localhost:9200')
|
|
|
|
os.environ.setdefault('ELASTICSEARCH_VERSION', '5')
|
2017-12-14 14:20:20 +00:00
|
|
|
elif args.elasticsearch6:
|
|
|
|
os.environ.setdefault('ELASTICSEARCH_URL', 'http://localhost:9200')
|
|
|
|
os.environ.setdefault('ELASTICSEARCH_VERSION', '6')
|
2019-10-10 10:00:14 +00:00
|
|
|
elif args.elasticsearch7:
|
|
|
|
os.environ.setdefault('ELASTICSEARCH_URL', 'http://localhost:9200')
|
|
|
|
os.environ.setdefault('ELASTICSEARCH_VERSION', '7')
|
2017-11-06 10:51:31 +00:00
|
|
|
|
2016-05-03 16:19:29 +00: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 12:13:07 +00:00
|
|
|
|
2017-02-09 15:06:50 +00:00
|
|
|
if args.bench:
|
|
|
|
benchmarks = [
|
|
|
|
'wagtail.admin.tests.benches',
|
|
|
|
]
|
|
|
|
|
|
|
|
argv = [sys.argv[0], 'test', '-v2'] + benchmarks + rest
|
|
|
|
else:
|
|
|
|
argv = [sys.argv[0], 'test'] + rest
|
|
|
|
|
2014-02-13 12:53:52 +00:00
|
|
|
try:
|
|
|
|
execute_from_command_line(argv)
|
|
|
|
finally:
|
2015-11-09 12:04:50 +00:00
|
|
|
from wagtail.tests.settings import STATIC_ROOT, MEDIA_ROOT
|
2014-02-13 12:53:52 +00:00
|
|
|
shutil.rmtree(STATIC_ROOT, ignore_errors=True)
|
2014-02-23 14:57:33 +00:00
|
|
|
shutil.rmtree(MEDIA_ROOT, ignore_errors=True)
|
2014-02-13 12:44:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
runtests()
|