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
|
|
|
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
|
|
|
|
|
2022-03-17 15:37:24 +01:00
|
|
|
os.environ["DJANGO_SETTINGS_MODULE"] = "wagtail.test.settings"
|
2014-02-13 13:44:49 +01:00
|
|
|
|
|
|
|
|
2016-03-23 06:46:01 +01:00
|
|
|
def make_parser():
|
|
|
|
parser = argparse.ArgumentParser()
|
2022-02-14 14:25:00 +01:00
|
|
|
parser.add_argument(
|
|
|
|
"--deprecation",
|
|
|
|
choices=["all", "pending", "imminent", "none"],
|
|
|
|
default="imminent",
|
|
|
|
)
|
|
|
|
parser.add_argument("--postgres", action="store_true")
|
|
|
|
parser.add_argument("--elasticsearch5", action="store_true")
|
|
|
|
parser.add_argument("--elasticsearch6", action="store_true")
|
|
|
|
parser.add_argument("--elasticsearch7", action="store_true")
|
|
|
|
parser.add_argument("--emailuser", action="store_true")
|
|
|
|
parser.add_argument("--disabletimezone", action="store_true")
|
|
|
|
parser.add_argument("--bench", action="store_true")
|
2016-03-23 06:46:01 +01:00
|
|
|
return parser
|
|
|
|
|
2014-07-23 15:48:42 +02:00
|
|
|
|
2016-03-23 06:46:01 +01:00
|
|
|
def parse_args(args=None):
|
2017-10-12 15:36:55 +02:00
|
|
|
return make_parser().parse_known_args(args)
|
2015-11-09 13:04:50 +01:00
|
|
|
|
2016-03-23 06:46:01 +01:00
|
|
|
|
|
|
|
def runtests():
|
2017-10-12 15:36:55 +02:00
|
|
|
args, rest = parse_args()
|
2016-03-23 06:46:01 +01:00
|
|
|
|
2022-02-14 14:25:00 +01:00
|
|
|
only_wagtail = r"^wagtail(\.|$)"
|
|
|
|
if args.deprecation == "all":
|
2016-03-23 06:46:01 +01:00
|
|
|
# Show all deprecation warnings from all packages
|
2022-02-14 14:25:00 +01:00
|
|
|
warnings.simplefilter("default", DeprecationWarning)
|
|
|
|
warnings.simplefilter("default", PendingDeprecationWarning)
|
|
|
|
elif args.deprecation == "pending":
|
2016-03-23 06:46:01 +01:00
|
|
|
# Show all deprecation warnings from wagtail
|
2022-02-14 14:25:00 +01:00
|
|
|
warnings.filterwarnings(
|
|
|
|
"default", category=DeprecationWarning, module=only_wagtail
|
|
|
|
)
|
|
|
|
warnings.filterwarnings(
|
|
|
|
"default", category=PendingDeprecationWarning, module=only_wagtail
|
|
|
|
)
|
|
|
|
elif args.deprecation == "imminent":
|
2016-03-23 06:46:01 +01:00
|
|
|
# Show only imminent deprecation warnings from wagtail
|
2022-02-14 14:25:00 +01:00
|
|
|
warnings.filterwarnings(
|
|
|
|
"default", category=DeprecationWarning, module=only_wagtail
|
|
|
|
)
|
|
|
|
elif args.deprecation == "none":
|
2016-03-23 06:46:01 +01:00
|
|
|
# Deprecation warnings are ignored by default
|
|
|
|
pass
|
|
|
|
|
|
|
|
if args.postgres:
|
2022-02-14 14:25:00 +01:00
|
|
|
os.environ["DATABASE_ENGINE"] = "django.db.backends.postgresql"
|
2015-11-09 13:04:50 +01:00
|
|
|
|
2020-11-04 23:24:59 +01:00
|
|
|
if args.elasticsearch5:
|
2022-02-14 14:25:00 +01:00
|
|
|
os.environ.setdefault("ELASTICSEARCH_URL", "http://localhost:9200")
|
|
|
|
os.environ.setdefault("ELASTICSEARCH_VERSION", "5")
|
2017-12-14 15:20:20 +01:00
|
|
|
elif args.elasticsearch6:
|
2022-02-14 14:25:00 +01:00
|
|
|
os.environ.setdefault("ELASTICSEARCH_URL", "http://localhost:9200")
|
|
|
|
os.environ.setdefault("ELASTICSEARCH_VERSION", "6")
|
2019-10-10 12:00:14 +02:00
|
|
|
elif args.elasticsearch7:
|
2022-02-14 14:25:00 +01:00
|
|
|
os.environ.setdefault("ELASTICSEARCH_URL", "http://localhost:9200")
|
|
|
|
os.environ.setdefault("ELASTICSEARCH_VERSION", "7")
|
2017-11-06 11:51:31 +01:00
|
|
|
|
2022-02-14 14:25:00 +01:00
|
|
|
elif "ELASTICSEARCH_URL" in os.environ:
|
2016-05-03 18:19:29 +02:00
|
|
|
# forcibly delete the ELASTICSEARCH_URL setting to skip those tests
|
2022-02-14 14:25:00 +01:00
|
|
|
del os.environ["ELASTICSEARCH_URL"]
|
2015-11-09 13:13:07 +01:00
|
|
|
|
2020-08-14 22:53:14 +02:00
|
|
|
if args.emailuser:
|
2022-02-14 14:25:00 +01:00
|
|
|
os.environ["USE_EMAIL_USER_MODEL"] = "1"
|
2020-08-14 00:28:33 +02:00
|
|
|
|
2020-08-24 17:54:45 +02:00
|
|
|
if args.disabletimezone:
|
2022-02-14 14:25:00 +01:00
|
|
|
os.environ["DISABLE_TIMEZONE"] = "1"
|
2020-08-24 17:54:45 +02:00
|
|
|
|
2017-02-09 16:06:50 +01:00
|
|
|
if args.bench:
|
|
|
|
benchmarks = [
|
2022-02-14 14:25:00 +01:00
|
|
|
"wagtail.admin.tests.benches",
|
2017-02-09 16:06:50 +01:00
|
|
|
]
|
|
|
|
|
2022-02-14 14:25:00 +01:00
|
|
|
argv = [sys.argv[0], "test", "-v2"] + benchmarks + rest
|
2017-02-09 16:06:50 +01:00
|
|
|
else:
|
2022-02-14 14:25:00 +01:00
|
|
|
argv = [sys.argv[0], "test"] + rest
|
2017-02-09 16:06:50 +01:00
|
|
|
|
2014-02-13 13:53:52 +01:00
|
|
|
try:
|
|
|
|
execute_from_command_line(argv)
|
|
|
|
finally:
|
2022-03-17 15:37:24 +01:00
|
|
|
from wagtail.test.settings import MEDIA_ROOT, STATIC_ROOT
|
2022-02-14 14:25:00 +01:00
|
|
|
|
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
|
|
|
|
|
|
|
|
2022-02-14 14:25:00 +01:00
|
|
|
if __name__ == "__main__":
|
2014-02-13 13:44:49 +01:00
|
|
|
runtests()
|