Stop overwriting the CompileFilter's options attribute in the __init__ method. Added optional test for the CSSTidy filter. Fixes issue #33.
This commit is contained in:
@@ -31,14 +31,15 @@ class CompilerFilter(FilterBase):
|
||||
external commands.
|
||||
"""
|
||||
command = None
|
||||
options = {}
|
||||
|
||||
def __init__(self, content, filter_type=None, verbose=0, command=None):
|
||||
def __init__(self, content, filter_type=None, verbose=0, command=None, **kwargs):
|
||||
super(CompilerFilter, self).__init__(content, filter_type, verbose)
|
||||
if command:
|
||||
self.command = command
|
||||
self.options.update(kwargs)
|
||||
if self.command is None:
|
||||
raise FilterError("Required command attribute not set")
|
||||
self.options = {}
|
||||
self.stdout = subprocess.PIPE
|
||||
self.stdin = subprocess.PIPE
|
||||
self.stderr = subprocess.PIPE
|
||||
|
||||
@@ -19,7 +19,7 @@ from compressor.conf import settings
|
||||
from compressor.css import CssCompressor
|
||||
from compressor.js import JsCompressor
|
||||
from compressor.management.commands.compress import Command as CompressCommand
|
||||
|
||||
from compressor.utils import find_command
|
||||
|
||||
class CompressorTestCase(TestCase):
|
||||
|
||||
@@ -419,3 +419,19 @@ class OfflineGenerationTestCase(TestCase):
|
||||
u'<script type="text/javascript" src="/media/CACHE/js/bf53fa5b13e2.js" charset="utf-8"></script>',
|
||||
], result)
|
||||
settings.COMPRESS_OFFLINE_CONTEXT = self._old_offline_context
|
||||
|
||||
|
||||
if find_command(settings.COMPRESS_CSSTIDY_BINARY):
|
||||
|
||||
class CssTidyTestCase(TestCase):
|
||||
|
||||
def test_tidy(self):
|
||||
content = """
|
||||
/* Some comment */
|
||||
font,th,td,p{
|
||||
color: black;
|
||||
}
|
||||
"""
|
||||
from compressor.filters.csstidy import CSSTidyFilter
|
||||
self.assertEqual(
|
||||
"font,th,td,p{color:#000;}", CSSTidyFilter(content).output())
|
||||
|
||||
@@ -57,3 +57,32 @@ def walk(root, topdown=True, onerror=None, followlinks=False):
|
||||
if os.path.islink(p):
|
||||
for link_dirpath, link_dirnames, link_filenames in walk(p):
|
||||
yield (link_dirpath, link_dirnames, link_filenames)
|
||||
|
||||
|
||||
def find_command(cmd, paths=None, pathext=None):
|
||||
"""
|
||||
Searches the PATH for the given command and returns its path
|
||||
"""
|
||||
if paths is None:
|
||||
paths = os.environ.get('PATH', []).split(os.pathsep)
|
||||
if isinstance(paths, basestring):
|
||||
paths = [paths]
|
||||
# check if there are funny path extensions for executables, e.g. Windows
|
||||
if pathext is None:
|
||||
pathext = os.environ.get('PATHEXT', '.COM;.EXE;.BAT;.CMD')
|
||||
pathext = [ext for ext in pathext.lower().split(os.pathsep)]
|
||||
# don't use extensions if the command ends with one of them
|
||||
if os.path.splitext(cmd)[1].lower() in pathext:
|
||||
pathext = ['']
|
||||
# check if we find the command on PATH
|
||||
for path in paths:
|
||||
# try without extension first
|
||||
cmd_path = os.path.join(path, cmd)
|
||||
for ext in pathext:
|
||||
# then including the extension
|
||||
cmd_path_ext = cmd_path + ext
|
||||
if os.path.isfile(cmd_path_ext):
|
||||
return cmd_path_ext
|
||||
if os.path.isfile(cmd_path):
|
||||
return cmd_path
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user