Commit cd14104f by Timothée Peignier

Improve tests

parent b68d46e7
......@@ -2,14 +2,17 @@
from __future__ import unicode_literals
import base64
import os
import io
import os
import sys
try:
from mock import patch
except ImportError:
from unittest.mock import patch # noqa
from unittest import skipIf
from django.test import TestCase
from pipeline.compressors import Compressor, TEMPLATE_FUNC, \
......@@ -74,32 +77,32 @@ class CompressorTest(TestCase):
self.assertEqual(base_path, _('js/templates'))
def test_absolute_path(self):
absolute_path = self.compressor.absolute_path('../../images/sprite.png',
'css/plugins/')
absolute_path = self.compressor.absolute_path(
'../../images/sprite.png', 'css/plugins/')
self.assertEqual(absolute_path, 'images/sprite.png')
absolute_path = self.compressor.absolute_path('/images/sprite.png',
'css/plugins/')
absolute_path = self.compressor.absolute_path(
'/images/sprite.png', 'css/plugins/')
self.assertEqual(absolute_path, '/images/sprite.png')
def test_template_name(self):
name = self.compressor.template_name('templates/photo/detail.jst',
'templates/')
name = self.compressor.template_name(
'templates/photo/detail.jst', 'templates/')
self.assertEqual(name, 'photo_detail')
name = self.compressor.template_name('templates/photo_edit.jst', '')
self.assertEqual(name, 'photo_edit')
name = self.compressor.template_name('templates\photo\detail.jst',
'templates\\')
name = self.compressor.template_name(
'templates\photo\detail.jst', 'templates\\')
self.assertEqual(name, 'photo_detail')
@pipeline_settings(TEMPLATE_SEPARATOR='/')
def test_template_name_separator(self):
name = self.compressor.template_name('templates/photo/detail.jst',
'templates/')
name = self.compressor.template_name(
'templates/photo/detail.jst', 'templates/')
self.assertEqual(name, 'photo/detail')
name = self.compressor.template_name('templates/photo_edit.jst', '')
self.assertEqual(name, 'photo_edit')
name = self.compressor.template_name('templates\photo\detail.jst',
'templates\\')
name = self.compressor.template_name(
'templates\photo\detail.jst', 'templates\\')
self.assertEqual(name, 'photo/detail')
def test_compile_templates(self):
......@@ -118,11 +121,11 @@ class CompressorTest(TestCase):
self.assertFalse(self.compressor.embeddable(_('pipeline/images/arrow.dat'), 'datauri'))
def test_construct_asset_path(self):
asset_path = self.compressor.construct_asset_path("../../images/sprite.png",
"css/plugins/gallery.css", "css/gallery.css")
asset_path = self.compressor.construct_asset_path(
"../../images/sprite.png", "css/plugins/gallery.css", "css/gallery.css")
self.assertEqual(asset_path, "../images/sprite.png")
asset_path = self.compressor.construct_asset_path("/images/sprite.png",
"css/plugins/gallery.css", "css/gallery.css")
asset_path = self.compressor.construct_asset_path(
"/images/sprite.png", "css/plugins/gallery.css", "css/gallery.css")
self.assertEqual(asset_path, "/images/sprite.png")
def test_url_rewrite(self):
......@@ -170,6 +173,7 @@ class CompressorTest(TestCase):
}
""", output)
@skipIf(sys.platform.startswith("win"), "requires posix platform")
def test_compressor_subprocess_unicode(self):
path = os.path.dirname(os.path.dirname(__file__))
content = io.open(path + '/assets/css/unicode.css', encoding="utf-8").read()
......
......@@ -52,48 +52,47 @@ class GlobTest(TestCase):
glob.staticfiles_storage = self.old_storage
def test_glob_literal(self):
self.assertSequenceEqual(self.glob('a'),
[self.normpath('a')])
self.assertSequenceEqual(self.glob('a', 'D'),
[self.normpath('a', 'D')])
self.assertSequenceEqual(self.glob('aab'),
[self.normpath('aab')])
self.assertSequenceEqual(self.glob('a'), [self.normpath('a')])
self.assertSequenceEqual(self.glob('a', 'D'), [self.normpath('a', 'D')])
self.assertSequenceEqual(self.glob('aab'), [self.normpath('aab')])
self.assertSequenceEqual(self.glob('zymurgy'), [])
def test_glob_one_directory(self):
self.assertSequenceEqual(self.glob('a*'),
map(self.normpath, ['a', 'aab', 'aaa']))
self.assertSequenceEqual(self.glob('*a'),
map(self.normpath, ['a', 'aaa']))
self.assertSequenceEqual(self.glob('aa?'),
map(self.normpath, ['aaa', 'aab']))
self.assertSequenceEqual(self.glob('aa[ab]'),
map(self.normpath, ['aaa', 'aab']))
self.assertSequenceEqual(
self.glob('a*'), map(self.normpath, ['a', 'aab', 'aaa']))
self.assertSequenceEqual(
self.glob('*a'), map(self.normpath, ['a', 'aaa']))
self.assertSequenceEqual(
self.glob('aa?'), map(self.normpath, ['aaa', 'aab']))
self.assertSequenceEqual(
self.glob('aa[ab]'), map(self.normpath, ['aaa', 'aab']))
self.assertSequenceEqual(self.glob('*q'), [])
def test_glob_nested_directory(self):
if os.path.normcase("abCD") == "abCD":
# case-sensitive filesystem
self.assertSequenceEqual(self.glob('a', 'bcd', 'E*'),
[self.normpath('a', 'bcd', 'EF')])
self.assertSequenceEqual(
self.glob('a', 'bcd', 'E*'), [self.normpath('a', 'bcd', 'EF')])
else:
# case insensitive filesystem
self.assertSequenceEqual(self.glob('a', 'bcd', 'E*'), [
self.normpath('a', 'bcd', 'EF'),
self.normpath('a', 'bcd', 'efg')
])
self.assertSequenceEqual(self.glob('a', 'bcd', '*g'),
[self.normpath('a', 'bcd', 'efg')])
self.assertSequenceEqual(
self.glob('a', 'bcd', '*g'), [self.normpath('a', 'bcd', 'efg')])
def test_glob_directory_names(self):
self.assertSequenceEqual(self.glob('*', 'D'),
[self.normpath('a', 'D')])
self.assertSequenceEqual(
self.glob('*', 'D'), [self.normpath('a', 'D')])
self.assertSequenceEqual(self.glob('*', '*a'), [])
self.assertSequenceEqual(self.glob('a', '*', '*', '*a'),
[self.normpath('a', 'bcd', 'efg', 'ha')])
self.assertSequenceEqual(self.glob('?a?', '*F'),
self.assertSequenceEqual(
self.glob('a', '*', '*', '*a'),
[self.normpath('a', 'bcd', 'efg', 'ha')])
self.assertSequenceEqual(
self.glob('?a?', '*F'),
map(self.normpath, [os.path.join('aaa', 'zzzF'),
os.path.join('aab', 'F')]))
os.path.join('aab', 'F')]))
def test_glob_directory_with_trailing_slash(self):
# We are verifying that when there is wildcard pattern which
......
......@@ -14,7 +14,7 @@ from tests.utils import pipeline_settings
class JinjaTest(TestCase):
def setUp(self):
self.env = Environment(extensions=[PipelineExtension],
loader=PackageLoader('pipeline', 'templates'))
loader=PackageLoader('pipeline', 'templates'))
def test_no_package(self):
template = self.env.from_string(u"""{% stylesheet "unknow" %}""")
......
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