Commits

Jan-Jaap Driessen committed d9be9bc

Move test from core to compiler.

Comments (0)

Files changed (1)

fanstatic/test_compiler.py

     assert mtime1 != os.path.getmtime(target_path)
 
 
+def test_minified_for_compile_resource(tmpdir):
+    foo = Library('foo', str(tmpdir), devmode=True)
+
+    class Comp(Compiler):
+        target_extension = 'js'
+
+        minified = True
+        debug = True
+
+        @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, mode=mode), 'wb').write('#  compile  %s  :' % mode_ + open(path).read())
+
+    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'''
+
+
 def test_compiler_bundle_interaction(tmpdir, monkeypatch):
     class Foo(Compiler):
         source_extension = 'foo'