Skip to content

Commit 4522d02

Browse files
committed
added tests!
1 parent 37b06af commit 4522d02

File tree

6 files changed

+165
-0
lines changed

6 files changed

+165
-0
lines changed

.travis.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
sudo: false
2+
language: python
3+
cache: pip
4+
matrix:
5+
include:
6+
- env: PACKAGES="django>=1.4.0,<1.5.0"
7+
python: "2.7"
8+
- env: PACKAGES="django>=1.5.0,<1.6.0"
9+
python: "2.7"
10+
- env: PACKAGES="django>=1.6.0,<1.7.0"
11+
python: "2.7"
12+
- env: PACKAGES="django>=1.7.0,<1.8.0"
13+
python: "2.7"
14+
- env: PACKAGES="django>=1.8.0,<1.9.0"
15+
python: "3.5"
16+
- env: PACKAGES="django>=1.9.0,<1.10.0"
17+
python: "3.5"
18+
- env: PACKAGES="django>=1.10.0,<1.11.0"
19+
python: "3.5"
20+
- env: PACKAGES="django>=1.11.0,<1.12.0"
21+
python: "3.6"
22+
before_install:
23+
- pip install codecov
24+
install:
25+
- pip install -U pip wheel
26+
- travis_retry pip install $PACKAGES -e .
27+
script:
28+
- coverage run --source=fluent_utils runtests.py
29+
after_success:
30+
- codecov
31+
branches:
32+
only:
33+
- master
34+
notifications:
35+
email:
36+
recipients:
37+
- travis@edoburu.nl
38+
on_success: never
39+
on_failure: always
40+
slack:
41+
secure: V+skNUEC7EyI29t5H7zO+CmY9uRqbQHoRyj12VPN057ayQUaXAX/mh5pYqwyiTYdywfwo0/7ruPMZtyKHN+dE1MKvXu2F7QMb83Fk1pJ+lSeti+IV6XwlaZYnvTR3KoWublrHRl/VxbbBdYlGEU2zr612vO1nRvC6Zb6cFprscw=
42+
on_success: never
43+
on_failure: always

fluent_utils/tests/__init__.py

Whitespace-only changes.

fluent_utils/tests/import_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import non_existant # noqa
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.test import SimpleTestCase
2+
3+
4+
class DjangoCompatTests(SimpleTestCase):
5+
def test_import(self):
6+
import fluent_utils.django_compat # noqa

fluent_utils/tests/test_load.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from django.core.exceptions import ImproperlyConfigured
2+
from django.test import SimpleTestCase
3+
4+
from fluent_utils.load import import_module_or_none, import_class, import_settings_class, \
5+
import_apps_submodule
6+
7+
8+
class LoadTests(SimpleTestCase):
9+
10+
def test_import_apps_submodule(self):
11+
self.assertEqual(import_apps_submodule('admin'), ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sites'])
12+
13+
def test_import_settings_class(self):
14+
self.assertIsNotNone(import_settings_class('TEST_RUNNER'))
15+
16+
def test_import_class(self):
17+
self.assertIs(import_class('fluent_utils.tests.test_load.LoadTests'), LoadTests)
18+
self.assertRaises(ImproperlyConfigured, lambda: import_class('fluent_utils.tests.test_load.InvalidLoadTests'))
19+
20+
def test_ignore_top_level(self):
21+
self.assertIsNone(import_module_or_none("non_existant"))
22+
23+
def test_detect_sub_import_error(self):
24+
self.assertRaises(ImportError, lambda: import_module_or_none("fluent_utils.tests.import_test"))

runtests.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env python
2+
import sys
3+
import django
4+
from django.core.management import execute_from_command_line
5+
from django.conf import settings, global_settings as default_settings
6+
from os import path
7+
8+
# Give feedback on used versions
9+
sys.stderr.write('Using Python version {0} from {1}\n'.format(sys.version[:5], sys.executable))
10+
sys.stderr.write('Using Django version {0} from {1}\n'.format(
11+
django.get_version(),
12+
path.dirname(path.abspath(django.__file__)))
13+
)
14+
15+
if not settings.configured:
16+
module_root = path.dirname(path.realpath(__file__))
17+
18+
if django.VERSION >= (1, 8):
19+
template_settings = dict(
20+
TEMPLATES = [
21+
{
22+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
23+
'DIRS': (),
24+
'OPTIONS': {
25+
'loaders': (
26+
'django.template.loaders.filesystem.Loader',
27+
'django.template.loaders.app_directories.Loader',
28+
),
29+
'context_processors': (
30+
'django.template.context_processors.debug',
31+
'django.template.context_processors.i18n',
32+
'django.template.context_processors.media',
33+
'django.template.context_processors.request',
34+
'django.template.context_processors.static',
35+
'django.contrib.auth.context_processors.auth',
36+
),
37+
},
38+
},
39+
]
40+
)
41+
else:
42+
template_settings = dict(
43+
TEMPLATE_DEBUG = True,
44+
TEMPLATE_LOADERS = (
45+
'django.template.loaders.app_directories.Loader',
46+
'django.template.loaders.filesystem.Loader',
47+
),
48+
TEMPLATE_CONTEXT_PROCESSORS = list(default_settings.TEMPLATE_CONTEXT_PROCESSORS) + [
49+
'django.core.context_processors.request',
50+
],
51+
)
52+
53+
settings.configure(
54+
DEBUG = False, # will be False anyway by DjangoTestRunner.
55+
DATABASES = {
56+
'default': {
57+
'ENGINE': 'django.db.backends.sqlite3',
58+
'NAME': ':memory:'
59+
}
60+
},
61+
INSTALLED_APPS = (
62+
'django.contrib.auth',
63+
'django.contrib.contenttypes',
64+
'django.contrib.sites',
65+
'django.contrib.admin',
66+
'django.contrib.sessions',
67+
),
68+
MIDDLEWARE_CLASSES = (
69+
'django.middleware.common.CommonMiddleware',
70+
'django.contrib.sessions.middleware.SessionMiddleware',
71+
'django.middleware.csrf.CsrfViewMiddleware',
72+
'django.contrib.auth.middleware.AuthenticationMiddleware',
73+
),
74+
TEST_RUNNER = 'django.test.simple.DjangoTestSuiteRunner' if django.VERSION < (1,6) else 'django.test.runner.DiscoverRunner',
75+
**template_settings
76+
)
77+
78+
79+
DEFAULT_TEST_APPS = [
80+
'fluent_utils',
81+
]
82+
83+
84+
def runtests():
85+
other_args = list(filter(lambda arg: arg.startswith('-'), sys.argv[1:]))
86+
test_apps = list(filter(lambda arg: not arg.startswith('-'), sys.argv[1:])) or DEFAULT_TEST_APPS
87+
argv = sys.argv[:1] + ['test', '--traceback'] + other_args + test_apps
88+
execute_from_command_line(argv)
89+
90+
if __name__ == '__main__':
91+
runtests()

0 commit comments

Comments
 (0)