Skip to content
Browse files

support running tests with python setup.py test

  • Loading branch information...
1 parent b9ae475 commit 45c6f6e0a7b2404e793f1ee72447d0c4a1153a03 @graingert committed
View
1 .gitignore
@@ -1,2 +1,3 @@
*.pyc
*.pyo
+test.db
View
25 runtests.py
@@ -0,0 +1,25 @@
+# This file mainly exists to allow python setup.py test to work.
+# http://ericholscher.com/blog/2009/jun/29/enable-setuppy-test-your-django-apps/
+import os
+import sys
+
+os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
+os.environ['REUSE_DB'] = '0'
+
+test_dir = os.path.join(os.path.dirname(__file__), 'templatetag_sugar/tests')
+sys.path.insert(0, test_dir)
+
+from django.test.utils import get_runner
+from django.conf import settings
+from django.core.management import call_command
+
+
+def runtests():
+ call_command('syncdb', interactive=False)
+ call_command('flush', interactive=False)
+ test_runner = get_runner(settings)
+ failures = test_runner(interactive=False, failfast=False).run_tests([])
+ sys.exit(failures)
+
+if __name__ == '__main__':
+ runtests()
View
4 setup.py
@@ -1,5 +1,4 @@
-from distutils.core import setup
-
+from setuptools import setup
setup(
name = "django-templatetag-sugar",
@@ -13,6 +12,7 @@
packages = [
"templatetag_sugar",
],
+ test_suite="runtests.runtests",
classifiers = [
"Development Status :: 3 - Alpha",
"Environment :: Web Environment",
View
13 templatetag_sugar/tests/settings.py
@@ -1,6 +1,19 @@
DATABASE_ENGINE = 'sqlite3'
INSTALLED_APPS = [
+ "django_nose",
"templatetag_sugar",
"templatetag_sugar.tests",
]
+
+SECRET_KEY="asdf"
+
+DATABASES = {
+ 'default': {
+ 'NAME': 'test.db',
+ 'ENGINE': 'django.db.backends.sqlite3',
+ }
+}
+
+TEST_RUNNER = 'django_nose.runner.NoseTestSuiteRunner'
+
View
0 ...tag_sugar/tests/templatetags/test_tags.py → ...tag_sugar/tests/templatetags/demo_tags.py
File renamed without changes.
View
44 templatetag_sugar/tests/tests.py
@@ -8,7 +8,7 @@ class SugarTestCase(TestCase):
def assert_renders(self, tmpl, context, value):
tmpl = Template(tmpl)
self.assertEqual(tmpl.render(context), value)
-
+
def assert_syntax_error(self, tmpl, error):
try:
Template(tmpl)
@@ -19,76 +19,74 @@ def assert_syntax_error(self, tmpl, error):
)
else:
self.fail("Didn't raise")
-
-
+
def test_basic(self):
self.assert_renders(
- """{% load test_tags %}{% test_tag_1 for "alex" %}""",
+ """{% load demo_tags %}{% test_tag_1 for "alex" %}""",
Context(),
"alex"
)
-
+
c = Context()
self.assert_renders(
- """{% load test_tags %}{% test_tag_1 for "brian" as name %}""",
+ """{% load demo_tags %}{% test_tag_1 for "brian" as name %}""",
c,
""
)
self.assertEqual(c["name"], "brian")
-
-
+
self.assert_renders(
- """{% load test_tags %}{% test_tag_1 for variable %}""",
+ """{% load demo_tags %}{% test_tag_1 for variable %}""",
Context({"variable": [1, 2, 3]}),
"[1, 2, 3]",
)
-
+
def test_model(self):
Book.objects.create(title="Pro Django")
self.assert_renders(
- """{% load test_tags %}{% test_tag_2 tests.Book 2 %}""",
+ """{% load demo_tags %}{% test_tag_2 tests.Book 2 %}""",
Context(),
"[<Book: Pro Django>]"
)
-
+
def test_errors(self):
self.assert_syntax_error(
- """{% load test_tags %}{% test_tag_1 for "jesse" as %}""",
+ """{% load demo_tags %}{% test_tag_1 for "jesse" as %}""",
"test_tag_1 has the following syntax: {% test_tag_1 for <arg> [as <arg>] %}"
)
-
+
self.assert_syntax_error(
- """{% load test_tags %}{% test_tag_4 width %}""",
+ """{% load demo_tags %}{% test_tag_4 width %}""",
"test_tag_4 has the following syntax: {% test_tag_4 [width <width>] [height <height>] %}"
)
def test_variable_as_string(self):
self.assert_renders(
- """{% load test_tags %}{% test_tag_3 "xela alex" %}""",
+ """{% load demo_tags %}{% test_tag_3 "xela alex" %}""",
Context(),
"xela alex",
)
def test_optional(self):
self.assert_renders(
- """{% load test_tags %}{% test_tag_4 width 100 height 200 %}""",
+ """{% load demo_tags %}{% test_tag_4 width 100 height 200 %}""",
Context(),
"100, 200",
)
-
+
self.assert_renders(
- """{% load test_tags %}{% test_tag_4 width 100 %}""",
+ """{% load demo_tags %}{% test_tag_4 width 100 %}""",
Context(),
"100, None"
)
-
+
self.assert_renders(
- """{% load test_tags %}{% test_tag_4 height 100 %}""",
+ """{% load demo_tags %}{% test_tag_4 height 100 %}""",
Context(),
"None, 100",
)
-
+
self.assert_syntax_error(
- """{% load test_tags %}{% test_tag_1 %}""",
+ """{% load demo_tags %}{% test_tag_1 %}""",
"test_tag_1 has the following syntax: {% test_tag_1 for <arg> [as <arg>] %}"
)

0 comments on commit 45c6f6e

Please sign in to comment.
Something went wrong with that request. Please try again.