From 00a9c43c26946ac96573036997fdbea1a51c98f5 Mon Sep 17 00:00:00 2001 From: Aron Griffis Date: Thu, 6 Feb 2014 12:57:17 -0500 Subject: [PATCH 1/2] 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 = '' From 0b5412aa6abd173a0540aa89d03fb8800f45aee1 Mon Sep 17 00:00:00 2001 From: Aron Griffis Date: Mon, 10 Feb 2014 10:24:19 -0500 Subject: [PATCH 2/2] Replace opaque rstrip() with assertEqualSplits() --- 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 0f669e5..46b1d91 100644 --- a/compressor/tests/test_base.py +++ b/compressor/tests/test_base.py @@ -71,6 +71,14 @@ class CompressorTestCase(SimpleTestCase): collapse = lambda x: re.sub(r'\n+', '\n', x).rstrip() self.assertEqual(collapse(a), collapse(b)) + def assertEqualSplits(self, a, b): + """ + assertEqual for splits, particularly ignoring the presence of + a trailing newline on the content. + """ + mangle = lambda split: [(x[0], x[1], x[2], x[3].rstrip()) for x in split] + self.assertEqual(mangle(a), mangle(b)) + def test_css_split(self): out = [ ( @@ -92,8 +100,8 @@ class CompressorTestCase(SimpleTestCase): ), ] split = self.css_node.split_contents() - split = [(x[0], x[1], x[2], self.css_node.parser.elem_str(x[3]).rstrip()) for x in split] - self.assertEqual(out, split) + split = [(x[0], x[1], x[2], self.css_node.parser.elem_str(x[3])) for x in split] + self.assertEqualSplits(split, out) def test_css_hunks(self): out = ['body { background:#990; }', 'p { border:5px solid green;}', 'body { color:#fff; }'] @@ -139,8 +147,8 @@ class CompressorTestCase(SimpleTestCase): ), ] split = self.js_node.split_contents() - split = [(x[0], x[1], x[2], self.js_node.parser.elem_str(x[3]).rstrip()) for x in split] - self.assertEqual(out, split) + split = [(x[0], x[1], x[2], self.js_node.parser.elem_str(x[3])) for x in split] + self.assertEqualSplits(split, out) def test_js_hunks(self): out = ['obj = {};', 'obj.value = "value";']