Browse Source

Add tests for combine plugin.

main
Vincent Bernat 13 years ago
parent
commit
12efa56ce2
4 changed files with 85 additions and 0 deletions
  1. +1
    -0
      hyde/tests/ext/combine/script.1.js
  2. +1
    -0
      hyde/tests/ext/combine/script.2.js
  3. +1
    -0
      hyde/tests/ext/combine/script.3.js
  4. +82
    -0
      hyde/tests/ext/test_combine.py

+ 1
- 0
hyde/tests/ext/combine/script.1.js View File

@@ -0,0 +1 @@
var a = 1 + 2;

+ 1
- 0
hyde/tests/ext/combine/script.2.js View File

@@ -0,0 +1 @@
var b = a + 3;

+ 1
- 0
hyde/tests/ext/combine/script.3.js View File

@@ -0,0 +1 @@
var c = a + 5;

+ 82
- 0
hyde/tests/ext/test_combine.py View File

@@ -0,0 +1,82 @@
# -*- coding: utf-8 -*-
"""
Use nose
`$ pip install nose`
`$ nosetests`
"""
from hyde.fs import File, Folder
from hyde.model import Expando
from hyde.generator import Generator
from hyde.site import Site

COMBINE_SOURCE = File(__file__).parent.child_folder('combine')
TEST_SITE = File(__file__).parent.parent.child_folder('_test')


class TestCombine(object):

def setUp(self):
TEST_SITE.make()
TEST_SITE.parent.child_folder(
'sites/test_jinja').copy_contents_to(TEST_SITE)
TEST_SITE.child_folder('content/media/js').make()
COMBINE_SOURCE.copy_contents_to(TEST_SITE.child('content/media/js'))

def tearDown(self):
TEST_SITE.delete()

def _test_combine(self, content):
s = Site(TEST_SITE)
s.config.plugins = [
'hyde.ext.plugins.meta.MetaPlugin',
'hyde.ext.plugins.combine.CombinePlugin']
source = TEST_SITE.child('content/media/js/script.js')
target = File(Folder(s.config.deploy_root_path).child('media/js/script.js'))
File(source).write(content)

gen = Generator(s)
gen.generate_resource_at_path(source)

assert target.exists
text = target.read_all()
return text, s

def test_combine_top(self):
text, _ = self._test_combine("""
---
combine:
files: script.*.js
where: top
---

Last line""")
assert len(text.split("\n")) == 4
assert text.split("\n")[-1] == "Last line"
return

def test_combine_bottom(self):
text, _ = self._test_combine("""
---
combine:
files: script.*.js
where: bottom
---

First line
""")
assert len(text.split("\n")) == 4
assert text.split("\n")[0] == "First line"
return

def test_combine_remove(self):
_, s = self._test_combine("""
---
combine:
files: script.*.js
remove: yes
---

First line""")
for i in range(1,4):
assert not File(Folder(s.config.deploy_root_path).
child('media/js/script.%d.js' % i)).exists

Loading…
Cancel
Save