PageRenderTime 28ms CodeModel.GetById 14ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/hyde/tests/ext/test_optipng.py

http://github.com/hyde/hyde
Python | 41 lines | 27 code | 8 blank | 6 comment | 0 complexity | 8796900790134c9df5f72a024171e44b MD5 | raw file
 1# -*- coding: utf-8 -*-
 2"""
 3Use nose
 4`$ pip install nose`
 5`$ nosetests`
 6"""
 7from hyde.model import Expando
 8from hyde.generator import Generator
 9from hyde.site import Site
10
11from fswrap import File, Folder
12
13OPTIPNG_SOURCE = File(__file__).parent.child_folder('optipng')
14TEST_SITE = File(__file__).parent.parent.child_folder('_test')
15
16
17class TestOptipng(object):
18
19    def setUp(self):
20        TEST_SITE.make()
21        TEST_SITE.parent.child_folder(
22                    'sites/test_jinja').copy_contents_to(TEST_SITE)
23        IMAGES = TEST_SITE.child_folder('content/media/images')
24        IMAGES.make()
25        OPTIPNG_SOURCE.copy_contents_to(IMAGES)
26
27
28    def tearDown(self):
29        TEST_SITE.delete()
30
31    def test_can_execute_optipng(self):
32        s = Site(TEST_SITE)
33        s.config.mode = "production"
34        s.config.plugins = ['hyde.ext.plugins.images.OptiPNGPlugin']
35        s.config.optipng = Expando(dict(args=dict(quiet="")))
36        source =File(TEST_SITE.child('content/media/images/hyde-lt-b.png'))
37        target = File(Folder(s.config.deploy_root_path).child('media/images/hyde-lt-b.png'))
38        gen = Generator(s)
39        gen.generate_resource_at_path(source)
40        assert target.exists
41        assert target.size < source.size