2005-04-06 Richard Taylor <rjt-gramps@thegrindstone.me.uk>

* src/GrampsDBCallback.py: improved error reporting when there is an error in
	a callback function. Added unittest for exception in callback function.


svn: r4305
This commit is contained in:
Richard Taylor 2005-04-06 10:04:32 +00:00
parent 5b44756832
commit 997d77068c
2 changed files with 45 additions and 3 deletions

View File

@ -1,3 +1,7 @@
2005-04-06 Richard Taylor <rjt-gramps@thegrindstone.me.uk>
* src/GrampsDBCallback.py: improved error reporting when there is an error in
a callback function. Added unittest for exception in callback function.
2005-04-06 Martin Hawlisch <Martin.Hawlisch@gmx.de> 2005-04-06 Martin Hawlisch <Martin.Hawlisch@gmx.de>
* src/gramps_main.py (post_load): Emit "database-changed" signal instead of * src/gramps_main.py (post_load): Emit "database-changed" signal instead of
calling change_db(). calling change_db().
@ -11,7 +15,7 @@
* src/SourceView.py (__init__): dont call change_cb because on initialisation * src/SourceView.py (__init__): dont call change_cb because on initialisation
there is no real database and this will be done by the signal. there is no real database and this will be done by the signal.
2005-04-04 Richard Taylor <rjt-gramps@thegrindstone.me.uk> 2005-04-06 Richard Taylor <rjt-gramps@thegrindstone.me.uk>
* src/plugins/ScratchPad.py: made clear buttons sensitive to contents of * src/plugins/ScratchPad.py: made clear buttons sensitive to contents of
list and current selection. Added support for PERSON_LINK dnd. list and current selection. Added support for PERSON_LINK dnd.
* src/DdTargets.py: added PERSON_LINK target and simplified generation of * src/DdTargets.py: added PERSON_LINK target and simplified generation of

View File

@ -35,8 +35,9 @@
to communicate events to any callback methods in either the database code to communicate events to any callback methods in either the database code
or the UI code. or the UI code.
""" """
import types
import sys import sys
import types
import traceback
log = sys.stderr.write log = sys.stderr.write
@ -364,7 +365,10 @@ class GrampsDBCallback(object):
else: else:
self._log("Warning: badly formed entry in callback map.\n") self._log("Warning: badly formed entry in callback map.\n")
except: except:
self._log("Warning: exception occured in callback function.\n") log("%s: %s" % (self.__class__.__name__,
"Warning: exception occured in callback function.\n"))
log("%s: %s" % (self.__class__.__name__,
"".join(traceback.format_exception(*sys.exc_info()))))
# #
# instance signals control methods # instance signals control methods
@ -434,6 +438,40 @@ if __name__ == "__main__":
assert len(rl) == 1, "No signal emitted" assert len(rl) == 1, "No signal emitted"
assert rl[0] == 1, "Wrong argument recieved" assert rl[0] == 1, "Wrong argument recieved"
def test_exception_catch(self):
class TestSignals(GrampsDBCallback):
__signals__ = {
'test-signal' : (int,)
}
rl = []
def fn(i,r=rl):
rl.append(i)
def borked(i):
rubish.append(i)
t = TestSignals()
def null(s):
pass
global log
_log = log
log = null
t.connect('test-signal',borked)
t.connect('test-signal',fn)
t.emit('test-signal',(1,))
log = _log
assert len(rl) == 1, "No signal emitted"
assert rl[0] == 1, "Wrong argument recieved"
def test_disconnect(self): def test_disconnect(self):
class TestSignals(GrampsDBCallback): class TestSignals(GrampsDBCallback):