Permalink
Browse files

Fixed #12991 -- Added unittest2 support. Thanks to PaulM for the draf…

…t patch, and to Luke, Karen, Justin, Alex, Łukasz Rekucki, and Chuck Harmston for their help testing and reviewing the final patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14139 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 1070c57 commit 121d2e36785dc0ce8e7d1c48883fc7b719b21afc @freakboy3742 freakboy3742 committed Oct 11, 2010
Showing with 3,875 additions and 1,054 deletions.
  1. +3 −2 django/contrib/admindocs/tests/__init__.py
  2. +3 −3 django/contrib/formtools/tests.py
  3. +2 −2 django/contrib/gis/db/backends/spatialite/creation.py
  4. +1 −1 django/contrib/gis/gdal/tests/__init__.py
  5. +42 −41 django/contrib/gis/gdal/tests/test_envelope.py
  6. +2 −1 django/contrib/gis/gdal/tests/test_geom.py
  7. +4 −3 django/contrib/gis/gdal/tests/test_srs.py
  8. +1 −1 django/contrib/gis/geos/tests/__init__.py
  9. +1 −1 django/contrib/gis/geos/tests/test_geos_mutation.py
  10. +2 −1 django/contrib/gis/geos/tests/test_mutable_list.py
  11. +2 −1 django/contrib/gis/tests/__init__.py
  12. +3 −1 django/contrib/gis/tests/geoapp/test_feeds.py
  13. +9 −5 django/contrib/gis/tests/geoapp/test_sitemaps.py
  14. +17 −17 django/contrib/gis/tests/layermap/tests.py
  15. +2 −2 django/contrib/gis/tests/test_geoforms.py
  16. +27 −26 django/contrib/gis/tests/test_measure.py
  17. +4 −4 django/contrib/gis/tests/test_spatialrefsys.py
  18. +61 −48 django/contrib/markup/tests.py
  19. +1 −1 django/contrib/messages/tests/middleware.py
  20. +4 −3 django/contrib/sessions/tests.py
  21. +90 −0 django/db/backends/__init__.py
  22. +3 −14 django/db/backends/creation.py
  23. +1 −1 django/db/backends/dummy/base.py
  24. +10 −2 django/db/backends/mysql/base.py
  25. +5 −3 django/db/backends/oracle/base.py
  26. +4 −1 django/db/backends/postgresql/base.py
  27. +4 −1 django/db/backends/postgresql_psycopg2/base.py
  28. +23 −2 django/db/backends/sqlite3/base.py
  29. +1 −1 django/test/__init__.py
  30. +11 −48 django/test/simple.py
  31. +28 −4 django/test/testcases.py
  32. +80 −0 django/utils/unittest/__init__.py
  33. +10 −0 django/utils/unittest/__main__.py
  34. +1,083 −0 django/utils/unittest/case.py
  35. +9 −0 django/utils/unittest/collector.py
  36. +64 −0 django/utils/unittest/compatibility.py
  37. +322 −0 django/utils/unittest/loader.py
  38. +241 −0 django/utils/unittest/main.py
  39. +183 −0 django/utils/unittest/result.py
  40. +206 −0 django/utils/unittest/runner.py
  41. +57 −0 django/utils/unittest/signals.py
  42. +287 −0 django/utils/unittest/suite.py
  43. +99 −0 django/utils/unittest/util.py
  44. +28 −0 docs/releases/1.3.txt
  45. +51 −19 docs/topics/testing.txt
  46. +3 −6 tests/modeltests/basic/models.py
  47. +10 −11 tests/modeltests/custom_pk/tests.py
  48. +45 −44 tests/modeltests/fixtures/tests.py
  49. +9 −8 tests/modeltests/lookup/models.py
  50. +1 −1 tests/modeltests/test_client/tests.py
  51. +152 −148 tests/modeltests/transactions/tests.py
  52. +1 −1 tests/modeltests/validation/__init__.py
  53. +3 −1 tests/modeltests/validation/test_unique.py
  54. +2 −1 tests/modeltests/validation/validators.py
  55. +3 −1 tests/modeltests/validators/tests.py
  56. +1 −1 tests/regressiontests/admin_scripts/tests.py
  57. +5 −6 tests/regressiontests/admin_util/tests.py
  58. +34 −32 tests/regressiontests/admin_views/tests.py
  59. +3 −2 tests/regressiontests/admin_widgets/tests.py
  60. +83 −102 tests/regressiontests/aggregation_regress/tests.py
  61. +1 −1 tests/regressiontests/app_loading/tests.py
  62. +1 −1 tests/regressiontests/backends/models.py
  63. +83 −83 tests/regressiontests/backends/tests.py
  64. +1 −1 tests/regressiontests/bash_completion/tests.py
  65. +2 −1 tests/regressiontests/bug639/tests.py
  66. +1 −2 tests/regressiontests/bug8245/tests.py
  67. +2 −1 tests/regressiontests/builtin_server/tests.py
  68. +2 −1 tests/regressiontests/cache/tests.py
  69. +9 −8 tests/regressiontests/datatypes/tests.py
  70. +10 −9 tests/regressiontests/decorators/tests.py
  71. +54 −53 tests/regressiontests/delete_regress/tests.py
  72. +9 −8 tests/regressiontests/dispatch/tests/test_dispatcher.py
  73. +1 −1 tests/regressiontests/dispatch/tests/test_saferef.py
  74. +14 −14 tests/regressiontests/expressions_regress/tests.py
  75. +69 −66 tests/regressiontests/file_storage/tests.py
  76. +4 −4 tests/regressiontests/file_uploads/tests.py
  77. +2 −2 tests/regressiontests/fixtures_regress/models.py
  78. +1 −2 tests/regressiontests/forms/fields.py
  79. +1 −1 tests/regressiontests/forms/input_formats.py
  80. +1 −2 tests/regressiontests/forms/validators.py
  81. +2 −3 tests/regressiontests/forms/widgets.py
  82. +25 −24 tests/regressiontests/httpwrappers/tests.py
  83. +2 −1 tests/regressiontests/humanize/tests.py
  84. +8 −8 tests/regressiontests/introspection/tests.py
  85. +1 −1 tests/regressiontests/localflavor/tests.py
  86. +5 −5 tests/regressiontests/max_lengths/tests.py
  87. +11 −11 tests/regressiontests/model_fields/tests.py
  88. +2 −4 tests/regressiontests/model_regress/models.py
  89. +1 −2 tests/regressiontests/pagination_regress/tests.py
  90. +4 −4 tests/regressiontests/queries/models.py
  91. +1 −2 tests/regressiontests/queries/tests.py
  92. +3 −3 tests/regressiontests/serializers_regress/tests.py
  93. +1 −1 tests/regressiontests/settings_tests/tests.py
  94. +3 −3 tests/regressiontests/templates/loaders.py
  95. +1 −1 tests/regressiontests/templates/nodelist.py
  96. +1 −1 tests/regressiontests/templates/smartif.py
  97. +30 −30 tests/regressiontests/templates/tests.py
  98. +48 −48 tests/regressiontests/test_client_regress/models.py
  99. +2 −2 tests/regressiontests/test_runner/tests.py
  100. +1 −2 tests/regressiontests/urlpatterns_reverse/tests.py
  101. +2 −2 tests/regressiontests/utils/dateformat.py
  102. +1 −2 tests/regressiontests/utils/feedgenerator.py
  103. +1 −2 tests/regressiontests/utils/functional.py
  104. +2 −1 tests/regressiontests/utils/module_loading.py
  105. +1 −2 tests/regressiontests/utils/termcolors.py
  106. +2 −3 tests/runtests.py
@@ -1,7 +1,8 @@
-import unittest
-import fields
from django.contrib.admindocs import views
from django.db.models import fields as builtin_fields
+from django.utils import unittest
+
+import fields
class TestFieldType(unittest.TestCase):
@@ -1,8 +1,8 @@
-import unittest
from django import forms
-from django.contrib.formtools import preview, wizard, utils
from django import http
+from django.contrib.formtools import preview, wizard, utils
from django.test import TestCase
+from django.utils import unittest
success_string = "Done was called!"
@@ -115,7 +115,7 @@ def test_textfield_hash(self):
hash1 = utils.security_hash(None, f1)
hash2 = utils.security_hash(None, f2)
self.assertEqual(hash1, hash2)
-
+
def test_empty_permitted(self):
"""
Regression test for #10643: the security hash should allow forms with
@@ -22,8 +22,8 @@ def create_test_db(self, verbosity=1, autoclobber=False):
self.connection.close()
self.connection.settings_dict["NAME"] = test_database_name
- can_rollback = self._rollback_works()
- self.connection.settings_dict["SUPPORTS_TRANSACTIONS"] = can_rollback
+ # Confirm the feature set of the test database
+ self.connection.features.confirm()
# Need to load the SpatiaLite initialization SQL before running `syncdb`.
self.load_spatialite_sql()
call_command('syncdb', verbosity=verbosity, interactive=False, database=self.connection.alias)
@@ -2,7 +2,7 @@
Module for executing all of the GDAL tests. None
of these tests require the use of the database.
"""
-from unittest import TestSuite, TextTestRunner
+from django.utils.unittest import TestSuite, TextTestRunner
# Importing the GDAL test modules.
import test_driver, test_ds, test_envelope, test_geom, test_srs
@@ -1,5 +1,6 @@
-import unittest
from django.contrib.gis.gdal import Envelope, OGRException
+from django.utils import unittest
+
class TestPoint(object):
def __init__(self, x, y):
@@ -8,8 +9,8 @@ def __init__(self, x, y):
class EnvelopeTest(unittest.TestCase):
- def setUp(self):
- self.e = Envelope(0, 0, 5, 5)
+ def setUp(self):
+ self.e = Envelope(0, 0, 5, 5)
def test01_init(self):
"Testing Envelope initilization."
@@ -23,10 +24,10 @@ def test01_init(self):
self.assertRaises(OGRException, Envelope, ())
self.assertRaises(ValueError, Envelope, 0, 'a', 5, 5)
self.assertRaises(TypeError, Envelope, u'foo')
- self.assertRaises(OGRException, Envelope, (1, 1, 0, 0))
- try:
- Envelope(0, 0, 0, 0)
- except OGRException:
+ self.assertRaises(OGRException, Envelope, (1, 1, 0, 0))
+ try:
+ Envelope(0, 0, 0, 0)
+ except OGRException:
self.fail("shouldn't raise an exception for min_x == max_x or min_y == max_y")
def test02_properties(self):
@@ -49,41 +50,41 @@ def test03_equivalence(self):
self.assertEqual(e1, e2)
self.assertEqual((0.523, 0.217, 253.23, 523.69), e1)
- def test04_expand_to_include_pt_2_params(self):
- "Testing Envelope expand_to_include -- point as two parameters."
- self.e.expand_to_include(2, 6)
- self.assertEqual((0, 0, 5, 6), self.e)
- self.e.expand_to_include(-1, -1)
- self.assertEqual((-1, -1, 5, 6), self.e)
-
- def test05_expand_to_include_pt_2_tuple(self):
- "Testing Envelope expand_to_include -- point as a single 2-tuple parameter."
- self.e.expand_to_include((10, 10))
- self.assertEqual((0, 0, 10, 10), self.e)
- self.e.expand_to_include((-10, -10))
- self.assertEqual((-10, -10, 10, 10), self.e)
+ def test04_expand_to_include_pt_2_params(self):
+ "Testing Envelope expand_to_include -- point as two parameters."
+ self.e.expand_to_include(2, 6)
+ self.assertEqual((0, 0, 5, 6), self.e)
+ self.e.expand_to_include(-1, -1)
+ self.assertEqual((-1, -1, 5, 6), self.e)
+
+ def test05_expand_to_include_pt_2_tuple(self):
+ "Testing Envelope expand_to_include -- point as a single 2-tuple parameter."
+ self.e.expand_to_include((10, 10))
+ self.assertEqual((0, 0, 10, 10), self.e)
+ self.e.expand_to_include((-10, -10))
+ self.assertEqual((-10, -10, 10, 10), self.e)
+
+ def test06_expand_to_include_extent_4_params(self):
+ "Testing Envelope expand_to_include -- extent as 4 parameters."
+ self.e.expand_to_include(-1, 1, 3, 7)
+ self.assertEqual((-1, 0, 5, 7), self.e)
+
+ def test06_expand_to_include_extent_4_tuple(self):
+ "Testing Envelope expand_to_include -- extent as a single 4-tuple parameter."
+ self.e.expand_to_include((-1, 1, 3, 7))
+ self.assertEqual((-1, 0, 5, 7), self.e)
+
+ def test07_expand_to_include_envelope(self):
+ "Testing Envelope expand_to_include with Envelope as parameter."
+ self.e.expand_to_include(Envelope(-1, 1, 3, 7))
+ self.assertEqual((-1, 0, 5, 7), self.e)
- def test06_expand_to_include_extent_4_params(self):
- "Testing Envelope expand_to_include -- extent as 4 parameters."
- self.e.expand_to_include(-1, 1, 3, 7)
- self.assertEqual((-1, 0, 5, 7), self.e)
-
- def test06_expand_to_include_extent_4_tuple(self):
- "Testing Envelope expand_to_include -- extent as a single 4-tuple parameter."
- self.e.expand_to_include((-1, 1, 3, 7))
- self.assertEqual((-1, 0, 5, 7), self.e)
-
- def test07_expand_to_include_envelope(self):
- "Testing Envelope expand_to_include with Envelope as parameter."
- self.e.expand_to_include(Envelope(-1, 1, 3, 7))
- self.assertEqual((-1, 0, 5, 7), self.e)
-
- def test08_expand_to_include_point(self):
- "Testing Envelope expand_to_include with Point as parameter."
- self.e.expand_to_include(TestPoint(-1, 1))
- self.assertEqual((-1, 0, 5, 5), self.e)
- self.e.expand_to_include(TestPoint(10, 10))
- self.assertEqual((-1, 0, 10, 10), self.e)
+ def test08_expand_to_include_point(self):
+ "Testing Envelope expand_to_include with Point as parameter."
+ self.e.expand_to_include(TestPoint(-1, 1))
+ self.assertEqual((-1, 0, 5, 5), self.e)
+ self.e.expand_to_include(TestPoint(10, 10))
+ self.assertEqual((-1, 0, 10, 10), self.e)
def suite():
s = unittest.TestSuite()
@@ -1,8 +1,9 @@
-import unittest
from django.contrib.gis.gdal import OGRGeometry, OGRGeomType, \
OGRException, OGRIndexError, SpatialReference, CoordTransform, \
gdal_version
from django.contrib.gis.tests.geometries import *
+from django.utils import unittest
+
class OGRGeomTest(unittest.TestCase):
"This tests the OGR Geometry."
@@ -1,5 +1,6 @@
-import unittest
from django.contrib.gis.gdal import SpatialReference, CoordTransform, OGRException, SRSException
+from django.utils import unittest
+
class TestSRS:
def __init__(self, wkt, **kwargs):
@@ -79,7 +80,7 @@ def test04_proj(self):
srs1 = SpatialReference(s.wkt)
srs2 = SpatialReference(s.proj)
self.assertEqual(srs1.proj, srs2.proj)
-
+
def test05_epsg(self):
"Test EPSG import."
for s in srlist:
@@ -159,7 +160,7 @@ def test13_attr_value(self):
self.assertEqual(4326, int(s1['AUTHORITY', 1]))
#for i in range(7): self.assertEqual(0, int(s1['TOWGS84', i]))
self.assertEqual(None, s1['FOOBAR'])
-
+
def suite():
s = unittest.TestSuite()
s.addTest(unittest.makeSuite(SpatialRefTest))
@@ -1,7 +1,7 @@
"""
GEOS Testing module.
"""
-from unittest import TestSuite, TextTestRunner
+from django.utils.unittest import TestSuite, TextTestRunner
import test_geos, test_io, test_geos_mutation, test_mutable_list
test_suites = [
@@ -1,12 +1,12 @@
# Copyright (c) 2008-2009 Aryeh Leib Taurog, all rights reserved.
# Modified from original contribution by Aryeh Leib Taurog, which was
# released under the New BSD license.
-import unittest
import django.utils.copycompat as copy
from django.contrib.gis.geos import *
from django.contrib.gis.geos.error import GEOSIndexError
+from django.utils import unittest
def getItem(o,i): return o[i]
def delItem(o,i): del o[i]
@@ -3,8 +3,9 @@
#
# Modified from original contribution by Aryeh Leib Taurog, which was
# released under the New BSD license.
-import unittest
from django.contrib.gis.geos.mutable_list import ListMixin
+from django.utils import unittest
+
class UserListA(ListMixin):
_mytype = tuple
@@ -1,9 +1,10 @@
import sys
-import unittest
from django.conf import settings
from django.db.models import get_app
from django.test.simple import build_suite, DjangoTestSuiteRunner
+from django.utils import unittest
+
def run_tests(*args, **kwargs):
from django.test.simple import run_tests as base_run_tests
@@ -1,9 +1,11 @@
-import unittest
from xml.dom import minidom
from django.test import Client
+from django.utils import unittest
+
from models import City
+
class GeoFeedTest(unittest.TestCase):
client = Client()
@@ -1,9 +1,13 @@
-import unittest, zipfile, cStringIO
+import cStringIO
from xml.dom import minidom
+import zipfile
from django.test import Client
+from django.utils import unittest
+
from models import City, Country
+
class GeoSitemapTest(unittest.TestCase):
client = Client()
@@ -30,7 +34,7 @@ def test_geositemap_kml(self):
urlset = doc.firstChild
self.assertEqual(urlset.getAttribute(u'xmlns'), u'http://www.sitemaps.org/schemas/sitemap/0.9')
self.assertEqual(urlset.getAttribute(u'xmlns:geo'), u'http://www.google.com/geo/schemas/sitemap/1.0')
-
+
urls = urlset.getElementsByTagName('url')
self.assertEqual(2, len(urls)) # Should only be 2 sitemaps.
for url in urls:
@@ -42,7 +46,7 @@ def test_geositemap_kml(self):
# Getting the relative URL since we don't have a real site.
kml_url = url.getElementsByTagName('loc')[0].childNodes[0].data.split('http://example.com')[1]
-
+
if kml_type == 'kml':
kml_doc = minidom.parseString(self.client.get(kml_url).content)
elif kml_type == 'kmz':
@@ -52,7 +56,7 @@ def test_geositemap_kml(self):
self.assertEqual(1, len(zf.filelist))
self.assertEqual('doc.kml', zf.filelist[0].filename)
kml_doc = minidom.parseString(zf.read('doc.kml'))
-
+
# Ensuring the correct number of placemarks are in the KML doc.
if 'city' in kml_url:
model = City
@@ -65,7 +69,7 @@ def test_geositemap_georss(self):
from feeds import feed_dict
doc = minidom.parseString(self.client.get('/geoapp/sitemaps/georss.xml').content)
-
+
# Ensuring the right sitemaps namespaces are present.
urlset = doc.firstChild
self.assertEqual(urlset.getAttribute(u'xmlns'), u'http://www.sitemaps.org/schemas/sitemap/0.9')
Oops, something went wrong. Retry.

0 comments on commit 121d2e3

Please sign in to comment.