[Checkins] SVN: grok/trunk/ Replace zope.deprecation.tests.warn with grok.testing.warn. Makes all the tests pass under 2.5

Jan-Wijbrand Kolman janwijbrand at gmail.com
Fri Jun 27 09:38:09 EDT 2008


Log message for revision 87828:
  Replace zope.deprecation.tests.warn with grok.testing.warn. Makes all the tests pass under 2.5

Changed:
  U   grok/trunk/CHANGES.txt
  U   grok/trunk/src/grok/ftests/view/macros.py
  U   grok/trunk/src/grok/templatereg.py
  U   grok/trunk/src/grok/testing.py
  U   grok/trunk/src/grok/tests/view/dirtemplatesonly.py
  U   grok/trunk/src/grok/tests/view/inline_unassociated.py
  U   grok/trunk/src/grok/tests/view/unassociated.py

-=-
Modified: grok/trunk/CHANGES.txt
===================================================================
--- grok/trunk/CHANGES.txt	2008-06-27 09:57:53 UTC (rev 87827)
+++ grok/trunk/CHANGES.txt	2008-06-27 13:38:04 UTC (rev 87828)
@@ -4,8 +4,18 @@
 0.14 (unreleased)
 =================
 
-...
+Bug fixes
+---------
 
+* Replace zope.deprecation.tests.warn with grok.testing.warn to:
+
+    * Make the signature identical to warnings.warn
+
+    * To check for *.pyc and *.pyo files.
+
+  When zope.deprecation is fixed this warn() function can be removed again.
+  Makes all the tests pass under Python-2.5.
+
 0.13 (2008-06-23)
 =================
 

Modified: grok/trunk/src/grok/ftests/view/macros.py
===================================================================
--- grok/trunk/src/grok/ftests/view/macros.py	2008-06-27 09:57:53 UTC (rev 87827)
+++ grok/trunk/src/grok/ftests/view/macros.py	2008-06-27 13:38:04 UTC (rev 87828)
@@ -21,7 +21,7 @@
   Traceback (most recent call last):
   AttributeError: 'DancingHall' object has no attribute 'template'
 
-If the view has an attribute with the same name as a macro, the macro 
+If the view has an attribute with the same name as a macro, the macro
 shadows the view. XXX This should probably generate a warning at runtime.
 
   >>> browser.open("http://localhost/manfred/@@grilldish")
@@ -29,19 +29,19 @@
   <html>
   Curry
   </html>
-  
+
 You can skip the "macro" part of the macro call, but this is deprecated:
 
-  >>> from zope.deprecation.tests import warn
+  >>> from grok.testing import warn
   >>> import warnings
   >>> saved_warn = warnings.warn
   >>> warnings.warn = warn
 
   >>> browser.open("http://localhost/manfred/@@burnt")
-  From tests.py's showwarning():
+  From grok.testing's warn():
   ... DeprecationWarning: Calling macros directly on the view is deprecated. Please use context/@@viewname/macros/macroname
   ...
-  
+
   >>> warnings.warn = saved_warn
 
 """

Modified: grok/trunk/src/grok/templatereg.py
===================================================================
--- grok/trunk/src/grok/templatereg.py	2008-06-27 09:57:53 UTC (rev 87827)
+++ grok/trunk/src/grok/templatereg.py	2008-06-27 13:38:04 UTC (rev 87828)
@@ -84,7 +84,7 @@
                 "grokking %r: %s.  Define view classes inheriting "
                 "from grok.View to enable the template(s)." % (
                 module_info.dotted_name, ', '.join(unassociated)))
-            warnings.warn(msg, UserWarning, 2)
+            warnings.warn(msg, UserWarning, 1)
 
     def checkTemplates(self, module_info, factory, component_name,
                        has_render, has_no_render):

Modified: grok/trunk/src/grok/testing.py
===================================================================
--- grok/trunk/src/grok/testing.py	2008-06-27 09:57:53 UTC (rev 87827)
+++ grok/trunk/src/grok/testing.py	2008-06-27 13:38:04 UTC (rev 87828)
@@ -13,6 +13,7 @@
 ##############################################################################
 """Grok test helpers
 """
+import sys
 import os.path
 import z3c.testsetup
 import grokcore.component
@@ -46,3 +47,33 @@
     zcml.do_grok('grok.templatereg', config)
     zcml.do_grok(module_name, config)
     config.execute_actions()
+
+def warn(message, category=None, stacklevel=1):
+    """Intended to replace warnings.warn in tests.
+
+    Modified copy from zope.deprecation.tests to:
+
+      * make the signature identical to warnings.warn
+      * to check for *.pyc and *.pyo files.
+
+    When zope.deprecation is fixed, this warn function can be removed again.
+    """
+    print "From grok.testing's warn():"
+
+    frame = sys._getframe(stacklevel)
+    path = frame.f_globals['__file__']
+    if path.endswith('.pyc') or path.endswith('.pyo'):
+        path = path[:-1]
+
+    file = open(path)
+    lineno = frame.f_lineno
+    for i in range(lineno):
+        line = file.readline()
+
+    print "%s:%s: %s: %s\n  %s" % (
+        path,
+        frame.f_lineno,
+        category.__name__,
+        message,
+        line.strip(),
+        )

Modified: grok/trunk/src/grok/tests/view/dirtemplatesonly.py
===================================================================
--- grok/trunk/src/grok/tests/view/dirtemplatesonly.py	2008-06-27 09:57:53 UTC (rev 87827)
+++ grok/trunk/src/grok/tests/view/dirtemplatesonly.py	2008-06-27 13:38:04 UTC (rev 87828)
@@ -1,13 +1,13 @@
 """
 A template directory may only contain recognized template files::
 
-  >>> from zope.deprecation.tests import warn
+  >>> from grok.testing import warn
   >>> import warnings
   >>> saved_warn = warnings.warn
   >>> warnings.warn = warn
 
   >>> grok.testing.grok(__name__)
-  From tests.py's showwarning():
+  From grok.testing's warn():
   ... UserWarning: File 'invalid.txt' has an unrecognized extension in
   directory '...dirtemplatesonly_templates'...
 

Modified: grok/trunk/src/grok/tests/view/inline_unassociated.py
===================================================================
--- grok/trunk/src/grok/tests/view/inline_unassociated.py	2008-06-27 09:57:53 UTC (rev 87827)
+++ grok/trunk/src/grok/tests/view/inline_unassociated.py	2008-06-27 13:38:04 UTC (rev 87828)
@@ -2,14 +2,16 @@
 Inline templates that are not associated with a view class will
 provoke an error:
 
-  >>> from zope.deprecation.tests import warn
+  >>> from grok.testing import warn
   >>> import warnings
   >>> saved_warn = warnings.warn
   >>> warnings.warn = warn
 
   >>> grok.testing.grok(__name__)
-  From tests.py's showwarning():
-  ...UserWarning: Found the following unassociated template(s) when grokking 'grok.tests.view.inline_unassociated': club.  Define view classes inheriting from grok.View to enable the template(s).
+  From grok.testing's warn():
+  ...UserWarning: Found the following unassociated template(s) when grokking
+  'grok.tests.view.inline_unassociated': club. Define view classes inheriting
+  from grok.View to enable the template(s)...
 
   >>> warnings.warn = saved_warn
 

Modified: grok/trunk/src/grok/tests/view/unassociated.py
===================================================================
--- grok/trunk/src/grok/tests/view/unassociated.py	2008-06-27 09:57:53 UTC (rev 87827)
+++ grok/trunk/src/grok/tests/view/unassociated.py	2008-06-27 13:38:04 UTC (rev 87828)
@@ -2,16 +2,16 @@
 Templates that are not associated with a view class will provoke an
 error:
 
-  >>> from zope.deprecation.tests import warn
+  >>> from grok.testing import warn
   >>> import warnings
   >>> saved_warn = warnings.warn
   >>> warnings.warn = warn
 
   >>> grok.testing.grok(__name__)
-  From tests.py's showwarning():
+  From grok.testing's warn():
   ...UserWarning: Found the following unassociated template(s) when grokking
   'grok.tests.view.unassociated': index.  Define view classes inheriting from
-  grok.View to enable the template(s).
+  grok.View to enable the template(s)...
 
 Also templates of modules named equally as the package name the module
 resides in, should be found without error or warning. We check this
@@ -22,7 +22,7 @@
   >>> pkg = __name__.rsplit('.', 1)[0] + '.modequalspkgname'
   >>> grok.testing.grok(pkg) is None
   True
-  
+
   >>> warnings.warn = saved_warn
 
 """



More information about the Checkins mailing list