2012-11-10 10:39:07 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
import os
|
|
|
|
|
import sys
|
2017-06-22 18:56:14 +00:00
|
|
|
import warnings
|
2018-01-31 11:02:00 +00:00
|
|
|
from optparse import OptionParser
|
2012-11-10 10:39:07 +00:00
|
|
|
|
2014-04-15 12:31:15 +00:00
|
|
|
import django
|
2012-11-10 17:47:03 +00:00
|
|
|
from django.conf import settings
|
2012-11-10 10:39:07 +00:00
|
|
|
from django.core.management import call_command
|
|
|
|
|
|
2013-04-02 21:27:43 +00:00
|
|
|
|
2018-01-31 11:02:00 +00:00
|
|
|
def runtests(test_path='modeltranslation'):
|
2012-11-10 17:47:03 +00:00
|
|
|
if not settings.configured:
|
|
|
|
|
# Choose database for settings
|
|
|
|
|
DATABASES = {
|
|
|
|
|
'default': {
|
|
|
|
|
'ENGINE': 'django.db.backends.sqlite3',
|
|
|
|
|
'NAME': ':memory:'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
test_db = os.environ.get('DB', 'sqlite')
|
|
|
|
|
if test_db == 'mysql':
|
|
|
|
|
DATABASES['default'].update({
|
|
|
|
|
'ENGINE': 'django.db.backends.mysql',
|
|
|
|
|
'NAME': 'modeltranslation',
|
|
|
|
|
'USER': 'root',
|
|
|
|
|
})
|
|
|
|
|
elif test_db == 'postgres':
|
|
|
|
|
DATABASES['default'].update({
|
|
|
|
|
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
|
|
|
|
'USER': 'postgres',
|
|
|
|
|
'NAME': 'modeltranslation',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
# Configure test environment
|
|
|
|
|
settings.configure(
|
2014-04-15 12:31:15 +00:00
|
|
|
DATABASES=DATABASES,
|
|
|
|
|
INSTALLED_APPS=(
|
2015-04-02 20:54:15 +00:00
|
|
|
'django.contrib.contenttypes',
|
2015-12-13 14:47:01 +00:00
|
|
|
'django.contrib.auth',
|
2012-11-10 17:47:03 +00:00
|
|
|
'modeltranslation',
|
|
|
|
|
),
|
2014-04-15 12:31:15 +00:00
|
|
|
ROOT_URLCONF=None, # tests override urlconf, but it still needs to be defined
|
|
|
|
|
LANGUAGES=(
|
2013-04-02 21:27:43 +00:00
|
|
|
('en', 'English'),
|
|
|
|
|
),
|
2014-09-07 19:43:58 +00:00
|
|
|
MIDDLEWARE_CLASSES=(),
|
2012-11-10 17:47:03 +00:00
|
|
|
)
|
|
|
|
|
|
2017-06-23 04:37:22 +00:00
|
|
|
django.setup()
|
2017-06-22 18:56:14 +00:00
|
|
|
warnings.simplefilter('always', DeprecationWarning)
|
2012-11-10 10:39:07 +00:00
|
|
|
failures = call_command(
|
2018-01-31 11:02:00 +00:00
|
|
|
'test', test_path, interactive=False, failfast=False, verbosity=2)
|
2014-04-15 12:31:15 +00:00
|
|
|
|
2012-11-10 10:39:07 +00:00
|
|
|
sys.exit(bool(failures))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2018-01-31 11:02:00 +00:00
|
|
|
parser = OptionParser()
|
|
|
|
|
|
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
runtests(*args)
|