diff options
Diffstat (limited to 'django/test/utils.py')
-rw-r--r-- | django/test/utils.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/django/test/utils.py b/django/test/utils.py index b6ab39901b..8ecb5a0e60 100644 --- a/django/test/utils.py +++ b/django/test/utils.py @@ -1,4 +1,6 @@ -import sys, time, os +import sys +import time +import os from django.conf import settings from django.core import mail from django.core.mail.backends import locmem @@ -6,6 +8,21 @@ from django.test import signals from django.template import Template from django.utils.translation import deactivate + +class Approximate(object): + def __init__(self, val, places=7): + self.val = val + self.places = places + + def __repr__(self): + return repr(self.val) + + def __eq__(self, other): + if self.val == other: + return True + return round(abs(self.val-other), self.places) == 0 + + class ContextList(list): """A wrapper that provides direct key access to context items contained in a list of context objects. @@ -19,6 +36,12 @@ class ContextList(list): else: return super(ContextList, self).__getitem__(key) + def __contains__(self, key): + try: + value = self[key] + except KeyError: + return False + return True def instrumented_test_render(self, context): """ |