Use Django's wrapped version of unittest2.

This commit is contained in:
Jannis Leidel
2013-05-27 11:23:10 +02:00
parent 963a210063
commit 21e1962e5a
3 changed files with 11 additions and 26 deletions

View File

@@ -6,6 +6,7 @@ import textwrap
from django.utils import six from django.utils import six
from django.test import TestCase from django.test import TestCase
from django.utils import unittest
from compressor.cache import get_hashed_mtime, get_hashed_content from compressor.cache import get_hashed_mtime, get_hashed_content
from compressor.conf import settings from compressor.conf import settings
@@ -17,13 +18,8 @@ from compressor.filters.css_default import CssAbsoluteFilter
from compressor.filters.template import TemplateFilter from compressor.filters.template import TemplateFilter
from compressor.tests.test_base import test_dir from compressor.tests.test_base import test_dir
try:
from django.utils import unittest as ut2
except ImportError:
import unittest2 as ut2
@unittest.skipIf(find_command(settings.COMPRESS_CSSTIDY_BINARY) is None,
@ut2.skipIf(find_command(settings.COMPRESS_CSSTIDY_BINARY) is None,
'CSStidy binary %r not found' % settings.COMPRESS_CSSTIDY_BINARY) 'CSStidy binary %r not found' % settings.COMPRESS_CSSTIDY_BINARY)
class CssTidyTestCase(TestCase): class CssTidyTestCase(TestCase):
def test_tidy(self): def test_tidy(self):

View File

@@ -3,10 +3,10 @@ import io
import os import os
import django import django
from django.core.management.base import CommandError
from django.template import Template, Context from django.template import Template, Context
from django.test import TestCase from django.test import TestCase
from django.utils import six from django.utils import six, unittest
from django.core.management.base import CommandError
from compressor.cache import flush_offline_manifest, get_offline_manifest from compressor.cache import flush_offline_manifest, get_offline_manifest
from compressor.conf import settings from compressor.conf import settings
@@ -14,11 +14,6 @@ from compressor.exceptions import OfflineGenerationError
from compressor.management.commands.compress import Command as CompressCommand from compressor.management.commands.compress import Command as CompressCommand
from compressor.storage import default_storage from compressor.storage import default_storage
try:
from django.utils import unittest as ut2
except ImportError:
import unittest2 as ut2
if six.PY3: if six.PY3:
# there is an 'io' module in python 2.6+, but io.StringIO does not # there is an 'io' module in python 2.6+, but io.StringIO does not
# accept regular strings, just unicode objects # accept regular strings, just unicode objects
@@ -140,13 +135,11 @@ class OfflineGenerationTemplateTagTestCase(OfflineTestCaseMixin, TestCase):
expected_hash = "a27e1d3a619a" expected_hash = "a27e1d3a619a"
# This test uses {% static %} which was introduced in django 1.4
@unittest.skipIf(django.VERSION[1] < 4, 'Django 1.4 not found')
class OfflineGenerationStaticTemplateTagTestCase(OfflineTestCaseMixin, TestCase): class OfflineGenerationStaticTemplateTagTestCase(OfflineTestCaseMixin, TestCase):
templates_dir = "test_static_templatetag" templates_dir = "test_static_templatetag"
expected_hash = "dfa2bb387fa8" expected_hash = "dfa2bb387fa8"
# This test uses {% static %} which was introduced in django 1.4
OfflineGenerationStaticTemplateTagTestCase = ut2.skipIf(
django.VERSION[1] < 4, 'Django 1.4 not found'
)(OfflineGenerationStaticTemplateTagTestCase)
class OfflineGenerationTestCaseWithContext(OfflineTestCaseMixin, TestCase): class OfflineGenerationTestCaseWithContext(OfflineTestCaseMixin, TestCase):

View File

@@ -16,16 +16,12 @@ try:
except ImportError: except ImportError:
BeautifulSoup = None BeautifulSoup = None
from django.utils import unittest
from compressor.base import SOURCE_HUNK, SOURCE_FILE from compressor.base import SOURCE_HUNK, SOURCE_FILE
from compressor.conf import settings from compressor.conf import settings
from compressor.tests.test_base import CompressorTestCase from compressor.tests.test_base import CompressorTestCase
try:
from django.utils import unittest as ut2
except ImportError:
import unittest2 as ut2
class ParserTestCase(object): class ParserTestCase(object):
def setUp(self): def setUp(self):
@@ -37,12 +33,12 @@ class ParserTestCase(object):
settings.COMPRESS_PARSER = self.old_parser settings.COMPRESS_PARSER = self.old_parser
@ut2.skipIf(lxml is None, 'lxml not found') @unittest.skipIf(lxml is None, 'lxml not found')
class LxmlParserTests(ParserTestCase, CompressorTestCase): class LxmlParserTests(ParserTestCase, CompressorTestCase):
parser_cls = 'compressor.parser.LxmlParser' parser_cls = 'compressor.parser.LxmlParser'
@ut2.skipIf(html5lib is None, 'html5lib not found') @unittest.skipIf(html5lib is None, 'html5lib not found')
class Html5LibParserTests(ParserTestCase, CompressorTestCase): class Html5LibParserTests(ParserTestCase, CompressorTestCase):
parser_cls = 'compressor.parser.Html5LibParser' parser_cls = 'compressor.parser.Html5LibParser'
# Special test variants required since xml.etree holds attributes # Special test variants required since xml.etree holds attributes
@@ -126,7 +122,7 @@ class Html5LibParserTests(ParserTestCase, CompressorTestCase):
settings.COMPRESS_PRECOMPILERS = precompilers settings.COMPRESS_PRECOMPILERS = precompilers
@ut2.skipIf(BeautifulSoup is None, 'BeautifulSoup not found') @unittest.skipIf(BeautifulSoup is None, 'BeautifulSoup not found')
class BeautifulSoupParserTests(ParserTestCase, CompressorTestCase): class BeautifulSoupParserTests(ParserTestCase, CompressorTestCase):
parser_cls = 'compressor.parser.BeautifulSoupParser' parser_cls = 'compressor.parser.BeautifulSoupParser'