Commit 4f9cb08f by Timothée Peignier

fix use of os.path.relpath to calculate relative path

parent 095ac354
...@@ -191,21 +191,21 @@ class Compressor(object): ...@@ -191,21 +191,21 @@ class Compressor(object):
name, ext = os.path.splitext(path) name, ext = os.path.splitext(path)
return MIME_TYPES[ext] return MIME_TYPES[ext]
def absolute_path(self, asset_path, css_path): def absolute_path(self, path, start):
""" """
Return the absolute public path for an asset, Return the absolute public path for an asset,
given the path of the stylesheet that contains it. given the path of the stylesheet that contains it.
""" """
if os.path.isabs(asset_path): if os.path.isabs(path):
path = os.path.join(settings.PIPELINE_ROOT, asset_path) path = os.path.join(settings.PIPELINE_ROOT, path)
else: else:
path = os.path.join(os.path.dirname(css_path), asset_path) path = os.path.join(os.path.dirname(start), path)
return os.path.normpath(path) return os.path.normpath(path)
def relative_path(self, absolute_path): def relative_path(self, absolute_path):
"""Rewrite paths relative to the output stylesheet path""" """Rewrite paths relative to the output stylesheet path"""
compress_root = os.path.normpath(settings.PIPELINE_ROOT) absolute_path = self.absolute_path(absolute_path, settings.PIPELINE_ROOT)
return os.path.join(os.sep, os.path.relpath(absolute_path, compress_root)) return os.path.join(os.sep, os.path.relpath(absolute_path, settings.PIPELINE_ROOT))
def read_file(self, path): def read_file(self, path):
"""Read file content in binary mode""" """Read file content in binary mode"""
......
...@@ -34,7 +34,7 @@ class CompressorTest(TestCase): ...@@ -34,7 +34,7 @@ class CompressorTest(TestCase):
'js/first.js', 'js/first.js',
'js/second.js' 'js/second.js'
]) ])
self.assertEquals("""(function() { function concat() {\n console.log(arguments);\n}\nfunction cat() {\n console.log("hello world");\n} }).call(this);""", js) self.assertEquals("""function concat() {\n console.log(arguments);\n}\nfunction cat() {\n console.log("hello world");\n}""", js)
@patch.object(base64, 'b64encode') @patch.object(base64, 'b64encode')
def test_encoded_content(self, mock): def test_encoded_content(self, mock):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment