From 952ba5237ea62e7647cdd5214b1df79c0e7cea38 Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Fri, 1 Mar 2013 15:29:39 -0500 Subject: [PATCH] Added a context manager to capture queries while testing. Also made some import cleanups while I was there. Refs #10399. --- django/test/testcases.py | 35 +++++++------------- django/test/utils.py | 39 +++++++++++++++++++++++ tests/test_utils/tests.py | 67 +++++++++++++++++++++++++++++++++------ 3 files changed, 108 insertions(+), 33 deletions(-) diff --git a/django/test/testcases.py b/django/test/testcases.py index f9d028bb72..345e4b191b 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -24,31 +24,30 @@ from django.core.exceptions import ValidationError, ImproperlyConfigured from django.core.handlers.wsgi import WSGIHandler from django.core.management import call_command from django.core.management.color import no_style -from django.core.signals import request_started from django.core.servers.basehttp import (WSGIRequestHandler, WSGIServer, WSGIServerException) from django.core.urlresolvers import clear_url_caches from django.core.validators import EMPTY_VALUES -from django.db import (transaction, connection, connections, DEFAULT_DB_ALIAS, - reset_queries) +from django.db import connection, connections, DEFAULT_DB_ALIAS, transaction from django.forms.fields import CharField from django.http import QueryDict from django.test import _doctest as doctest from django.test.client import Client from django.test.html import HTMLParseError, parse_html from django.test.signals import template_rendered -from django.test.utils import (override_settings, compare_xml, strip_quotes) -from django.test.utils import ContextList -from django.utils import unittest as ut2 +from django.test.utils import (CaptureQueriesContext, ContextList, + override_settings, compare_xml, strip_quotes) +from django.utils import six, unittest as ut2 from django.utils.encoding import force_text -from django.utils import six +from django.utils.unittest import skipIf # Imported here for backward compatibility from django.utils.unittest.util import safe_repr -from django.utils.unittest import skipIf from django.views.static import serve + __all__ = ('DocTestRunner', 'OutputChecker', 'TestCase', 'TransactionTestCase', 'SimpleTestCase', 'skipIfDBFeature', 'skipUnlessDBFeature') + normalize_long_ints = lambda s: re.sub(r'(?

Hello

') self.assertEqual(len(element.children), 1) self.assertEqual(element.children[0].name, 'p') @@ -259,7 +315,6 @@ class HTMLEqualTests(TestCase): self.assertEqual(dom[0], 'foo') def test_parse_html_in_script(self): - from django.test.html import parse_html parse_html(''); parse_html('''