[Checkins] SVN: grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/test refactor to ease test conversion

Godefroid Chapelle gotcha at bubblenet.be
Fri Jul 18 06:27:29 EDT 2008


Log message for revision 88487:
  refactor to ease test conversion

Changed:
  A   grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/testing.py
  U   grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/tests/components.py
  U   grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/tests/grok.py

-=-
Added: grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/testing.py
===================================================================
--- grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/testing.py	                        (rev 0)
+++ grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/testing.py	2008-07-18 10:27:29 UTC (rev 88487)
@@ -0,0 +1,46 @@
+import sys
+
+from zope.configuration.config import ConfigurationMachine
+
+from grokcore.component import zcml
+
+
+def grok(module_name):
+    config = ConfigurationMachine()
+    zcml.do_grok('grokcore.component.meta', config)
+    zcml.do_grok('grokcore.view.meta', config)
+    zcml.do_grok('grokcore.view.templatereg', config)
+    zcml.do_grok('grokcore.view.tests.meta', 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/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/tests/components.py
===================================================================
--- grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/tests/components.py	2008-07-18 10:20:31 UTC (rev 88486)
+++ grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/tests/components.py	2008-07-18 10:27:29 UTC (rev 88487)
@@ -2,9 +2,7 @@
 
 from zope import interface
 from zope.publisher.browser import BrowserPage
-from zope.configuration.config import ConfigurationMachine
 
-from grokcore.component import zcml
 from grokcore.component.interfaces import IContext
 
 import grokcore.view
@@ -45,18 +43,3 @@
                       "View %r, macro %s" % (self, key),
                       DeprecationWarning, 1)
         return value
-
-
-class Testing(object):
-
-    def grok(self, module_name):
-        config = ConfigurationMachine()
-        zcml.do_grok('grokcore.component.meta', config)
-        zcml.do_grok('grokcore.view.meta', config)
-        zcml.do_grok('grokcore.view.templatereg', config)
-        zcml.do_grok('grokcore.view.tests.meta', config)
-        zcml.do_grok(module_name, config)
-        config.execute_actions()
-
-
-testing = Testing()

Modified: grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/tests/grok.py
===================================================================
--- grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/tests/grok.py	2008-07-18 10:20:31 UTC (rev 88486)
+++ grok/branches/grokcore.xxx/devel/grokcore.view/src/grokcore/view/tests/grok.py	2008-07-18 10:27:29 UTC (rev 88487)
@@ -1 +1,2 @@
-from grokcore.view.tests.components import Model, View, testing
+from grokcore.view.tests.components import Model, View
+from grokcore.view import testing



More information about the Checkins mailing list