diff --git a/compressor/tests/tests.py b/compressor/tests/tests.py index 577fb4b..5d628fd 100644 --- a/compressor/tests/tests.py +++ b/compressor/tests/tests.py @@ -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''), - ('hunk', u'p { border:5px solid green;}', u''), - ('file', os.path.join(settings.COMPRESS_ROOT, u'css/two.css'), u''), - ] - 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''), + ('hunk', u'p { border:5px solid green;}', u''), + ('file', os.path.join(settings.COMPRESS_ROOT, u'css/two.css'), u''), + ] + 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''), - ('hunk', u'p { border:5px solid green;}', u''), - ('file', os.path.join(settings.COMPRESS_ROOT, u'css/two.css'), u''), - ] - 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''), - ('hunk', u'obj.value = "value";', u'') - ] - 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''), + ('hunk', u'p { border:5px solid green;}', u''), + ('file', os.path.join(settings.COMPRESS_ROOT, u'css/two.css'), u''), + ] + 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''), + ('hunk', u'obj.value = "value";', u'') + ] + 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)