Revision aba462a2 snf-django-lib/snf_django/utils/testing.py
b/snf-django-lib/snf_django/utils/testing.py | ||
---|---|---|
186 | 186 |
|
187 | 187 |
def assertItemNotFound(self, response): |
188 | 188 |
self.assertFault(response, 404, 'itemNotFound') |
189 |
|
|
190 |
|
|
191 |
# Imitate unittest assertions new in Python 2.7 |
|
192 |
|
|
193 |
class _AssertRaisesContext(object): |
|
194 |
""" |
|
195 |
A context manager used to implement TestCase.assertRaises* methods. |
|
196 |
Adapted from unittest2. |
|
197 |
""" |
|
198 |
|
|
199 |
def __init__(self, expected): |
|
200 |
self.expected = expected |
|
201 |
|
|
202 |
def __enter__(self): |
|
203 |
return self |
|
204 |
|
|
205 |
def __exit__(self, exc_type, exc_value, tb): |
|
206 |
if exc_type is None: |
|
207 |
try: |
|
208 |
exc_name = self.expected.__name__ |
|
209 |
except AttributeError: |
|
210 |
exc_name = str(self.expected) |
|
211 |
raise AssertionError( |
|
212 |
"%s not raised" % (exc_name,)) |
|
213 |
if not issubclass(exc_type, self.expected): |
|
214 |
# let unexpected exceptions pass through |
|
215 |
return False |
|
216 |
self.exception = exc_value # store for later retrieval |
|
217 |
return True |
|
218 |
|
|
219 |
|
|
220 |
def assertRaises(excClass): |
|
221 |
return _AssertRaisesContext(excClass) |
|
222 |
|
|
223 |
|
|
224 |
def assertGreater(x, y): |
|
225 |
assert x > y |
|
226 |
|
|
227 |
|
|
228 |
def assertIn(x, y): |
|
229 |
assert x in y |
Also available in: Unified diff