Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

after discussion with eevee #1

  • Loading branch information...
commit f365190fd86fb97fffce006a89870cd013711e3e 1 parent 6e3e640
Buck Evan authored
14 cheetah/Compiler.py
View
@@ -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) )
2  cheetah/Template.py
View
@@ -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
25 cheetah/Tests/SyntaxAndOutput.py
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.