Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

after discussion with eevee #1

  • Loading branch information...
commit f365190fd86fb97fffce006a89870cd013711e3e 1 parent 6e3e640
Buck Golemon authored
14  cheetah/Compiler.py
@@ -1096,12 +1096,14 @@ def _addAutoCleanupCode(self):
1096 1096
         self.addChunk('')
1097 1097
         
1098 1098
     def addStop(self, expr=None):
1099  
-        if self.setting('autoAssignDummyTransactionToSelf'):
1100  
-            empty = None
1101  
-        else:
1102  
-            empty = ''
1103  
-
1104  
-        self.addChunk('return _dummyTrans and trans.response().getvalue() or %r' % empty)
  1099
+        self.addChunk('if _dummyTrans:')
  1100
+        self.indent()
  1101
+        self.addChunk('return trans.response().getvalue()')
  1102
+        self.dedent()
  1103
+        self.addChunk('else:')
  1104
+        self.indent()
  1105
+        self.addChunk('return None')
  1106
+        self.dedent()
1105 1107
 
1106 1108
     def addMethArg(self, name, defVal=None):
1107 1109
         self._argStringList.append( (name, defVal) )
2  cheetah/Template.py
@@ -1424,7 +1424,7 @@ def capture(self, function, *args, **kwargs):
1424 1424
                 if buffer.strip():
1425 1425
                     warnings.warn("Ignoring buffer contents due to use of #return in $capture(%r)" % function)
1426 1426
 
1427  
-            return retval
  1427
+                return retval
1428 1428
         finally:
1429 1429
             self.transaction = current_transaction
1430 1430
 
25  cheetah/Tests/SyntaxAndOutput.py
@@ -2977,10 +2977,15 @@ def test2(self):
2977 2977
         )
2978 2978
 
2979 2979
     def test3(self):
2980  
-        filters_copy = warnings.filters[:]
2981  
-        warnings.filterwarnings('error',
2982  
-                                'Ignoring buffer contents due to use of #return',
2983  
-                                UserWarning)
  2980
+        # Monkeypatch showwarning to do logging; this is actually what the docs
  2981
+        # recommend!
  2982
+        warnings_log = []
  2983
+        def showwarning(message, category, filename, lineno, file=None, line=None):
  2984
+            # message is actually a warning object when using warnings.warn()
  2985
+            warnings_log.append(message.message)
  2986
+        orig_showwarning = warnings.showwarning
  2987
+        warnings.showwarning = showwarning
  2988
+
2984 2989
         try:
2985 2990
             self.verify(
2986 2991
                 "#def foo\n"
@@ -2991,13 +2996,13 @@ def test3(self):
2991 2996
                 "$buf $buf",
2992 2997
                 'output output'
2993 2998
             )
2994  
-        except UserWarning:
2995  
-            pass
2996  
-        else:
2997  
-            self.fail("Expected warning about losing foo()'s contents")
2998 2999
 
2999  
-        # Restore the old filters.
3000  
-        warnings.filters[:] = filters_copy
  3000
+            assert any(
  3001
+                    'Ignoring buffer contents due to use of #return' in warning
  3002
+                    for warning in warnings_log
  3003
+                ), "Expected warning about losing foo()'s contents"
  3004
+        finally:
  3005
+            warnings.showwarning = orig_showwarning
3001 3006
 
3002 3007
 
3003 3008
 

0 notes on commit f365190

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