Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Migrated urlpatterns_reverse doctests. Thanks to Stephan Jaekel.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13893 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 36ac6f1fb97fc2c8285df1168ba9867ab02b994a 1 parent 110c247
Russell Keith-Magee freakboy3742 authored
Showing with 22 additions and 14 deletions.
  1. +22 −14 tests/regressiontests/urlpatterns_reverse/tests.py
36 tests/regressiontests/urlpatterns_reverse/tests.py
View
@@ -1,19 +1,6 @@
"""
Unit tests for reverse URL lookups.
"""
-__test__ = {'API_TESTS': """
-
-RegexURLResolver should raise an exception when no urlpatterns exist.
-
->>> from django.core.urlresolvers import RegexURLResolver
->>> no_urls = 'regressiontests.urlpatterns_reverse.no_urls'
->>> resolver = RegexURLResolver(r'^$', no_urls)
->>> resolver.url_patterns
-Traceback (most recent call last):
-...
-ImproperlyConfigured: The included urlconf regressiontests.urlpatterns_reverse.no_urls doesn't have any patterns in it
-"""}
-
import unittest
from django.conf import settings
@@ -144,6 +131,27 @@
)
+class NoURLPatternsTests(TestCase):
+ urls = 'regressiontests.urlpatterns_reverse.no_urls'
+
+ def assertRaisesErrorWithMessage(self, error, message, callable,
+ *args, **kwargs):
+ self.assertRaises(error, callable, *args, **kwargs)
+ try:
+ callable(*args, **kwargs)
+ except error, e:
+ self.assertEqual(message, str(e))
+
+ def test_no_urls_exception(self):
+ """
+ RegexURLResolver should raise an exception when no urlpatterns exist.
+ """
+ resolver = RegexURLResolver(r'^$', self.urls)
+
+ self.assertRaisesErrorWithMessage(ImproperlyConfigured,
+ "The included urlconf regressiontests.urlpatterns_reverse.no_urls "\
+ "doesn't have any patterns in it", getattr, resolver, 'url_patterns')
+
class URLPatternReverse(TestCase):
urls = 'regressiontests.urlpatterns_reverse.urls'
@@ -174,7 +182,7 @@ def test_non_regex(self):
self.assertRaises(Resolver404, resolve, 'a')
self.assertRaises(Resolver404, resolve, '\\')
self.assertRaises(Resolver404, resolve, '.')
-
+
def test_404_tried_urls_have_names(self):
"""
Verifies that the list of URLs that come back from a Resolver404
Please sign in to comment.
Something went wrong with that request. Please try again.