#!/usr/bin/env python # # $Id: test_templatefile.py,v 1.2 2003/03/16 16:29:14 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.2 2003/03/16 16:29:14 doughellmann Exp $', 'creator' : 'Doug Hellmann ', 'project' : 'HappyDoc', 'created' : 'Sun, 26-Jan-2003 13:04:06 EST', # # Current Information # 'author' : '$Author: doughellmann $', 'version' : '$Revision: 1.2 $', 'date' : '$Date: 2003/03/16 16:29:14 $', } 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 = '

YOU GOT ATHENS

' Atlanta = 'YOU GOT ATLANTA' 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 = ''' Override title This is the head_slot part of the header.

Call Me

%(here_name)s was called
bar
bar as python string
Should see this.

Athens, Structure

YOU GOT ATHENS

Atlanta, Structure

YOU GOT ATLANTA

Athens, No Structure

<p>YOU GOT ATHENS</p>

Atlanta, No Structure

YOU GOT <b>ATLANTA</b>
%(here_name)s %(here_name)s-foo YOU ARE HERE YOU ARE HERE (function) YOU ARE HERE (function)
''' 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