"""Unit Tests for the template matching."""
__revision__ = "$Rev: 455 $"
__author__ = "David Stanek "
__copyright__ = "Copyright 2005, David Stanek"
from os.path import join as joinpath
from tempfile import mkdtemp
from shutil import rmtree
import kid
def setup_module(module):
global tmpdir
tmpdir = mkdtemp(prefix='kid_test_match_')
kid.path.insert(tmpdir)
def teardown_module(module):
kid.path.remove(tmpdir)
rmtree(tmpdir)
def test_match0():
open(joinpath(tmpdir, "match0_base.kid"), 'w').write("""\
Your title goes here
""")
open(joinpath(tmpdir, "match0_page.kid"), 'w').write("""\
Welcome to TurboGears
My Main page with bold text
""")
html = kid.Template(file="match0_page.kid").serialize()
assert 'Welcome to TurboGears' in html
assert 'BOLD' in html
def test_match1():
open(joinpath(tmpdir, "match1_base.kid"), 'w').write("""\
Some title here
Real content would go here.
""")
open(joinpath(tmpdir, "match1_page.kid"), 'w').write("""\
This is a test link,
or an e-mail address.
""")
html = kid.Template(file="match1_page.kid").serialize()
assert '' in html
assert '' \
'test link' in html
assert '' \
'e-mail address' in html
assert '' in html
assert 'Real content would go here.
' not in html
def test_match_2():
"""Test for a know bad case in the apply_matches function (ticket # 142)."""
open(joinpath(tmpdir, "match2_master.kid"), 'w').write("""\
""")
open(joinpath(tmpdir, "match2_userform.kid"), 'w').write("""\
""")
extends = ('master', 'userform')
for i in range(2):
file = "match2_%s_%s.kid" % extends
open(joinpath(tmpdir, file), 'w').write("""\
""" % extends)
t = kid.Template(file=file)
t.action = file
html = t.serialize()
assert 'THIS IS THE TAG' in html # text from main template
assert 'MASTER MATCH' in html # text from master template
assert 'seasources:userform' not in html # text from userform template
extends = list(extends)
extends.reverse()
extends = tuple(extends)
def test_match_3():
"""Check for an issue with additional blank lines (ticket #131)."""
template = """\
one
hello world!
two
"""
t = kid.Template(source=template)
rslt = t.serialize(output="html")
expect = """
one
two
"""
print rslt
print expect
assert rslt.endswith(expect)