diff options
author | Johan Dahlin <johan@src.gnome.org> | 2005-05-09 20:02:46 +0000 |
---|---|---|
committer | Johan Dahlin <johan@src.gnome.org> | 2005-05-09 20:02:46 +0000 |
commit | d774bbeb97ff5b3cbd6d1fcbae629bf83574d6e9 (patch) | |
tree | a68371efbd0cd57ef3ff8bbc691814087ac71e4d | |
parent | 46323c8148108e48abf6725646c5ab68406f2a8f (diff) | |
download | pygobject-d774bbeb97ff5b3cbd6d1fcbae629bf83574d6e9.tar.gz pygobject-d774bbeb97ff5b3cbd6d1fcbae629bf83574d6e9.tar.xz pygobject-d774bbeb97ff5b3cbd6d1fcbae629bf83574d6e9.zip |
And the test
-rw-r--r-- | tests/test_mainloop.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/test_mainloop.py b/tests/test_mainloop.py new file mode 100644 index 0000000..44d6937 --- /dev/null +++ b/tests/test_mainloop.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python + +import exceptions +import os +import sys +import select +import unittest + +from common import gobject + +class TestMainLoop(unittest.TestCase): + def testExceptionHandling(self): + pipe_r, pipe_w = os.pipe() + + pid = os.fork() + if pid == 0: + os.close(pipe_w) + select.select([pipe_r], [], []) + os.close(pipe_r) + os._exit(1) + + def child_died(pid, status, loop): + loop.quit() + raise Exception("deadbabe") + + loop = gobject.MainLoop() + gobject.child_watch_add(pid, child_died, loop) + + os.close(pipe_r) + os.write(pipe_w, "Y") + os.close(pipe_w) + + def excepthook(type, value, traceback): + assert type is exceptions.Exception + assert value.args[0] == "deadbabe" + sys.excepthook = excepthook + + got_exception = False + try: + loop.run() + except: + got_exception = True + + # + # The exception should be handled (by printing it) + # immediately on return from child_died() rather + # than here. See bug #303573 + # + sys.excepthook = sys.__excepthook__ + assert not got_exception + +if __name__ == '__main__': + unittest.main() |