Commit 9bebcbfb by idan Committed by Timothée Peignier

fix tests and compatibility for windows environment

parent dfd4cbb3
...@@ -154,11 +154,11 @@ class Compressor(object): ...@@ -154,11 +154,11 @@ class Compressor(object):
def embeddable(self, path, variant): def embeddable(self, path, variant):
"""Is the asset embeddable ?""" """Is the asset embeddable ?"""
name, ext = posixpath.splitext(path) name, ext = os.path.splitext(path)
font = ext in FONT_EXTS font = ext in FONT_EXTS
if not variant: if not variant:
return False return False
if not (re.search(settings.PIPELINE_EMBED_PATH, path) and self.storage.exists(path)): if not (re.search(settings.PIPELINE_EMBED_PATH, path.replace('\\','/')) and self.storage.exists(path)):
return False return False
if not ext in EMBED_EXTS: if not ext in EMBED_EXTS:
return False return False
......
...@@ -3,6 +3,8 @@ from django.test import TestCase ...@@ -3,6 +3,8 @@ from django.test import TestCase
from pipeline.conf import settings from pipeline.conf import settings
from pipeline.compilers import Compiler, CompilerBase from pipeline.compilers import Compiler, CompilerBase
from paths import _
class DummyCompiler(CompilerBase): class DummyCompiler(CompilerBase):
output_extension = 'js' output_extension = 'js'
...@@ -30,10 +32,10 @@ class CompilerTest(TestCase): ...@@ -30,10 +32,10 @@ class CompilerTest(TestCase):
def test_compile(self): def test_compile(self):
paths = self.compiler.compile([ paths = self.compiler.compile([
'pipeline/js/dummy.coffee', _('pipeline/js/dummy.coffee'),
'pipeline/js/application.js', _('pipeline/js/application.js'),
]) ])
self.assertEquals(['pipeline/js/dummy.js', 'pipeline/js/application.js'], paths) self.assertEquals([_('pipeline/js/dummy.js'), _('pipeline/js/application.js')], paths)
def tearDown(self): def tearDown(self):
settings.PIPELINE_COMPILERS = self.old_compilers settings.PIPELINE_COMPILERS = self.old_compilers
...@@ -8,6 +8,8 @@ from django.test import TestCase ...@@ -8,6 +8,8 @@ from django.test import TestCase
from pipeline.compressors import Compressor, TEMPLATE_FUNC from pipeline.compressors import Compressor, TEMPLATE_FUNC
from pipeline.compressors.yui import YUICompressor from pipeline.compressors.yui import YUICompressor
from paths import _
class CompressorTest(TestCase): class CompressorTest(TestCase):
def setUp(self): def setUp(self):
...@@ -22,24 +24,24 @@ class CompressorTest(TestCase): ...@@ -22,24 +24,24 @@ class CompressorTest(TestCase):
def test_concatenate_and_rewrite(self): def test_concatenate_and_rewrite(self):
css = self.compressor.concatenate_and_rewrite([ css = self.compressor.concatenate_and_rewrite([
'pipeline/css/first.css', _('pipeline/css/first.css'),
'pipeline/css/second.css' _('pipeline/css/second.css')
], 'css/screen.css') ], 'css/screen.css')
self.assertEquals(""".concat {\n display: none;\n}\n\n.concatenate {\n display: block;\n}\n""", css) self.assertEquals(""".concat {\n display: none;\n}\n\n.concatenate {\n display: block;\n}\n""", css)
def test_concatenate(self): def test_concatenate(self):
js = self.compressor.concatenate([ js = self.compressor.concatenate([
'pipeline/js/first.js', _('pipeline/js/first.js'),
'pipeline/js/second.js' _('pipeline/js/second.js')
]) ])
self.assertEquals("""function concat() {\n console.log(arguments);\n}\n\nfunction cat() {\n console.log("hello world");\n}\n""", js) self.assertEquals("""function concat() {\n console.log(arguments);\n}\n\nfunction cat() {\n console.log("hello world");\n}\n""", js)
@patch.object(base64, 'b64encode') @patch.object(base64, 'b64encode')
def test_encoded_content(self, mock): def test_encoded_content(self, mock):
self.compressor.encoded_content('pipeline/images/arrow.png') self.compressor.encoded_content(_('pipeline/images/arrow.png'))
self.assertTrue(mock.called) self.assertTrue(mock.called)
mock.reset_mock() mock.reset_mock()
self.compressor.encoded_content('pipeline/images/arrow.png') self.compressor.encoded_content(_('pipeline/images/arrow.png'))
self.assertFalse(mock.called) self.assertFalse(mock.called)
def test_relative_path(self): def test_relative_path(self):
...@@ -48,9 +50,9 @@ class CompressorTest(TestCase): ...@@ -48,9 +50,9 @@ class CompressorTest(TestCase):
def test_base_path(self): def test_base_path(self):
base_path = self.compressor.base_path([ base_path = self.compressor.base_path([
'js/templates/form.jst', 'js/templates/field.jst' _('js/templates/form.jst'), _('js/templates/field.jst')
]) ])
self.assertEquals(base_path, 'js/templates') self.assertEquals(base_path, _('js/templates'))
def test_absolute_path(self): def test_absolute_path(self):
absolute_path = self.compressor.absolute_path('../../images/sprite.png', absolute_path = self.compressor.absolute_path('../../images/sprite.png',
...@@ -71,19 +73,19 @@ class CompressorTest(TestCase): ...@@ -71,19 +73,19 @@ class CompressorTest(TestCase):
self.assertEquals(name, 'photo_detail') self.assertEquals(name, 'photo_detail')
def test_compile_templates(self): def test_compile_templates(self):
templates = self.compressor.compile_templates(['pipeline/templates/photo/list.jst']) templates = self.compressor.compile_templates([_('pipeline/templates/photo/list.jst')])
self.assertEquals(templates, """window.JST = window.JST || {};\n%s\nwindow.JST[\'list\'] = template(\'<div class="photo">\\n <img src="<%%= src %%>" />\\n <div class="caption">\\n <%%= caption %%>\\n </div>\\n</div>\');\n""" % TEMPLATE_FUNC) self.assertEquals(templates, """window.JST = window.JST || {};\n%s\nwindow.JST[\'list\'] = template(\'<div class="photo">\\n <img src="<%%= src %%>" />\\n <div class="caption">\\n <%%= caption %%>\\n </div>\\n</div>\');\n""" % TEMPLATE_FUNC)
templates = self.compressor.compile_templates([ templates = self.compressor.compile_templates([
'pipeline/templates/video/detail.jst', _('pipeline/templates/video/detail.jst'),
'pipeline/templates/photo/detail.jst' _('pipeline/templates/photo/detail.jst')
]) ])
self.assertEqual(templates, """window.JST = window.JST || {};\n%s\nwindow.JST[\'video_detail\'] = template(\'<div class="video">\\n <video src="<%%= src %%>" />\\n <div class="caption">\\n <%%= description %%>\\n </div>\\n</div>\');\nwindow.JST[\'photo_detail\'] = template(\'<div class="photo">\\n <img src="<%%= src %%>" />\\n <div class="caption">\\n <%%= caption %%> by <%%= author %%>\\n </div>\\n</div>\');\n""" % TEMPLATE_FUNC) self.assertEqual(templates, """window.JST = window.JST || {};\n%s\nwindow.JST[\'video_detail\'] = template(\'<div class="video">\\n <video src="<%%= src %%>" />\\n <div class="caption">\\n <%%= description %%>\\n </div>\\n</div>\');\nwindow.JST[\'photo_detail\'] = template(\'<div class="photo">\\n <img src="<%%= src %%>" />\\n <div class="caption">\\n <%%= caption %%> by <%%= author %%>\\n </div>\\n</div>\');\n""" % TEMPLATE_FUNC)
def test_embeddable(self): def test_embeddable(self):
self.assertFalse(self.compressor.embeddable('pipeline/images/sprite.png', None)) self.assertFalse(self.compressor.embeddable(_('pipeline/images/sprite.png'), None))
self.assertFalse(self.compressor.embeddable('pipeline/images/arrow.png', 'datauri')) self.assertFalse(self.compressor.embeddable(_('pipeline/images/arrow.png'), 'datauri'))
self.assertTrue(self.compressor.embeddable('pipeline/images/embed/arrow.png', 'datauri')) self.assertTrue(self.compressor.embeddable(_('pipeline/images/embed/arrow.png'), 'datauri'))
self.assertFalse(self.compressor.embeddable('pipeline/images/arrow.dat', 'datauri')) self.assertFalse(self.compressor.embeddable(_('pipeline/images/arrow.dat'), 'datauri'))
def test_construct_asset_path(self): def test_construct_asset_path(self):
asset_path = self.compressor.construct_asset_path("../../images/sprite.png", asset_path = self.compressor.construct_asset_path("../../images/sprite.png",
...@@ -95,7 +97,7 @@ class CompressorTest(TestCase): ...@@ -95,7 +97,7 @@ class CompressorTest(TestCase):
def test_url_rewrite(self): def test_url_rewrite(self):
output = self.compressor.concatenate_and_rewrite([ output = self.compressor.concatenate_and_rewrite([
'pipeline/css/urls.css', _('pipeline/css/urls.css'),
], 'css/screen.css') ], 'css/screen.css')
self.assertEquals(u"""@font-face { self.assertEquals(u"""@font-face {
font-family: 'Pipeline'; font-family: 'Pipeline';
......
...@@ -2,6 +2,8 @@ from django.test import TestCase ...@@ -2,6 +2,8 @@ from django.test import TestCase
from pipeline.packager import Packager, PackageNotFound from pipeline.packager import Packager, PackageNotFound
from paths import _
class PackagerTest(TestCase): class PackagerTest(TestCase):
def test_package_for(self): def test_package_for(self):
...@@ -9,7 +11,7 @@ class PackagerTest(TestCase): ...@@ -9,7 +11,7 @@ class PackagerTest(TestCase):
packager.packages['js'] = packager.create_packages({ packager.packages['js'] = packager.create_packages({
'application': { 'application': {
'source_filenames': ( 'source_filenames': (
'pipeline/js/application.js', _('pipeline/js/application.js'),
), ),
'output_filename': 'application.js' 'output_filename': 'application.js'
} }
...@@ -29,9 +31,9 @@ class PackagerTest(TestCase): ...@@ -29,9 +31,9 @@ class PackagerTest(TestCase):
packages = packager.create_packages({ packages = packager.create_packages({
'templates': { 'templates': {
'source_filenames': ( 'source_filenames': (
'pipeline/templates/photo/list.jst', _('pipeline/templates/photo/list.jst'),
), ),
'output_filename': 'templates.js', 'output_filename': 'templates.js',
} }
}) })
self.assertEqual(packages['templates'].templates, ['pipeline/templates/photo/list.jst']) self.assertEqual(packages['templates'].templates, [_('pipeline/templates/photo/list.jst')])
import os
def _(path):
# Make sure the path contains only the correct separator
return path.replace('/', os.sep).replace('\\', os.sep)
...@@ -3,6 +3,7 @@ from django.utils.datastructures import SortedDict ...@@ -3,6 +3,7 @@ from django.utils.datastructures import SortedDict
from pipeline.conf import settings from pipeline.conf import settings
from pipeline.storage import PipelineStorage from pipeline.storage import PipelineStorage
from paths import _
class StorageTest(TestCase): class StorageTest(TestCase):
...@@ -10,8 +11,8 @@ class StorageTest(TestCase): ...@@ -10,8 +11,8 @@ class StorageTest(TestCase):
settings.PIPELINE_CSS = { settings.PIPELINE_CSS = {
'testing': { 'testing': {
'source_filenames': ( 'source_filenames': (
'pipeline/css/first.css', _('pipeline/css/first.css'),
'css/third.css', _('css/third.css'),
), ),
'manifest': False, 'manifest': False,
'output_filename': 'testing.css', 'output_filename': 'testing.css',
......
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