#!/usr/bin/env python
#
# $Id: test_templatefile.py,v 1.3 2006/12/05 13:10:45 doughellmann Exp $
#
# Copyright 2003 Doug Hellmann.
#
#
# All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose and without fee is hereby
# granted, provided that the above copyright notice appear in all
# copies and that both that copyright notice and this permission
# notice appear in supporting documentation, and that the name of Doug
# Hellmann not be used in advertising or publicity pertaining to
# distribution of the software without specific, written prior
# permission.
#
# DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
# NO EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
"""Basic tests for templatefile module for HappyDoc.
"""
__rcs_info__ = {
#
# Creation Information
#
'module_name' : '$RCSfile: test_templatefile.py,v $',
'rcs_id' : '$Id: test_templatefile.py,v 1.3 2006/12/05 13:10:45 doughellmann Exp $',
'creator' : 'Doug Hellmann',
'project' : 'HappyDoc',
'created' : 'Sun, 26-Jan-2003 13:04:06 EST',
#
# Current Information
#
'author' : '$Author: doughellmann $',
'version' : '$Revision: 1.3 $',
'date' : '$Date: 2006/12/05 13:10:45 $',
}
try:
__version__ = __rcs_info__['version'].split(' ')[1]
except:
__version__ = '0.0'
#
# Import system modules
#
import os
import unittest
#
# Import Local modules
#
from happydoclib.docset.docset_TAL.templatefile import TemplateFile
#
# Module
#
class Here:
Athens = '<p>YOU GOT ATHENS</p>'
Atlanta = 'YOU GOT <b>ATLANTA</b>'
def __init__(self, name):
self.name = name
self.dict = { 'foo':'foo'}
return
def callMe(self):
return '%s was called' % self.name
def __getitem__(self, key):
return '%s-%s' % (self.name, self.dict[key])
class TemplateFileTestCase(unittest.TestCase):
PROCTOR_TEST_CATEGORIES = ( 'docset',
'TAL',
)
def runOneTest(self, hereName, templateFileName, macroFileNames, expectedResults):
template = TemplateFile(templateFileName)
macro_files = {}
for macro_filename in macroFileNames:
macro_file_basename = os.path.basename(macro_filename)
m = TemplateFile(macro_filename)
macro_files[macro_file_basename] = m
actual_value = template.render(
extraContext={'templates':macro_files,
'here':Here(hereName),
},
)
self.failUnlessEqual(actual_value, expectedResults)
return
default_expected_value = '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<title>Override title</title>
This is the head_slot part of the header.
</head>
<body>
<div>
<table border="0" cellpadding="5" cellspacing="5">
<tr>
<td>
<a href="http://my.weather.com/weather/map/30605?name=index_large&day=1" target="_blank">
<img border="0" src="http://image.weather.com/web/radar/us_atl_closeradar_small_usen.jpg">
</a>
</td>
</tr>
<tr>
<td>
<a href="http://www.weather.com/weather/local/30605" target="_blank">
<img border="1" width="270" height="140" src="http://oap.weather.com/fcgi-bin/oap/generate_magnet?loc_id=USGA0027&code=482224"></a>
</td>
</tr>
</table>
<h2>Call Me</h2>
<div>%(here_name)s was called</div>
<div>
<span>bar</span>
</div>
<div>
<span>bar as python string</span>
</div>
<ul>
<li>
<p>foo</p>
</li>
<li>
<p>bar</p>
</li>
<li>
<p>blah</p>
</li>
<li>
<p>bletch</p>
</li>
</ul>
<span>Should see this.</span>
<h2>Athens, Structure</h2>
<div><p>YOU GOT ATHENS</p></div>
<h2>Atlanta, Structure</h2>
<div>YOU GOT <b>ATLANTA</b></div>
<h2>Athens, No Structure</h2>
<div><p>YOU GOT ATHENS</p></div>
<h2>Atlanta, No Structure</h2>
<div>YOU GOT <b>ATLANTA</b></div>
<span>%(here_name)s</span>
<span>%(here_name)s-foo</span>
<span>YOU ARE HERE</span>
<span>YOU ARE HERE (function)</span>
<span>YOU ARE HERE (function)</span>
</div>
</body>
</html>
'''
def testOne(self):
here_name = 'one'
expected_value = self.default_expected_value % locals()
self.runOneTest( 'one',
'TestCases/TAL/testtal.pt',
('TestCases/TAL/header.pt',
),
expected_value,
)
return
def testTwo(self):
here_name = 'two'
expected_value = self.default_expected_value % locals()
self.runOneTest( 'two',
'TestCases/TAL/testtal.pt',
('TestCases/TAL/header.pt',
),
expected_value,
)
return
|