From 36ac6f1fb97fc2c8285df1168ba9867ab02b994a Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Mon, 27 Sep 2010 15:16:46 +0000 Subject: [PATCH] Migrated urlpatterns_reverse doctests. Thanks to Stephan Jaekel. git-svn-id: http://code.djangoproject.com/svn/django/trunk@13893 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- .../urlpatterns_reverse/tests.py | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/tests/regressiontests/urlpatterns_reverse/tests.py b/tests/regressiontests/urlpatterns_reverse/tests.py index a0b98a88d3..477b0b7b3f 100644 --- a/tests/regressiontests/urlpatterns_reverse/tests.py +++ b/tests/regressiontests/urlpatterns_reverse/tests.py @@ -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 @@ test_data = ( ) +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 @@ class ResolverTests(unittest.TestCase): 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