Use unittest2.skipIf decorator for some of the tests.
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import socket
|
import socket
|
||||||
|
from unittest2 import skipIf
|
||||||
|
|
||||||
from BeautifulSoup import BeautifulSoup
|
from BeautifulSoup import BeautifulSoup
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -134,55 +136,57 @@ class CompressorTestCase(TestCase):
|
|||||||
finally:
|
finally:
|
||||||
settings.COMPRESS_OUTPUT_DIR = old_output_dir
|
settings.COMPRESS_OUTPUT_DIR = old_output_dir
|
||||||
|
|
||||||
if lxml:
|
class LxmlCompressorTestCase(CompressorTestCase):
|
||||||
class LxmlCompressorTestCase(CompressorTestCase):
|
|
||||||
|
|
||||||
def test_css_split(self):
|
def test_css_split(self):
|
||||||
out = [
|
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">'),
|
('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>'),
|
('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">'),
|
('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 = self.css_node.split_contents()
|
||||||
split = [(x[0], x[1], self.css_node.parser.elem_str(x[2])) for x in split]
|
split = [(x[0], x[1], self.css_node.parser.elem_str(x[2])) for x in split]
|
||||||
self.assertEqual(out, split)
|
self.assertEqual(out, split)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.old_parser = settings.COMPRESS_PARSER
|
self.old_parser = settings.COMPRESS_PARSER
|
||||||
settings.COMPRESS_PARSER = 'compressor.parser.LxmlParser'
|
settings.COMPRESS_PARSER = 'compressor.parser.LxmlParser'
|
||||||
super(LxmlCompressorTestCase, self).setUp()
|
super(LxmlCompressorTestCase, self).setUp()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
settings.COMPRESS_PARSER = self.old_parser
|
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):
|
class Html5LibCompressorTesCase(CompressorTestCase):
|
||||||
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 test_js_split(self):
|
def test_css_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>'),
|
out = [
|
||||||
('hunk', u'obj.value = "value";', u'<script charset="utf-8" type="text/javascript">obj.value = "value";</script>')
|
('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>'),
|
||||||
split = self.js_node.split_contents()
|
('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 = [(x[0], x[1], self.js_node.parser.elem_str(x[2])) for x in split]
|
]
|
||||||
self.assertEqual(out, split)
|
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):
|
def test_js_split(self):
|
||||||
self.old_parser = settings.COMPRESS_PARSER
|
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>'),
|
||||||
settings.COMPRESS_PARSER = 'compressor.parser.Html5LibParser'
|
('hunk', u'obj.value = "value";', u'<script charset="utf-8" type="text/javascript">obj.value = "value";</script>')
|
||||||
super(Html5LibCompressorTesCase, self).setUp()
|
]
|
||||||
|
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):
|
class CssAbsolutizingTestCase(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@@ -454,17 +458,19 @@ class OfflineGenerationTestCase(TestCase):
|
|||||||
settings.COMPRESS_OFFLINE_CONTEXT = self._old_offline_context
|
settings.COMPRESS_OFFLINE_CONTEXT = self._old_offline_context
|
||||||
|
|
||||||
|
|
||||||
if find_command(settings.COMPRESS_CSSTIDY_BINARY):
|
class CssTidyTestCase(TestCase):
|
||||||
|
def test_tidy(self):
|
||||||
class CssTidyTestCase(TestCase):
|
content = """
|
||||||
|
|
||||||
def test_tidy(self):
|
|
||||||
content = """
|
|
||||||
/* Some comment */
|
/* Some comment */
|
||||||
font,th,td,p{
|
font,th,td,p{
|
||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
from compressor.filters.csstidy import CSSTidyFilter
|
from compressor.filters.csstidy import CSSTidyFilter
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
"font,th,td,p{color:#000;}", CSSTidyFilter(content).output())
|
"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