"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "Cheetah/Tests/SyntaxAndOutput.py" between
cheetah3-3.1.0.tar.gz and cheetah3-3.2.0.tar.gz

About: Cheetah3 is a template engine and code generation tool for e.g. for Web development or Java, SQL, LaTeX, form email ... (written in Python).

SyntaxAndOutput.py  (cheetah3-3.1.0):SyntaxAndOutput.py  (cheetah3-3.2.0)
skipping to change at line 96 skipping to change at line 96
'strip3': ' \t strippable whitespace \t\t\n1 2 3\n', 'strip3': ' \t strippable whitespace \t\t\n1 2 3\n',
'blockToBeParsed': """$numOne $numTwo""", 'blockToBeParsed': """$numOne $numTwo""",
'includeBlock2': """$numOne $numTwo $aSetVar""", 'includeBlock2': """$numOne $numTwo $aSetVar""",
'includeFileName': 'parseTest.txt', 'includeFileName': 'parseTest.txt',
'listOfLambdas': [lambda x: x, lambda x: x, lambda x: x], 'listOfLambdas': [lambda x: x, lambda x: x, lambda x: x],
'list': [ 'list': [
{'index': 0, 'numOne': 1, 'numTwo': 2}, {'index': 0, 'numOne': 1, 'numTwo': 2},
{'index': 1, 'numOne': 1, 'numTwo': 2}, {'index': 1, 'numOne': 1, 'numTwo': 2},
], ],
'nameList': [('john', 'doe'), ('jane', 'smith')], 'nameList': [('john', 'doe'), ('jane', 'smith')],
'letterList': ['a', 'b', 'c'], 'letterList': ['a', 'b', 'c'],
'_': lambda x: 'Translated: ' + x, '_': lambda x: 'Translated: ' + x,
'unicodeData': u'aoeu12345\u1234', 'unicodeData': u'aoeu12345\u1234',
} }
################################################## ##################################################
# TEST BASE CLASSES # TEST BASE CLASSES
class OutputTest(unittest.TestCase): class OutputTest(unittest.TestCase):
report = ''' report = '''
Template output mismatch: Template output mismatch:
Input Template = Input Template =
%(template)s%(end)s %(template)s%(end)s
skipping to change at line 155 skipping to change at line 155
self._input = input self._input = input
if self._useNewStyleCompilation: if self._useNewStyleCompilation:
extraKwArgs = self._extraCompileKwArgs or {} extraKwArgs = self._extraCompileKwArgs or {}
templateClass = Template.compile( templateClass = Template.compile(
source=input, source=input,
compilerSettings=self._getCompilerSettings(), compilerSettings=self._getCompilerSettings(),
keepRefToGeneratedCode=True, keepRefToGeneratedCode=True,
**extraKwArgs **extraKwArgs
) )
moduleCode = templateClass._CHEETAH_generatedModuleCode moduleCode = templateClass._CHEETAH_generatedModuleCode
searchList = self.searchList() or self._searchList searchList = self.searchList() or self._searchList
self.template = templateObj = templateClass(searchList=searchList) self.template = templateObj = templateClass(searchList=searchList)
else: else:
self.template = templateObj = Template( self.template = templateObj = Template(
input, input,
searchList=self.searchList(), searchList=self.searchList(),
compilerSettings=self._getCompilerSettings(), compilerSettings=self._getCompilerSettings(),
) )
moduleCode = templateObj._CHEETAH_generatedModuleCode moduleCode = templateObj._CHEETAH_generatedModuleCode
if self.DEBUGLEV >= 1: if self.DEBUGLEV >= 1:
print("Module: %s" % templateObj.__module__) print("Module: %s" % templateObj.__module__)
print( print(
moduleCode.encode('ascii', 'backslashreplace').decode('ascii')) moduleCode.encode('ascii', 'backslashreplace').decode('ascii'))
try: try:
# rather than __str__, because of unicode # rather than __str__, because of unicode
output = templateObj.respond() output = templateObj.respond()
assert output == expectedOutput, \ assert output == expectedOutput, \
self._outputMismatchReport(output, expectedOutput) self._outputMismatchReport(output, expectedOutput)
skipping to change at line 620 skipping to change at line 620
def test21(self): def test21(self):
"""Make sure that $*caching is actually working""" """Make sure that $*caching is actually working"""
namesStr = 'You Me Them Everyone' namesStr = 'You Me Them Everyone'
names = namesStr.split() names = namesStr.split()
tmpl = Template.compile('#for name in $names: $name ', baseclass=dict) tmpl = Template.compile('#for name in $names: $name ', baseclass=dict)
assert str(tmpl({'names': names})).strip() == namesStr assert str(tmpl({'names': names})).strip() == namesStr
tmpl = tmpl.subclass('#for name in $names: $*name ') tmpl = tmpl.subclass('#for name in $names: $*name ')
assert str(tmpl({'names': names})) == 'You '*len(names) assert str(tmpl({'names': names})) == 'You ' * len(names)
tmpl = tmpl.subclass('#for name in $names: $*1*name ') tmpl = tmpl.subclass('#for name in $names: $*1*name ')
assert str(tmpl({'names': names})) == 'You '*len(names) assert str(tmpl({'names': names})) == 'You ' * len(names)
tmpl = tmpl.subclass('#for name in $names: $*1*(name) ') tmpl = tmpl.subclass('#for name in $names: $*1*(name) ')
assert str(tmpl({'names': names})) == 'You '*len(names) assert str(tmpl({'names': names})) == 'You ' * len(names)
tmpl = tmpl.subclass('#for name in $names: $*1*(name) ') tmpl = tmpl.subclass('#for name in $names: $*1*(name) ')
assert str(tmpl(names=names)) == 'You '*len(names) assert str(tmpl(names=names)) == 'You ' * len(names)
class Placeholders_Vals(OutputTest): class Placeholders_Vals(OutputTest):
convertEOLs = False convertEOLs = False
def test1(self): def test1(self):
"""string""" """string"""
self.verify("$aStr", "blarg") self.verify("$aStr", "blarg")
def test2(self): def test2(self):
"""string - with whitespace""" """string - with whitespace"""
skipping to change at line 1110 skipping to change at line 1110
$anInt $anInt
#end cache #end cache
#cache id='cache2', timer=15s #cache id='cache2', timer=15s
#for $i in range(5) #for $i in range(5)
$i#slurp $i#slurp
#end for #end for
#end cache #end cache
$aStr#slurp $aStr#slurp
#end def #end def
$foo$foo$foo$foo$foo""", $foo$foo$foo$foo$foo""",
"1\n01234blarg"*5) "1\n01234blarg"*5) # noqa: E226,E501 missing whitespace aro und operator
def test5(self): def test5(self):
r"""nested #cache blocks""" r"""nested #cache blocks"""
self.verify("""#slurp self.verify("""#slurp
#def foo #def foo
#cache ID='cache1', timer=150m #cache ID='cache1', timer=150m
$anInt $anInt
#cache id='cache2', timer=15s #cache id='cache2', timer=15s
#for $i in range(5) #for $i in range(5)
$i#slurp $i#slurp
#end for #end for
$*(6)#slurp $*(6)#slurp
#end cache #end cache
#end cache #end cache
$aStr#slurp $aStr#slurp
#end def #end def
$foo$foo$foo$foo$foo""", $foo$foo$foo$foo$foo""",
"1\n012346blarg"*5) "1\n012346blarg"*5) # noqa: E226,E501 missing whitespace ar ound operator
def test6(self): def test6(self):
r"""Make sure that partial directives don't match""" r"""Make sure that partial directives don't match"""
self.verify("#cache_foo", self.verify("#cache_foo",
"#cache_foo") "#cache_foo")
self.verify("#cached", self.verify("#cached",
"#cached") "#cached")
class CallDirective(OutputTest): class CallDirective(OutputTest):
skipping to change at line 1620 skipping to change at line 1620
self.verify("#for $i in range($aFunc(5)): $i", self.verify("#for $i in range($aFunc(5)): $i",
"01234") "01234")
def test14(self): def test14(self):
"""single line #for with 1 extra leading space""" """single line #for with 1 extra leading space"""
self.verify("#for $i in range($aFunc(5)): $i", self.verify("#for $i in range($aFunc(5)): $i",
" 0 1 2 3 4") " 0 1 2 3 4")
def test15(self): def test15(self):
"""2 times single line #for""" """2 times single line #for"""
self.verify("#for $i in range($aFunc(5)): $i#slurp\n"*2, self.verify("#for $i in range($aFunc(5)): $i#slurp\n"*2, # noqa: E226,E
"01234"*2) 501 missing whitespace around operator
"01234"*2) # noqa: E226 missing whitespace around operator
def test16(self): def test16(self):
"""false single line #for """ """false single line #for """
self.verify("#for $i in range(5): \n$i\n#end for", self.verify("#for $i in range(5): \n$i\n#end for",
"0\n1\n2\n3\n4\n") "0\n1\n2\n3\n4\n")
class RepeatDirective(OutputTest): class RepeatDirective(OutputTest):
def test1(self): def test1(self):
"""basic #repeat""" """basic #repeat"""
skipping to change at line 1667 skipping to change at line 1667
def test5(self): def test5(self):
"""#repeat with placeholder and WS""" """#repeat with placeholder and WS"""
self.verify(" #repeat $numTwo \n1\n #end repeat ", self.verify(" #repeat $numTwo \n1\n #end repeat ",
"1\n1\n") "1\n1\n")
def test6(self): def test6(self):
"""single-line #repeat""" """single-line #repeat"""
self.verify("#repeat $numTwo: 1", self.verify("#repeat $numTwo: 1",
"11") "11")
self.verify("#repeat $numTwo: 1\n"*2, self.verify("#repeat $numTwo: 1\n"*2, # noqa: E226,E501 missing whitesp
"1\n1\n"*2) ace around operator
"1\n1\n"*2) # noqa: E226,E501 missing whitespace around ope
rator
# false single-line # false single-line
self.verify("#repeat 3: \n1\n#end repeat", self.verify("#repeat 3: \n1\n#end repeat",
"1\n1\n1\n") "1\n1\n1\n")
class AttrDirective(OutputTest): class AttrDirective(OutputTest):
def test1(self): def test1(self):
"""#attr with int""" """#attr with int"""
self.verify("#attr $test = 1234\n$test", self.verify("#attr $test = 1234\n$test",
skipping to change at line 2392 skipping to change at line 2392
def test5(self): def test5(self):
"""#unless $numTwo with WS""" """#unless $numTwo with WS"""
self.verify(" #unless $numTwo \n 1234 \n #end unless ", self.verify(" #unless $numTwo \n 1234 \n #end unless ",
"") "")
def test6(self): def test6(self):
"""single-line #unless""" """single-line #unless"""
self.verify("#unless 1: 1234", "") self.verify("#unless 1: 1234", "")
self.verify("#unless 0: 1234", "1234") self.verify("#unless 0: 1234", "1234")
self.verify("#unless 0: 1234\n"*2, "1234\n"*2) self.verify("#unless 0: 1234\n"*2, "1234\n"*2) # noqa: E226,E501 missin g whitespace around operator
class PSP(OutputTest): class PSP(OutputTest):
def searchList(self): def searchList(self):
return None return None
def test1(self): def test1(self):
"""simple <%= [int] %>""" """simple <%= [int] %>"""
self.verify("<%= 1234 %>", "1234") self.verify("<%= 1234 %>", "1234")
def test2(self): def test2(self):
"""simple <%= [string] %>""" """simple <%= [string] %>"""
self.verify("<%= 'blarg' %>", "blarg") self.verify("<%= 'blarg' %>", "blarg")
def test3(self): def test3(self):
"""simple <%= None %>""" """simple <%= None %>"""
self.verify("<%= None %>", "") self.verify("<%= None %>", "")
def test4(self): def test4(self):
 End of changes. 14 change blocks. 
16 lines changed or deleted 19 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)