Permalink
Browse files

after discussion with eevee #1

  • Loading branch information...
1 parent 6e3e640 commit f365190fd86fb97fffce006a89870cd013711e3e @bukzor committed Apr 3, 2012
Showing with 24 additions and 17 deletions.
  1. +8 −6 cheetah/Compiler.py
  2. +1 −1 cheetah/Template.py
  3. +15 −10 cheetah/Tests/SyntaxAndOutput.py
View
14 cheetah/Compiler.py
@@ -1096,12 +1096,14 @@ def _addAutoCleanupCode(self):
self.addChunk('')
def addStop(self, expr=None):
- if self.setting('autoAssignDummyTransactionToSelf'):
- empty = None
- else:
- empty = ''
-
- self.addChunk('return _dummyTrans and trans.response().getvalue() or %r' % empty)
+ self.addChunk('if _dummyTrans:')
+ self.indent()
+ self.addChunk('return trans.response().getvalue()')
+ self.dedent()
+ self.addChunk('else:')
+ self.indent()
+ self.addChunk('return None')
+ self.dedent()
def addMethArg(self, name, defVal=None):
self._argStringList.append( (name, defVal) )
View
2 cheetah/Template.py
@@ -1424,7 +1424,7 @@ def capture(self, function, *args, **kwargs):
if buffer.strip():
warnings.warn("Ignoring buffer contents due to use of #return in $capture(%r)" % function)
- return retval
+ return retval
finally:
self.transaction = current_transaction
View
25 cheetah/Tests/SyntaxAndOutput.py
@@ -2977,10 +2977,15 @@ def test2(self):
)
def test3(self):
- filters_copy = warnings.filters[:]
- warnings.filterwarnings('error',
- 'Ignoring buffer contents due to use of #return',
- UserWarning)
+ # Monkeypatch showwarning to do logging; this is actually what the docs
+ # recommend!
+ warnings_log = []
+ def showwarning(message, category, filename, lineno, file=None, line=None):
+ # message is actually a warning object when using warnings.warn()
+ warnings_log.append(message.message)
+ orig_showwarning = warnings.showwarning
+ warnings.showwarning = showwarning
+
try:
self.verify(
"#def foo\n"
@@ -2991,13 +2996,13 @@ def test3(self):
"$buf $buf",
'output output'
)
- except UserWarning:
- pass
- else:
- self.fail("Expected warning about losing foo()'s contents")
- # Restore the old filters.
- warnings.filters[:] = filters_copy
+ assert any(
+ 'Ignoring buffer contents due to use of #return' in warning
+ for warning in warnings_log
+ ), "Expected warning about losing foo()'s contents"
+ finally:
+ warnings.showwarning = orig_showwarning

0 comments on commit f365190

Please sign in to comment.