Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

register programming errors when logging them

git-svn-id: http://projects.conceptive.be/camelot/svn/trunk@2491 8325946a-aa55-0410-8760-f0bc8c33efaa
  • Loading branch information...
commit ae0e07a1cbbd073f2e0ab4f57e8b67c06f43c6bd 1 parent 0e5c3fd
erikj authored
View
15 camelot/core/exception.py
@@ -26,7 +26,22 @@
"""
from camelot.core.utils import ugettext_lazy as _
+from camelot import test
+def log_programming_error( logger, message, exc_info = None ):
+ """Log a programming error and set the the global programming error variable
+ to be able to detect them in unit tests. Programming error logs are
+ generated by Camelot when something goes wrong and Camelot catches the
+ exception and tries to continue. The global flag is set to be able to
+ detect these issues with unit tests.
+
+ :param logger: a `logging.Logger` object
+ :param message: the message to log
+ :param exc_info: an exception that was raised
+ """
+ test.has_programming_error = True
+ logger.error( u'ProgrammingError : %s'%message, exc_info = exc_info )
+
class UserException(Exception):
"""
Raise this exception to inform the user he did something wrong, without
View
7 camelot/test/__init__.py
@@ -30,6 +30,8 @@
import unittest
+has_programming_error = False
+
_application_ = []
def get_application():
@@ -208,9 +210,11 @@ def get_admins(self):
def setUp(self):
super(EntityViewsTest, self).setUp()
from PyQt4 import QtCore
+ global has_programming_error
translators = self.get_application_admin().get_translator()
for translator in translators:
QtCore.QCoreApplication.installTranslator(translator)
+ has_programming_error = False
def get_application_admin(self):
"""Overwrite this method to make use of a custom application admin"""
@@ -236,6 +240,7 @@ def test_select_view(self):
for admin in self.get_admins():
widget = admin.create_select_view()
self.grab_widget(widget, suffix=admin.entity.__name__.lower(), subdir='entityviews')
+ self.assertFalse( has_programming_error )
def test_table_view(self):
from camelot.admin.action.base import GuiContext
@@ -243,9 +248,11 @@ def test_table_view(self):
for admin in self.get_admins():
widget = admin.create_table_view( gui_context )
self.grab_widget(widget, suffix=admin.entity.__name__.lower(), subdir='entityviews')
+ self.assertFalse( has_programming_error )
def test_new_view(self):
for admin in self.get_admins():
widget = admin.create_new_view()
self.grab_widget(widget, suffix=admin.entity.__name__.lower(), subdir='entityviews')
+ self.assertFalse( has_programming_error )
View
5 camelot/view/controls/editors/embeddedmany2oneeditor.py
@@ -31,6 +31,7 @@
from wideeditor import WideEditor
from camelot.view.model_thread import post
from camelot.view.proxy import ValueLoading
+from camelot.core.exception import log_programming_error
from camelot.core.utils import CollectionGetterFromObjectGetter
class EmbeddedMany2OneEditor( CustomEditor, WideEditor ):
@@ -96,7 +97,9 @@ def set_entity_instance():
try:
new_entity = self.admin.entity()
except Exception, e:
- logger.error('ProgrammingError : could not create a new entity of type %s'%(self.admin.entity.__name__), exc_info=e)
+ log_programming_error( logger,
+ 'Could not create a new entity of type %s'%(self.admin.entity.__name__),
+ exc_info = e )
self.entity_instance_getter = create_instance_getter( new_entity )
current_entity_admin = self.admin
return True, propagate, current_entity_admin
View
3  camelot/view/forms.py
@@ -32,6 +32,7 @@
from PyQt4 import QtCore, QtGui
+from camelot.core.exception import log_programming_error
from camelot.view.model_thread import gui_function
class Form( list ):
@@ -262,7 +263,7 @@ def __str__(self):
c.next_col()
size_policy = editor.sizePolicy()
else:
- logger.warning('ProgrammingError : widgets should contain a widget for field %s'%unicode(field))
+ log_programming_error( logger, 'widgets should contain a widget for field %s'%unicode(field) )
if size_policy and size_policy.verticalPolicy() == QtGui.QSizePolicy.Expanding:
has_vertical_expanding_row = True
View
17 camelot/view/proxy/collection_proxy.py
@@ -38,6 +38,7 @@
from PyQt4.QtCore import Qt, QThread
from PyQt4 import QtGui, QtCore
+from camelot.core.exception import log_programming_error
from camelot.core.utils import is_deleted, variant_to_pyobject
from camelot.core.files.storage import StoredFile
from camelot.view.art import Icon
@@ -110,8 +111,10 @@ def create_collection_getter( o, attr ):
else:
field_value = getter( obj )
except (Exception, RuntimeError, TypeError, NameError), e:
- logger.error( "ProgrammingError : could not get field '%s' of object of type %s"%(col[0], obj.__class__.__name__),
- exc_info = e )
+ message = "could not get field '%s' of object of type %s"%(col[0], obj.__class__.__name__)
+ log_programming_error( logger,
+ message,
+ exc_info = e )
finally:
row_data.append( field_value )
return row_data
@@ -150,9 +153,9 @@ def stripped_data_to_unicode( stripped_data, obj, static_field_attributes, dynam
elif field_data != None:
unicode_data = unicode( field_data )
except (Exception, RuntimeError, TypeError, NameError), e:
- logger.error( "ProgrammingError : could not get view data for field '%s' with of object of type %s"%( static_attributes['name'],
- obj.__class__.__name__),
- exc_info = e)
+ log_programming_error( "Could not get view data for field '%s' with of object of type %s"%( static_attributes['name'],
+ obj.__class__.__name__),
+ exc_info = e )
finally:
row_data.append( unicode_data )
@@ -498,7 +501,9 @@ def setColumns( self, columns ):
try:
delegate = c[1]['delegate']( parent = delegate_manager, **c[1] )
except Exception, e:
- logger.error('ProgrammingError : could not create delegate for field %s'%field_name, exc_info=e)
+ log_programming_error( logger,
+ 'Could not create delegate for field %s'%field_name,
+ exc_info = e )
delegate = delegates.PlainTextDelegate( parent = delegate_manager, **c[1] )
delegate_manager.insertColumnDelegate( i, delegate )
#
Please sign in to comment.
Something went wrong with that request. Please try again.