Use unittest2.skipIf decorator for some of the tests.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import os
|
||||
import re
|
||||
import socket
|
||||
from unittest2 import skipIf
|
||||
|
||||
from BeautifulSoup import BeautifulSoup
|
||||
|
||||
try:
|
||||
@@ -134,55 +136,57 @@ class CompressorTestCase(TestCase):
|
||||
finally:
|
||||
settings.COMPRESS_OUTPUT_DIR = old_output_dir
|
||||
|
||||
if lxml:
|
||||
class LxmlCompressorTestCase(CompressorTestCase):
|
||||
class LxmlCompressorTestCase(CompressorTestCase):
|
||||
|
||||
def test_css_split(self):
|
||||
out = [
|
||||
('file', os.path.join(settings.COMPRESS_ROOT, u'css/one.css'), u'<link rel="stylesheet" href="/media/css/one.css" type="text/css" charset="utf-8">'),
|
||||
('hunk', u'p { border:5px solid green;}', u'<style type="text/css">p { border:5px solid green;}</style>'),
|
||||
('file', os.path.join(settings.COMPRESS_ROOT, u'css/two.css'), u'<link rel="stylesheet" href="/media/css/two.css" type="text/css" charset="utf-8">'),
|
||||
]
|
||||
split = self.css_node.split_contents()
|
||||
split = [(x[0], x[1], self.css_node.parser.elem_str(x[2])) for x in split]
|
||||
self.assertEqual(out, split)
|
||||
def test_css_split(self):
|
||||
out = [
|
||||
('file', os.path.join(settings.COMPRESS_ROOT, u'css/one.css'), u'<link rel="stylesheet" href="/media/css/one.css" type="text/css" charset="utf-8">'),
|
||||
('hunk', u'p { border:5px solid green;}', u'<style type="text/css">p { border:5px solid green;}</style>'),
|
||||
('file', os.path.join(settings.COMPRESS_ROOT, u'css/two.css'), u'<link rel="stylesheet" href="/media/css/two.css" type="text/css" charset="utf-8">'),
|
||||
]
|
||||
split = self.css_node.split_contents()
|
||||
split = [(x[0], x[1], self.css_node.parser.elem_str(x[2])) for x in split]
|
||||
self.assertEqual(out, split)
|
||||
|
||||
def setUp(self):
|
||||
self.old_parser = settings.COMPRESS_PARSER
|
||||
settings.COMPRESS_PARSER = 'compressor.parser.LxmlParser'
|
||||
super(LxmlCompressorTestCase, self).setUp()
|
||||
def setUp(self):
|
||||
self.old_parser = settings.COMPRESS_PARSER
|
||||
settings.COMPRESS_PARSER = 'compressor.parser.LxmlParser'
|
||||
super(LxmlCompressorTestCase, self).setUp()
|
||||
|
||||
def tearDown(self):
|
||||
settings.COMPRESS_PARSER = self.old_parser
|
||||
def tearDown(self):
|
||||
settings.COMPRESS_PARSER = self.old_parser
|
||||
LxmlCompressorTestCase = skipIf(lxml is None, 'lxml not found')(LxmlCompressorTestCase)
|
||||
|
||||
if html5lib:
|
||||
class Html5LibCompressorTesCase(CompressorTestCase):
|
||||
|
||||
def test_css_split(self):
|
||||
out = [
|
||||
('file', os.path.join(settings.COMPRESS_ROOT, u'css/one.css'), u'<link charset="utf-8" href="/media/css/one.css" rel="stylesheet" type="text/css">'),
|
||||
('hunk', u'p { border:5px solid green;}', u'<style type="text/css">p { border:5px solid green;}</style>'),
|
||||
('file', os.path.join(settings.COMPRESS_ROOT, u'css/two.css'), u'<link charset="utf-8" href="/media/css/two.css" rel="stylesheet" type="text/css">'),
|
||||
]
|
||||
split = self.css_node.split_contents()
|
||||
split = [(x[0], x[1], self.css_node.parser.elem_str(x[2])) for x in split]
|
||||
self.assertEqual(out, split)
|
||||
class Html5LibCompressorTesCase(CompressorTestCase):
|
||||
|
||||
def test_js_split(self):
|
||||
out = [('file', os.path.join(settings.COMPRESS_ROOT, u'js/one.js'), u'<script charset="utf-8" src="/media/js/one.js" type="text/javascript"></script>'),
|
||||
('hunk', u'obj.value = "value";', u'<script charset="utf-8" type="text/javascript">obj.value = "value";</script>')
|
||||
]
|
||||
split = self.js_node.split_contents()
|
||||
split = [(x[0], x[1], self.js_node.parser.elem_str(x[2])) for x in split]
|
||||
self.assertEqual(out, split)
|
||||
def test_css_split(self):
|
||||
out = [
|
||||
('file', os.path.join(settings.COMPRESS_ROOT, u'css/one.css'), u'<link charset="utf-8" href="/media/css/one.css" rel="stylesheet" type="text/css">'),
|
||||
('hunk', u'p { border:5px solid green;}', u'<style type="text/css">p { border:5px solid green;}</style>'),
|
||||
('file', os.path.join(settings.COMPRESS_ROOT, u'css/two.css'), u'<link charset="utf-8" href="/media/css/two.css" rel="stylesheet" type="text/css">'),
|
||||
]
|
||||
split = self.css_node.split_contents()
|
||||
split = [(x[0], x[1], self.css_node.parser.elem_str(x[2])) for x in split]
|
||||
self.assertEqual(out, split)
|
||||
|
||||
def setUp(self):
|
||||
self.old_parser = settings.COMPRESS_PARSER
|
||||
settings.COMPRESS_PARSER = 'compressor.parser.Html5LibParser'
|
||||
super(Html5LibCompressorTesCase, self).setUp()
|
||||
def test_js_split(self):
|
||||
out = [('file', os.path.join(settings.COMPRESS_ROOT, u'js/one.js'), u'<script charset="utf-8" src="/media/js/one.js" type="text/javascript"></script>'),
|
||||
('hunk', u'obj.value = "value";', u'<script charset="utf-8" type="text/javascript">obj.value = "value";</script>')
|
||||
]
|
||||
split = self.js_node.split_contents()
|
||||
split = [(x[0], x[1], self.js_node.parser.elem_str(x[2])) for x in split]
|
||||
self.assertEqual(out, split)
|
||||
|
||||
def setUp(self):
|
||||
self.old_parser = settings.COMPRESS_PARSER
|
||||
settings.COMPRESS_PARSER = 'compressor.parser.Html5LibParser'
|
||||
super(Html5LibCompressorTesCase, self).setUp()
|
||||
|
||||
def tearDown(self):
|
||||
settings.COMPRESS_PARSER = self.old_parser
|
||||
Html5LibCompressorTesCase = skipIf(html5lib is None, 'html5lib not found')(Html5LibCompressorTesCase)
|
||||
|
||||
def tearDown(self):
|
||||
settings.COMPRESS_PARSER = self.old_parser
|
||||
|
||||
class CssAbsolutizingTestCase(TestCase):
|
||||
def setUp(self):
|
||||
@@ -454,17 +458,19 @@ class OfflineGenerationTestCase(TestCase):
|
||||
settings.COMPRESS_OFFLINE_CONTEXT = self._old_offline_context
|
||||
|
||||
|
||||
if find_command(settings.COMPRESS_CSSTIDY_BINARY):
|
||||
|
||||
class CssTidyTestCase(TestCase):
|
||||
|
||||
def test_tidy(self):
|
||||
content = """
|
||||
class CssTidyTestCase(TestCase):
|
||||
def test_tidy(self):
|
||||
content = """
|
||||
/* Some comment */
|
||||
font,th,td,p{
|
||||
color: black;
|
||||
color: black;
|
||||
}
|
||||
"""
|
||||
from compressor.filters.csstidy import CSSTidyFilter
|
||||
self.assertEqual(
|
||||
"font,th,td,p{color:#000;}", CSSTidyFilter(content).output())
|
||||
from compressor.filters.csstidy import CSSTidyFilter
|
||||
self.assertEqual(
|
||||
"font,th,td,p{color:#000;}", CSSTidyFilter(content).output())
|
||||
|
||||
CssTidyTestCase = skipIf(
|
||||
find_command(settings.COMPRESS_CSSTIDY_BINARY) is None,
|
||||
'CSStidy binary %r not found' % settings.COMPRESS_CSSTIDY_BINARY
|
||||
)(CssTidyTestCase)
|
||||
|
||||
Reference in New Issue
Block a user