[Checkins] SVN: grok/trunk/src/grok/te Issue a UserWarning when Grok finds unassociated templates, do not

Jan-Wijbrand Kolman janwijbrand at gmail.com
Wed Nov 14 06:23:44 EST 2007


Log message for revision 81825:
  Issue a UserWarning when Grok finds unassociated templates, do not 
  raise an GrokError.

Changed:
  U   grok/trunk/src/grok/templatereg.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/src/grok/templatereg.py
===================================================================
--- grok/trunk/src/grok/templatereg.py	2007-11-14 09:05:48 UTC (rev 81824)
+++ grok/trunk/src/grok/templatereg.py	2007-11-14 11:23:43 UTC (rev 81825)
@@ -31,7 +31,7 @@
 
         if not os.path.isdir(template_dir):
             return
-        
+
         for template_file in os.listdir(template_dir):
             if template_file.startswith('.') or template_file.endswith('~'):
                 continue
@@ -41,7 +41,7 @@
             template_factory = zope.component.queryUtility(
                 grok.interfaces.ITemplateFileFactory,
                 name=extension)
-                
+
             if template_factory is None:
                 # Warning when importing files. This should be
                 # allowed because people may be using editors that generate
@@ -74,19 +74,20 @@
     def checkUnassociated(self, module_info):
         unassociated = list(self.listUnassociated())
         if unassociated:
-            raise GrokError("Found the following unassociated template(s) when "
-                            "grokking %r: %s.  Define view classes inheriting "
-                            "from grok.View to enable the template(s)."
-                            % (module_info.dotted_name,
-                               ', '.join(unassociated)), module_info)
+            msg = (
+                "Found the following unassociated template(s) when "
+                "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)
 
     def checkTemplates(self, module_info, factory, factory_name):
         template_name = util.class_annotation(factory, 'grok.template',
                                               factory_name)
-            
+
         if factory_name != template_name:
             # grok.template is being used
-    
+
             if self.get(factory_name):
                 raise GrokError("Multiple possible templates for view %r. It "
                                 "uses grok.template('%s'), but there is also "
@@ -113,9 +114,9 @@
                                 "'render' method." % factory, factory)
 
 class PageTemplateFileFactory(grok.GlobalUtility):
-    
+
     grok.implements(grok.interfaces.ITemplateFileFactory)
     grok.name('pt')
-    
+
     def __call__(self, filename, _prefix=None):
         return grok.components.PageTemplate(filename=filename, _prefix=_prefix)

Modified: grok/trunk/src/grok/tests/view/dirtemplatesonly.py
===================================================================
--- grok/trunk/src/grok/tests/view/dirtemplatesonly.py	2007-11-14 09:05:48 UTC (rev 81824)
+++ grok/trunk/src/grok/tests/view/dirtemplatesonly.py	2007-11-14 11:23:43 UTC (rev 81825)
@@ -1,15 +1,16 @@
 """
-A template directory may only contain recognized template files:
+A template directory may only contain recognized template files::
+
   >>> from zope.deprecation.tests import warn
   >>> import warnings
   >>> saved_warn = warnings.warn
   >>> warnings.warn = warn
 
+  >>> grok.testing.grok(__name__)
+  From tests.py's showwarning():
+  ... UserWarning: File 'invalid.txt' has an unrecognized extension in
+  directory '...dirtemplatesonly_templates'...
 
-  >>> grok.testing.grok(__name__)
-    From tests.py's showwarning():
-    ... UserWarning: File 'invalid.txt' has an unrecognized extension in directory '...dirtemplatesonly_templates'...
-    
   >>> warnings.warn = saved_warn
 
 """

Modified: grok/trunk/src/grok/tests/view/inline_unassociated.py
===================================================================
--- grok/trunk/src/grok/tests/view/inline_unassociated.py	2007-11-14 09:05:48 UTC (rev 81824)
+++ grok/trunk/src/grok/tests/view/inline_unassociated.py	2007-11-14 11:23:43 UTC (rev 81825)
@@ -2,14 +2,19 @@
 Inline templates that are not associated with a view class will
 provoke an error:
 
+  >>> from zope.deprecation.tests import warn
+  >>> import warnings
+  >>> saved_warn = warnings.warn
+  >>> warnings.warn = warn
+
   >>> grok.testing.grok(__name__)
-  Traceback (most recent call last):
-  ...
-  ConfigurationExecutionError: martian.error.GrokError: Found the following unassociated template(s) when grokking
+  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).
-  in:
-  
+
+  >>> warnings.warn = saved_warn
+
 """
 import grok
 

Modified: grok/trunk/src/grok/tests/view/unassociated.py
===================================================================
--- grok/trunk/src/grok/tests/view/unassociated.py	2007-11-14 09:05:48 UTC (rev 81824)
+++ grok/trunk/src/grok/tests/view/unassociated.py	2007-11-14 11:23:43 UTC (rev 81825)
@@ -2,14 +2,19 @@
 Templates that are not associated with a view class will provoke an
 error:
 
+  >>> from zope.deprecation.tests import warn
+  >>> import warnings
+  >>> saved_warn = warnings.warn
+  >>> warnings.warn = warn
+
   >>> grok.testing.grok(__name__)
-  Traceback (most recent call last):
-  ...
-  ConfigurationExecutionError: martian.error.GrokError: 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).
-  in:
+  From tests.py's showwarning():
+  ...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).
 
+  >>> warnings.warn = saved_warn
+
 """
 import grok
 



More information about the Checkins mailing list