PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/hyde/tests/ext/test_uglify.py

http://github.com/hyde/hyde
Python | 78 lines | 54 code | 15 blank | 9 comment | 0 complexity | 96c1468d2730e6019495e5de8b28f692 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
12from hyde.tests.util import assert_no_diff
13
14UGLIFY_SOURCE = File(__file__).parent.child_folder('uglify')
15TEST_SITE = File(__file__).parent.parent.child_folder('_test')
16
17
18class TestUglify(object):
19
20    def setUp(self):
21        TEST_SITE.make()
22        TEST_SITE.parent.child_folder(
23                    'sites/test_jinja').copy_contents_to(TEST_SITE)
24        JS = TEST_SITE.child_folder('content/media/js')
25        JS.make()
26        UGLIFY_SOURCE.copy_contents_to(JS)
27
28
29    def tearDown(self):
30        TEST_SITE.delete()
31
32    def test_can_uglify(self):
33        s = Site(TEST_SITE)
34        s.config.plugins = ['hyde.ext.plugins.js.UglifyPlugin']
35        s.config.mode = "production"
36        source = TEST_SITE.child('content/media/js/jquery.js')
37        target = File(Folder(s.config.deploy_root_path).child('media/js/jquery.js'))
38        gen = Generator(s)
39        gen.generate_resource_at_path(source)
40
41        assert target.exists
42        expected = UGLIFY_SOURCE.child_file('expected-jquery.js').read_all()
43        # TODO: Very fragile. Better comparison needed.
44        text = target.read_all()
45        assert_no_diff(expected, text)
46
47    def test_uglify_with_extra_options(self):
48        s = Site(TEST_SITE)
49        s.config.plugins = ['hyde.ext.plugins.js.UglifyPlugin']
50        s.config.mode = "production"
51        s.config.uglify = Expando(dict(args={"comments":"/http\:\/\/jquery.org\/license/"}))
52        source = TEST_SITE.child('content/media/js/jquery.js')
53        target = File(Folder(s.config.deploy_root_path).child('media/js/jquery.js'))
54        gen = Generator(s)
55        gen.generate_resource_at_path(source)
56
57        assert target.exists
58        expected = UGLIFY_SOURCE.child_file('expected-jquery-nc.js').read_all()
59        # TODO: Very fragile. Better comparison needed.
60        text = target.read_all()
61        assert_no_diff(expected, text)
62
63    def test_no_uglify_in_dev_mode(self):
64        s = Site(TEST_SITE)
65        s.config.plugins = ['hyde.ext.plugins.js.UglifyPlugin']
66        s.config.mode = "dev"
67        source = TEST_SITE.child('content/media/js/jquery.js')
68        target = File(Folder(s.config.deploy_root_path).child('media/js/jquery.js'))
69        gen = Generator(s)
70        gen.generate_resource_at_path(source)
71
72        assert target.exists
73        expected = UGLIFY_SOURCE.child_file('jquery.js').read_all()
74        # TODO: Very fragile. Better comparison needed.
75        text = target.read_all()
76        assert_no_diff(expected, text)
77
78