2016-01-23 23:16:14 +01:00
|
|
|
#!/usr/bin/env python2.7
|
|
|
|
|
2016-03-10 17:15:34 +01:00
|
|
|
from __future__ import print_function
|
2016-01-23 23:16:14 +01:00
|
|
|
import optparse
|
|
|
|
import os
|
|
|
|
import sys
|
2016-03-12 05:58:35 +01:00
|
|
|
import subprocess
|
2016-01-23 23:16:14 +01:00
|
|
|
|
|
|
|
import django
|
|
|
|
from django.conf import settings
|
|
|
|
from django.test.utils import get_runner
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2016-03-12 05:58:35 +01:00
|
|
|
TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
sys.path.insert(0, os.path.dirname(TOOLS_DIR))
|
2016-01-23 23:16:14 +01:00
|
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.test_settings'
|
|
|
|
# "-u" uses unbuffered IO, which is important when wrapping it in subprocess
|
|
|
|
os.environ['PYTHONUNBUFFERED'] = 'y'
|
|
|
|
django.setup()
|
|
|
|
|
|
|
|
parser = optparse.OptionParser()
|
2016-01-23 23:18:26 +01:00
|
|
|
parser.add_option('--nonfatal-errors', action="store_false", default=True,
|
|
|
|
dest="fatal_errors", help="Continue past test failures to run all tests")
|
2016-01-23 23:16:14 +01:00
|
|
|
parser.add_option('--coverage', dest='coverage',
|
|
|
|
action="store_true",
|
|
|
|
default=False, help='Compute test coverage.')
|
2016-01-24 02:21:34 +01:00
|
|
|
parser.add_option('--profile', dest='profile',
|
|
|
|
action="store_true",
|
|
|
|
default=False, help='Profile test runtime.')
|
2016-01-23 23:16:14 +01:00
|
|
|
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
if len(args) == 0:
|
2016-04-12 07:16:09 +02:00
|
|
|
suites = ["zerver.tests"]
|
2016-01-23 23:16:14 +01:00
|
|
|
else:
|
|
|
|
suites = args
|
|
|
|
|
|
|
|
if options.coverage:
|
|
|
|
import coverage
|
2016-05-19 19:01:23 +02:00
|
|
|
cov = coverage.Coverage(omit="*/zulip-venv-cache/*")
|
2016-01-23 23:16:14 +01:00
|
|
|
cov.start()
|
2016-01-24 02:21:34 +01:00
|
|
|
if options.profile:
|
|
|
|
import cProfile
|
|
|
|
prof = cProfile.Profile()
|
|
|
|
prof.enable()
|
2016-01-23 23:16:14 +01:00
|
|
|
|
2016-05-26 12:40:41 +02:00
|
|
|
subprocess.call(os.path.join(TOOLS_DIR, 'setup', 'generate-fixtures'))
|
2016-03-12 05:58:35 +01:00
|
|
|
|
2016-01-23 23:16:14 +01:00
|
|
|
TestRunner = get_runner(settings)
|
|
|
|
test_runner = TestRunner()
|
2016-01-23 23:18:26 +01:00
|
|
|
failures = test_runner.run_tests(suites, fatal_errors=options.fatal_errors)
|
2016-01-23 23:16:14 +01:00
|
|
|
|
|
|
|
if options.coverage:
|
|
|
|
cov.stop()
|
|
|
|
cov.save()
|
|
|
|
print("Printing coverage data")
|
|
|
|
cov.report(show_missing=False)
|
|
|
|
cov.html_report()
|
|
|
|
print("HTML report saved to htmlcov/")
|
2016-01-24 02:21:34 +01:00
|
|
|
if options.profile:
|
|
|
|
prof.disable()
|
|
|
|
prof.dump_stats("/tmp/profile.data")
|
|
|
|
print("Profile data saved to /tmp/profile.data")
|
|
|
|
print("You can visualize it using e.g. `runsnake /tmp/profile.data`")
|
2016-01-23 23:16:14 +01:00
|
|
|
|
|
|
|
if failures:
|
|
|
|
print('FAILED!')
|
|
|
|
else:
|
|
|
|
print('DONE!')
|
|
|
|
sys.exit(bool(failures))
|