Skip to content
Browse files

Updated to use getattr instead of hasattr.

  • Loading branch information...
1 parent b6e0f64 commit 94871bb33ca6aca6e0ea0e94dc9627e77d541a7e @asottile committed Jul 27, 2012
Showing with 30 additions and 7 deletions.
  1. +1 −1 cheetah/Parser.py
  2. +29 −6 cheetah/Tests/SyntaxAndOutput.py
View
2 cheetah/Parser.py
@@ -2334,7 +2334,7 @@ def eatMacroCall(self):
srcBlock = self.readToEOL(gobble=False)
EOLCharsInShortForm = self.readToEOL(gobble=True)
#self.readToEOL(gobble=False)
- elif hasattr(macro, 'emptySourceBlock'):
+ elif getattr(macro, 'emptySourceBlock', False):
isShortForm = True
srcBlock = ''
self.readToEOL(gobble=False)
View
35 cheetah/Tests/SyntaxAndOutput.py
@@ -3118,7 +3118,7 @@ class TestMacroNoArgs(object):
emptySourceBlock = True
def __init__(self, parser): pass
- def __call__(self, src, **kwargs): return 'testMacroNoArgs'
+ def __call__(self, src, **kwargs): return 'TestMacroNoArgs'
class TestMacroTakesArgs(object):
"""
@@ -3131,27 +3131,50 @@ def __init__(self, parser): pass
def __call__(self, src, customParam=None, **kwargs): return customParam
def convertArgStrToDict(self, argumentString, **kwargs):
return {'customParam': argumentString}
+
+ class TestMacroNotEmptySourceBlock(object):
+ """
+ Define a macro that requires the end block by having emptySourceBlock = False
+ """
+
+ emptySourceBlock = False
+
+ def __init__(self, parser): pass
+ def __call__(self, src, **kwargs): return 'TestMacroNotEmptySourceBlock'
+
def _getCompilerSettings(self):
return {'macroDirectives': {
- 'testMacroNoArgs': self.TestMacroNoArgs ,
- 'testMacroTakesArgs': self.TestMacroTakesArgs
+ 'TestMacroNoArgs': self.TestMacroNoArgs ,
+ 'TestMacroTakesArgs': self.TestMacroTakesArgs,
+ 'TestMacroNotEmptySourceBlock': self.TestMacroNotEmptySourceBlock
}}
def test1(self):
"""Test that a macro with no args is processed correctly."""
self.verify("""\
-#testMacroNoArgs
+#TestMacroNoArgs
""",
- 'testMacroNoArgs')
+ 'TestMacroNoArgs')
def test2(self):
"""Test that a macro with no args is processed correctly."""
+
self.verify("""\
-#testMacroTakesArgs arguments, passed
+#TestMacroTakesArgs arguments, passed
""",
'arguments, passed')
+
+ def test3(self):
+ """Test that a macro with emptySourceBlock = False requires end macro."""
+
+ self.verify("""\
+#TestMacroNotEmptySourceBlock
+herp
+#end TestMacroNotEmptySourceBlock
+""",
+ 'TestMacroNotEmptySourceBlock')
class DefmacroDirective(OutputTest):
def _getCompilerSettings(self):

0 comments on commit 94871bb

Please sign in to comment.
Something went wrong with that request. Please try again.