From 00a9c43c26946ac96573036997fdbea1a51c98f5 Mon Sep 17 00:00:00 2001 From: Aron Griffis Date: Thu, 6 Feb 2014 12:57:17 -0500 Subject: [PATCH] Fix #468: Loosen tests to account for extra newlines with libxml2-2.9.1 --- compressor/tests/test_base.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/compressor/tests/test_base.py b/compressor/tests/test_base.py index a68db96..0f669e5 100644 --- a/compressor/tests/test_base.py +++ b/compressor/tests/test_base.py @@ -63,6 +63,14 @@ class CompressorTestCase(SimpleTestCase): """ self.js_node = JsCompressor(self.js) + def assertEqualCollapsed(self, a, b): + """ + assertEqual with internal newlines collapsed to single, and + trailing whitespace removed. + """ + collapse = lambda x: re.sub(r'\n+', '\n', x).rstrip() + self.assertEqual(collapse(a), collapse(b)) + def test_css_split(self): out = [ ( @@ -84,7 +92,7 @@ class CompressorTestCase(SimpleTestCase): ), ] split = self.css_node.split_contents() - split = [(x[0], x[1], x[2], self.css_node.parser.elem_str(x[3])) for x in split] + split = [(x[0], x[1], x[2], self.css_node.parser.elem_str(x[3]).rstrip()) for x in split] self.assertEqual(out, split) def test_css_hunks(self): @@ -104,7 +112,7 @@ class CompressorTestCase(SimpleTestCase): def test_css_return_if_off(self): settings.COMPRESS_ENABLED = False - self.assertEqual(self.css, self.css_node.output()) + self.assertEqualCollapsed(self.css, self.css_node.output()) def test_cachekey(self): is_cachekey = re.compile(r'\w{12}') @@ -131,7 +139,7 @@ class CompressorTestCase(SimpleTestCase): ), ] split = self.js_node.split_contents() - split = [(x[0], x[1], x[2], self.js_node.parser.elem_str(x[3])) for x in split] + split = [(x[0], x[1], x[2], self.js_node.parser.elem_str(x[3]).rstrip()) for x in split] self.assertEqual(out, split) def test_js_hunks(self): @@ -154,7 +162,7 @@ class CompressorTestCase(SimpleTestCase): @override_settings(COMPRESS_PRECOMPILERS=(), COMPRESS_ENABLED=False) def test_js_return_if_off(self): - self.assertEqual(self.js, self.js_node.output()) + self.assertEqualCollapsed(self.js, self.js_node.output()) def test_js_return_if_on(self): output = ''