Commits

Jan-Jaap Driessen  committed 57d87d1

Test for proper compilation / minfication of Resources. Pass mode to compiler in order to do proper check whether we need to compile.

  • Participants
  • Parent commits 2db81fe
  • Branches compilers-n-minifiers2

Comments (0)

Files changed (3)

File fanstatic/minifier.py

 class Minifier(Processor):
 
     @classmethod
-    def target_path(cls, path):
+    def target_path(cls, path, mode=None):
         """
         Return the target path of the minifier result.
         """

File fanstatic/processor.py

         return True
 
     @classmethod
-    def target_path(cls, path):
+    def target_path(cls, path, mode=None):
         """
         Return the target path of the processor result.
         """
         raise NotImplementedError
 
     @classmethod
-    def should_process(cls, path):
+    def should_process(cls, path, mode=None):
         """
         Determine whether to process the resource based on the mtime of the target
         and source.
         """
-        target = cls.target_path(path)
+        target = cls.target_path(path, mode=mode)
         return not os.path.isfile(target) or mtime(path) > mtime(target)
 
     @classmethod
     def process(cls, path, mode=None, force=False):
-        if force or cls.should_process(path):
+        if force or cls.should_process(path, mode=mode):
             cls.__call__(path, mode=mode)
 
     @classmethod

File fanstatic/test_core.py

         @classmethod
         def __call__(cls, path, mode=None):
             # Make mode a part of the compilation:
-            mode = {DEBUG: 'ddeebbuugg', MINIFIED: 'mmiinniiffiieedd'}.get(mode, '')
-            open(cls.target_path(path), 'wb').write('#  compile   %s  :' % mode + open(path).read())
+            mode_ = {DEBUG: 'ddeebbuugg', MINIFIED: 'mmiinniiffiieedd'}.get(mode, '')
+            open(cls.target_path(path, mode=mode), 'wb').write('#  compile  %s  :' % mode_ + open(path).read())
 
-    class Mini(Minifier):
-
-        @classmethod
-        def __call__(cls, path):
-            input = open(path).read()
-            while '  ' in input:
-                input = input.replace('  ', ' ')
-            open(cls.target_path(path), 'w').write(input.strip())
-
-    tmpdir.join('r1.comp').ensure()
+    tmpdir.join('r1.comp').write('frop')
     r1 = Resource(foo, 'r1.comp', compiler=Comp)
 
     needed = NeededResources(resources=[r1])
     assert needed.render() == '''\
 <script type="text/javascript" src="/fanstatic/foo/r1.js"></script>'''
+    assert tmpdir.join('r1.js').read() == '''\
+#  compile    :frop'''
 
     needed_minified = NeededResources(resources=[r1], minified=True)
     assert needed_minified.render() == '''\
 <script type="text/javascript" src="/fanstatic/foo/r1-min.js"></script>'''
+    assert tmpdir.join('r1-min.js').read() == '''\
+#  compile  mmiinniiffiieedd  :frop'''
 
     needed_debug = NeededResources(resources=[r1], debug=True)
     assert needed_debug.render() == '''\
 <script type="text/javascript" src="/fanstatic/foo/r1-debug.js"></script>'''
-
+    assert tmpdir.join('r1-debug.js').read() == '''\
+#  compile  ddeebbuugg  :frop'''