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
This commit is contained in:
parent
67df1a5002
commit
ec3ba39fdb
|
@ -1,8 +1,8 @@
|
||||||
from django.test import TestCase
|
import unittest
|
||||||
|
|
||||||
from django.utils import checksums
|
from django.utils import checksums
|
||||||
|
|
||||||
class TestUtilsChecksums(TestCase):
|
class TestUtilsChecksums(unittest.TestCase):
|
||||||
|
|
||||||
def check_output(self, function, value, output=None):
|
def check_output(self, function, value, output=None):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
from django.test import TestCase
|
import unittest
|
||||||
|
|
||||||
from django.utils.datastructures import SortedDict
|
from django.utils.datastructures import SortedDict
|
||||||
|
|
||||||
class DatastructuresTests(TestCase):
|
class DatastructuresTests(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.d1 = SortedDict()
|
self.d1 = SortedDict()
|
||||||
self.d1[7] = 'seven'
|
self.d1[7] = 'seven'
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import os
|
|
||||||
from unittest import TestCase
|
|
||||||
from datetime import datetime, date
|
from datetime import datetime, date
|
||||||
|
import os
|
||||||
|
import unittest
|
||||||
|
|
||||||
from django.utils.dateformat import format
|
from django.utils.dateformat import format
|
||||||
from django.utils.tzinfo import FixedOffset, LocalTimezone
|
from django.utils.tzinfo import FixedOffset, LocalTimezone
|
||||||
|
|
||||||
class DateFormatTests(TestCase):
|
class DateFormatTests(unittest.TestCase):
|
||||||
def test_date(self):
|
def test_date(self):
|
||||||
d = date(2009, 5, 16)
|
d = date(2009, 5, 16)
|
||||||
self.assertEquals(date.fromtimestamp(int(format(d, 'U'))), d)
|
self.assertEquals(date.fromtimestamp(int(format(d, 'U'))), d)
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
from django.test import TestCase
|
import unittest
|
||||||
|
|
||||||
from datetime import date as original_date, datetime as original_datetime
|
from datetime import date as original_date, datetime as original_datetime
|
||||||
from django.utils.datetime_safe import date, datetime
|
from django.utils.datetime_safe import date, datetime
|
||||||
|
|
||||||
class DatetimeTests(TestCase):
|
class DatetimeTests(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.just_safe = (1900, 1, 1)
|
self.just_safe = (1900, 1, 1)
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import datetime
|
import datetime
|
||||||
from unittest import TestCase
|
import unittest
|
||||||
|
|
||||||
from django.utils import feedgenerator, tzinfo
|
from django.utils import feedgenerator, tzinfo
|
||||||
|
|
||||||
class FeedgeneratorTest(TestCase):
|
class FeedgeneratorTest(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
Tests for the low-level syndication feed framework.
|
Tests for the low-level syndication feed framework.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
from unittest import TestCase
|
import unittest
|
||||||
|
|
||||||
from django.utils.functional import lazy
|
from django.utils.functional import lazy
|
||||||
|
|
||||||
|
|
||||||
class FunctionalTestCase(TestCase):
|
class FunctionalTestCase(unittest.TestCase):
|
||||||
def test_lazy(self):
|
def test_lazy(self):
|
||||||
t = lazy(lambda: tuple(range(3)), list, tuple)
|
t = lazy(lambda: tuple(range(3)), list, tuple)
|
||||||
for a, b in zip(t(), range(3)):
|
for a, b in zip(t(), range(3)):
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
from django.test import TestCase
|
import unittest
|
||||||
|
|
||||||
from django.utils import html
|
from django.utils import html
|
||||||
|
|
||||||
class TestUtilsHtml(TestCase):
|
class TestUtilsHtml(unittest.TestCase):
|
||||||
|
|
||||||
def check_output(self, function, value, output=None):
|
def check_output(self, function, value, output=None):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from unittest import TestCase
|
import unittest
|
||||||
from zipimport import zipimporter
|
from zipimport import zipimporter
|
||||||
|
|
||||||
from django.utils.importlib import import_module
|
from django.utils.importlib import import_module
|
||||||
from django.utils.module_loading import module_has_submodule
|
from django.utils.module_loading import module_has_submodule
|
||||||
|
|
||||||
class DefaultLoader(TestCase):
|
class DefaultLoader(unittest.TestCase):
|
||||||
def test_loader(self):
|
def test_loader(self):
|
||||||
"Normal module existence can be tested"
|
"Normal module existence can be tested"
|
||||||
test_module = import_module('regressiontests.utils.test_module')
|
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.assertFalse(module_has_submodule(test_module, 'no_such_module'))
|
||||||
self.assertRaises(ImportError, import_module, 'regressiontests.utils.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):
|
def setUp(self):
|
||||||
self.old_path = sys.path
|
self.old_path = sys.path
|
||||||
self.egg_dir = '%s/eggs' % os.path.dirname(__file__)
|
self.egg_dir = '%s/eggs' % os.path.dirname(__file__)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from django.test import TestCase
|
import unittest
|
||||||
|
|
||||||
|
import django.utils.copycompat as copy
|
||||||
from django.utils.functional import SimpleLazyObject
|
from django.utils.functional import SimpleLazyObject
|
||||||
|
|
||||||
class _ComplexObject(object):
|
class _ComplexObject(object):
|
||||||
|
@ -23,7 +24,7 @@ class _ComplexObject(object):
|
||||||
|
|
||||||
complex_object = lambda: _ComplexObject("joe")
|
complex_object = lambda: _ComplexObject("joe")
|
||||||
|
|
||||||
class TestUtilsSimpleLazyObject(TestCase):
|
class TestUtilsSimpleLazyObject(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
Tests for SimpleLazyObject
|
Tests for SimpleLazyObject
|
||||||
"""
|
"""
|
||||||
|
@ -59,7 +60,6 @@ class TestUtilsSimpleLazyObject(TestCase):
|
||||||
self.assertEqual(_ComplexObject, SimpleLazyObject(complex_object).__class__)
|
self.assertEqual(_ComplexObject, SimpleLazyObject(complex_object).__class__)
|
||||||
|
|
||||||
def test_deepcopy(self):
|
def test_deepcopy(self):
|
||||||
import django.utils.copycompat as copy
|
|
||||||
# Check that we *can* do deep copy, and that it returns the right
|
# Check that we *can* do deep copy, and that it returns the right
|
||||||
# objects.
|
# objects.
|
||||||
|
|
||||||
|
|
|
@ -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
|
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):
|
def test_empty_string(self):
|
||||||
self.assertEquals(parse_color_setting(''), PALETTES[DEFAULT_PALETTE])
|
self.assertEquals(parse_color_setting(''), PALETTES[DEFAULT_PALETTE])
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
from django.test import TestCase
|
import unittest
|
||||||
|
|
||||||
from django.utils import text
|
from django.utils import text
|
||||||
|
|
||||||
class TestUtilsText(TestCase):
|
class TestUtilsText(unittest.TestCase):
|
||||||
def test_truncate_words(self):
|
def test_truncate_words(self):
|
||||||
self.assertEqual(u'The quick brown fox jumped over the lazy dog.',
|
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))
|
text.truncate_words(u'The quick brown fox jumped over the lazy dog.', 10))
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import unittest
|
||||||
|
|
||||||
from django.utils.timesince import timesince, timeuntil
|
from django.utils.timesince import timesince, timeuntil
|
||||||
from django.utils.tzinfo import LocalTimezone, FixedOffset
|
from django.utils.tzinfo import LocalTimezone, FixedOffset
|
||||||
|
|
||||||
class TimesinceTests(TestCase):
|
class TimesinceTests(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.t = datetime.datetime(2007, 8, 14, 13, 46, 0)
|
self.t = datetime.datetime(2007, 8, 14, 13, 46, 0)
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
from django.test import TestCase
|
import unittest
|
||||||
|
|
||||||
from django.utils.tzinfo import FixedOffset
|
from django.utils.tzinfo import FixedOffset
|
||||||
|
|
||||||
class TzinfoTests(TestCase):
|
class TzinfoTests(unittest.TestCase):
|
||||||
|
|
||||||
def test_fixedoffset(self):
|
def test_fixedoffset(self):
|
||||||
self.assertEquals(repr(FixedOffset(0)), '+0000')
|
self.assertEquals(repr(FixedOffset(0)), '+0000')
|
||||||
|
|
Loading…
Reference in New Issue