From ec3ba39fdb9dd6b82fb790a7babff5d2c4630ad5 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Tue, 28 Sep 2010 08:18:12 +0000 Subject: [PATCH] A few test optimizations; using native unittest where no Django-specific TestCase features are required. git-svn-id: http://code.djangoproject.com/svn/django/trunk@13935 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/utils/checksums.py | 4 ++-- tests/regressiontests/utils/datastructures.py | 5 +++-- tests/regressiontests/utils/dateformat.py | 7 ++++--- tests/regressiontests/utils/datetime_safe.py | 4 ++-- tests/regressiontests/utils/feedgenerator.py | 4 ++-- tests/regressiontests/utils/functional.py | 4 ++-- tests/regressiontests/utils/html.py | 4 ++-- tests/regressiontests/utils/module_loading.py | 6 +++--- tests/regressiontests/utils/simplelazyobject.py | 6 +++--- tests/regressiontests/utils/termcolors.py | 4 ++-- tests/regressiontests/utils/text.py | 4 ++-- tests/regressiontests/utils/timesince.py | 5 ++--- tests/regressiontests/utils/tzinfo.py | 4 ++-- 13 files changed, 31 insertions(+), 30 deletions(-) diff --git a/tests/regressiontests/utils/checksums.py b/tests/regressiontests/utils/checksums.py index bb73576a80..cee6dca2a8 100644 --- a/tests/regressiontests/utils/checksums.py +++ b/tests/regressiontests/utils/checksums.py @@ -1,8 +1,8 @@ -from django.test import TestCase +import unittest from django.utils import checksums -class TestUtilsChecksums(TestCase): +class TestUtilsChecksums(unittest.TestCase): def check_output(self, function, value, output=None): """ diff --git a/tests/regressiontests/utils/datastructures.py b/tests/regressiontests/utils/datastructures.py index a353a32404..e684694d7c 100644 --- a/tests/regressiontests/utils/datastructures.py +++ b/tests/regressiontests/utils/datastructures.py @@ -1,7 +1,8 @@ -from django.test import TestCase +import unittest + from django.utils.datastructures import SortedDict -class DatastructuresTests(TestCase): +class DatastructuresTests(unittest.TestCase): def setUp(self): self.d1 = SortedDict() self.d1[7] = 'seven' diff --git a/tests/regressiontests/utils/dateformat.py b/tests/regressiontests/utils/dateformat.py index b80010f8d8..d83e3e191c 100644 --- a/tests/regressiontests/utils/dateformat.py +++ b/tests/regressiontests/utils/dateformat.py @@ -1,10 +1,11 @@ -import os -from unittest import TestCase from datetime import datetime, date +import os +import unittest + from django.utils.dateformat import format from django.utils.tzinfo import FixedOffset, LocalTimezone -class DateFormatTests(TestCase): +class DateFormatTests(unittest.TestCase): def test_date(self): d = date(2009, 5, 16) self.assertEquals(date.fromtimestamp(int(format(d, 'U'))), d) diff --git a/tests/regressiontests/utils/datetime_safe.py b/tests/regressiontests/utils/datetime_safe.py index 62b9c7481f..458a6b79f8 100644 --- a/tests/regressiontests/utils/datetime_safe.py +++ b/tests/regressiontests/utils/datetime_safe.py @@ -1,9 +1,9 @@ -from django.test import TestCase +import unittest from datetime import date as original_date, datetime as original_datetime from django.utils.datetime_safe import date, datetime -class DatetimeTests(TestCase): +class DatetimeTests(unittest.TestCase): def setUp(self): self.just_safe = (1900, 1, 1) diff --git a/tests/regressiontests/utils/feedgenerator.py b/tests/regressiontests/utils/feedgenerator.py index 5a10de2d1b..9085d41c06 100644 --- a/tests/regressiontests/utils/feedgenerator.py +++ b/tests/regressiontests/utils/feedgenerator.py @@ -1,9 +1,9 @@ import datetime -from unittest import TestCase +import unittest from django.utils import feedgenerator, tzinfo -class FeedgeneratorTest(TestCase): +class FeedgeneratorTest(unittest.TestCase): """ Tests for the low-level syndication feed framework. """ diff --git a/tests/regressiontests/utils/functional.py b/tests/regressiontests/utils/functional.py index 72610154d8..206a5838b5 100644 --- a/tests/regressiontests/utils/functional.py +++ b/tests/regressiontests/utils/functional.py @@ -1,9 +1,9 @@ -from unittest import TestCase +import unittest from django.utils.functional import lazy -class FunctionalTestCase(TestCase): +class FunctionalTestCase(unittest.TestCase): def test_lazy(self): t = lazy(lambda: tuple(range(3)), list, tuple) for a, b in zip(t(), range(3)): diff --git a/tests/regressiontests/utils/html.py b/tests/regressiontests/utils/html.py index 61ca6f4c53..a9b0d337f2 100644 --- a/tests/regressiontests/utils/html.py +++ b/tests/regressiontests/utils/html.py @@ -1,8 +1,8 @@ -from django.test import TestCase +import unittest from django.utils import html -class TestUtilsHtml(TestCase): +class TestUtilsHtml(unittest.TestCase): def check_output(self, function, value, output=None): """ diff --git a/tests/regressiontests/utils/module_loading.py b/tests/regressiontests/utils/module_loading.py index b7df6d68b1..4422f8f5d8 100644 --- a/tests/regressiontests/utils/module_loading.py +++ b/tests/regressiontests/utils/module_loading.py @@ -1,12 +1,12 @@ import os import sys -from unittest import TestCase +import unittest from zipimport import zipimporter from django.utils.importlib import import_module from django.utils.module_loading import module_has_submodule -class DefaultLoader(TestCase): +class DefaultLoader(unittest.TestCase): def test_loader(self): "Normal module existence can be tested" test_module = import_module('regressiontests.utils.test_module') @@ -24,7 +24,7 @@ class DefaultLoader(TestCase): self.assertFalse(module_has_submodule(test_module, 'no_such_module')) self.assertRaises(ImportError, import_module, 'regressiontests.utils.test_module.no_such_module') -class EggLoader(TestCase): +class EggLoader(unittest.TestCase): def setUp(self): self.old_path = sys.path self.egg_dir = '%s/eggs' % os.path.dirname(__file__) diff --git a/tests/regressiontests/utils/simplelazyobject.py b/tests/regressiontests/utils/simplelazyobject.py index 1df55aa885..4a930dd69b 100644 --- a/tests/regressiontests/utils/simplelazyobject.py +++ b/tests/regressiontests/utils/simplelazyobject.py @@ -1,5 +1,6 @@ -from django.test import TestCase +import unittest +import django.utils.copycompat as copy from django.utils.functional import SimpleLazyObject class _ComplexObject(object): @@ -23,7 +24,7 @@ class _ComplexObject(object): complex_object = lambda: _ComplexObject("joe") -class TestUtilsSimpleLazyObject(TestCase): +class TestUtilsSimpleLazyObject(unittest.TestCase): """ Tests for SimpleLazyObject """ @@ -59,7 +60,6 @@ class TestUtilsSimpleLazyObject(TestCase): self.assertEqual(_ComplexObject, SimpleLazyObject(complex_object).__class__) def test_deepcopy(self): - import django.utils.copycompat as copy # Check that we *can* do deep copy, and that it returns the right # objects. diff --git a/tests/regressiontests/utils/termcolors.py b/tests/regressiontests/utils/termcolors.py index 7c8fe0d63b..ccae32cd16 100644 --- a/tests/regressiontests/utils/termcolors.py +++ b/tests/regressiontests/utils/termcolors.py @@ -1,8 +1,8 @@ -from unittest import TestCase +import unittest from django.utils.termcolors import parse_color_setting, PALETTES, DEFAULT_PALETTE, LIGHT_PALETTE, DARK_PALETTE, NOCOLOR_PALETTE -class TermColorTests(TestCase): +class TermColorTests(unittest.TestCase): def test_empty_string(self): self.assertEquals(parse_color_setting(''), PALETTES[DEFAULT_PALETTE]) diff --git a/tests/regressiontests/utils/text.py b/tests/regressiontests/utils/text.py index 7cf52ca92c..e7d2d38d3b 100644 --- a/tests/regressiontests/utils/text.py +++ b/tests/regressiontests/utils/text.py @@ -1,8 +1,8 @@ -from django.test import TestCase +import unittest from django.utils import text -class TestUtilsText(TestCase): +class TestUtilsText(unittest.TestCase): def test_truncate_words(self): self.assertEqual(u'The quick brown fox jumped over the lazy dog.', text.truncate_words(u'The quick brown fox jumped over the lazy dog.', 10)) diff --git a/tests/regressiontests/utils/timesince.py b/tests/regressiontests/utils/timesince.py index d751121730..774aa3f7cd 100644 --- a/tests/regressiontests/utils/timesince.py +++ b/tests/regressiontests/utils/timesince.py @@ -1,11 +1,10 @@ -from django.test import TestCase - import datetime +import unittest from django.utils.timesince import timesince, timeuntil from django.utils.tzinfo import LocalTimezone, FixedOffset -class TimesinceTests(TestCase): +class TimesinceTests(unittest.TestCase): def setUp(self): self.t = datetime.datetime(2007, 8, 14, 13, 46, 0) diff --git a/tests/regressiontests/utils/tzinfo.py b/tests/regressiontests/utils/tzinfo.py index 60fc0b942e..edbb9a70da 100644 --- a/tests/regressiontests/utils/tzinfo.py +++ b/tests/regressiontests/utils/tzinfo.py @@ -1,8 +1,8 @@ -from django.test import TestCase +import unittest from django.utils.tzinfo import FixedOffset -class TzinfoTests(TestCase): +class TzinfoTests(unittest.TestCase): def test_fixedoffset(self): self.assertEquals(repr(FixedOffset(0)), '+0000')