1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #14503 -- Unified multiple implementations of test cases assert* methods that verify a given exception is raised by a callable throughout the Django test suite.

Replaced them with a new assertRaisesMessage method of a new SimpleTestCase, a lightweight subclass of unittest.TestCase. Both are also available for usage in user tests.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16610 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Ramiro Morales
2011-08-13 00:42:08 +00:00
parent a539d434d9
commit 326949e444
13 changed files with 299 additions and 292 deletions

View File

@@ -4,22 +4,12 @@ Tests for stuff in django.utils.datastructures.
import copy
import pickle
import unittest
from django.test import SimpleTestCase
from django.utils.datastructures import *
class DatastructuresTestCase(unittest.TestCase):
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))
class SortedDictTests(DatastructuresTestCase):
class SortedDictTests(SimpleTestCase):
def setUp(self):
self.d1 = SortedDict()
self.d1[7] = 'seven'
@@ -125,7 +115,7 @@ class SortedDictTests(DatastructuresTestCase):
self.assertEqual(self.d1, {})
self.assertEqual(self.d1.keyOrder, [])
class MergeDictTests(DatastructuresTestCase):
class MergeDictTests(SimpleTestCase):
def test_simple_mergedict(self):
d1 = {'chris':'cool', 'camri':'cute', 'cotton':'adorable',
@@ -179,7 +169,7 @@ class MergeDictTests(DatastructuresTestCase):
('key2', ['value2', 'value3']),
('key4', ['value5', 'value6'])])
class MultiValueDictTests(DatastructuresTestCase):
class MultiValueDictTests(SimpleTestCase):
def test_multivaluedict(self):
d = MultiValueDict({'name': ['Adrian', 'Simon'],
@@ -198,7 +188,7 @@ class MultiValueDictTests(DatastructuresTestCase):
# MultiValueDictKeyError: "Key 'lastname' not found in
# <MultiValueDict: {'position': ['Developer'],
# 'name': ['Adrian', 'Simon']}>"
self.assertRaisesErrorWithMessage(MultiValueDictKeyError,
self.assertRaisesMessage(MultiValueDictKeyError,
'"Key \'lastname\' not found in <MultiValueDict: {\'position\':'\
' [\'Developer\'], \'name\': [\'Adrian\', \'Simon\']}>"',
d.__getitem__, 'lastname')
@@ -248,7 +238,7 @@ class MultiValueDictTests(DatastructuresTestCase):
self.assertEqual({}, MultiValueDict().dict())
class DotExpandedDictTests(DatastructuresTestCase):
class DotExpandedDictTests(SimpleTestCase):
def test_dotexpandeddict(self):
@@ -262,13 +252,13 @@ class DotExpandedDictTests(DatastructuresTestCase):
self.assertEqual(d['person']['2']['firstname'], ['Adrian'])
class ImmutableListTests(DatastructuresTestCase):
class ImmutableListTests(SimpleTestCase):
def test_sort(self):
d = ImmutableList(range(10))
# AttributeError: ImmutableList object is immutable.
self.assertRaisesErrorWithMessage(AttributeError,
self.assertRaisesMessage(AttributeError,
'ImmutableList object is immutable.', d.sort)
self.assertEqual(repr(d), '(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)')
@@ -279,11 +269,11 @@ class ImmutableListTests(DatastructuresTestCase):
self.assertEqual(d[1], 1)
# AttributeError: Object is immutable!
self.assertRaisesErrorWithMessage(AttributeError,
self.assertRaisesMessage(AttributeError,
'Object is immutable!', d.__setitem__, 1, 'test')
class DictWrapperTests(DatastructuresTestCase):
class DictWrapperTests(SimpleTestCase):
def test_dictwrapper(self):
f = lambda x: "*%s" % x