PageRenderTime 14ms CodeModel.GetById 1ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

/hyde/tests/test_simple_copy.py

http://github.com/hyde/hyde
Python | 139 lines | 107 code | 13 blank | 19 comment | 2 complexity | 1bf3f282858686f380541365e855831a MD5 | raw file
  1# -*- coding: utf-8 -*-
  2"""
  3Tests the simple copy feature.
  4
  5In order to mark some files to simply be copied to the
  6destination without any processing what so ever add this
  7to the config (site.yaml for example):
  8simple_copy:
  9    - media/css/*.css
 10    - media/js/*.js
 11    - **/*.js
 12
 13Matching is done with `fnmatch` module. So any `glob` that fnmatch
 14can process is a valid pattern.
 15
 16Use nose
 17`$ pip install nose`
 18`$ nosetests`
 19"""
 20import yaml
 21
 22from hyde.model import Config
 23from hyde.site import Site
 24from hyde.generator import Generator
 25
 26from fswrap import File
 27from nose.tools import nottest
 28
 29
 30TEST_SITE_ROOT = File(__file__).parent.child_folder('sites/test_jinja')
 31
 32class TestSimpleCopy(object):
 33    @classmethod
 34    def setup_class(cls):
 35        cls.SITE_PATH =  File(__file__).parent.child_folder('sites/test_jinja_with_config')
 36        cls.SITE_PATH.make()
 37        TEST_SITE_ROOT.copy_contents_to(cls.SITE_PATH)
 38
 39    @classmethod
 40    def teardown_class(cls):
 41        cls.SITE_PATH.delete()
 42
 43    @nottest
 44    def setup_config(self, passthru):
 45        self.config_file = File(self.SITE_PATH.child('site.yaml'))
 46        with open(self.config_file.path) as config:
 47            conf = yaml.load(config)
 48            conf['simple_copy'] = passthru
 49            self.config = Config(sitepath=self.SITE_PATH, config_dict=conf)
 50
 51    def test_simple_copy_basic(self):
 52        self.setup_config([
 53            'about.html'
 54        ])
 55        s = Site(self.SITE_PATH, config=self.config)
 56        s.load()
 57        res = s.content.resource_from_relative_path('about.html')
 58        assert res
 59        assert res.simple_copy
 60
 61    def test_simple_copy_directory(self):
 62        self.setup_config([
 63            '**/*.html'
 64        ])
 65        s = Site(self.SITE_PATH, config=self.config)
 66        s.load()
 67        res = s.content.resource_from_relative_path('about.html')
 68        assert res
 69        assert not res.simple_copy
 70        res = s.content.resource_from_relative_path('blog/2010/december/merry-christmas.html')
 71        assert res
 72        assert res.simple_copy
 73
 74    def test_simple_copy_multiple(self):
 75        self.setup_config([
 76            '**/*.html',
 77            'media/css/*.css'
 78        ])
 79        s = Site(self.SITE_PATH, config=self.config)
 80        s.load()
 81        res = s.content.resource_from_relative_path('about.html')
 82        assert res
 83        assert not res.simple_copy
 84        res = s.content.resource_from_relative_path('blog/2010/december/merry-christmas.html')
 85        assert res
 86        assert res.simple_copy
 87        res = s.content.resource_from_relative_path('media/css/site.css')
 88        assert res
 89        assert res.simple_copy
 90
 91    def test_generator(self):
 92        self.setup_config([
 93            '**/*.html',
 94            'media/css/*.css'
 95        ])
 96        s = Site(self.SITE_PATH, self.config)
 97        g = Generator(s)
 98        g.generate_all()
 99        source = s.content.resource_from_relative_path('blog/2010/december/merry-christmas.html')
100        target = File(s.config.deploy_root_path.child(source.relative_deploy_path))
101        left = source.source_file.read_all()
102        right = target.read_all()
103        assert left == right
104
105    def test_plugins(self):
106
107        text = """
108---
109title: Hey
110author: Me
111twitter: @me
112---
113{%% extends "base.html" %%}
114
115{%% block main %%}
116    Hi!
117
118    I am a test template to make sure jinja2 generation works well with hyde.
119    <span class="title">{{resource.meta.title}}</span>
120    <span class="author">{{resource.meta.author}}</span>
121    <span class="twitter">{{resource.meta.twitter}}</span>
122{%% endblock %%}
123"""
124        index = File(self.SITE_PATH.child('content/blog/index.html'))
125        index.write(text)
126        self.setup_config([
127            '**/*.html',
128            'media/css/*.css'
129        ])
130        conf = {'plugins': ['hyde.ext.plugins.meta.MetaPlugin']}
131        conf.update(self.config.to_dict())
132        s = Site(self.SITE_PATH, Config(sitepath=self.SITE_PATH, config_dict=conf))
133        g = Generator(s)
134        g.generate_all()
135        source = s.content.resource_from_relative_path('blog/index.html')
136        target = File(s.config.deploy_root_path.child(source.relative_deploy_path))
137        left = source.source_file.read_all()
138        right = target.read_all()
139        assert left == right