Package elisa :: Package core :: Package tests :: Module test_utils_exception_hook
[hide private]
[frames] | no frames]

Source Code for Module elisa.core.tests.test_utils_exception_hook

 1  # Elisa - Home multimedia server 
 2  # Copyright (C) 2006-2008 Fluendo Embedded S.L. (www.fluendo.com). 
 3  # All rights reserved. 
 4  # 
 5  # This file is available under one of two license agreements. 
 6  # 
 7  # This file is licensed under the GPL version 3. 
 8  # See "LICENSE.GPL" in the root of this distribution including a special 
 9  # exception to use Elisa with Fluendo's plugins. 
10  # 
11  # The GPL part of Elisa is also available under a commercial licensing 
12  # agreement from Fluendo. 
13  # See "LICENSE.Elisa" in the root directory of this distribution package 
14  # for details on that license. 
15   
16  from elisa.core.tests.elisa_test_case import ElisaTestCase 
17  from elisa.core.utils import exception_hook 
18  import sys, os, tempfile, platform 
19   
20 -class TestExceptionHook(ElisaTestCase):
21
22 - def __init__(self, methodName='runTest'):
23 ElisaTestCase.__init__(self, methodName) 24 if platform.system() == 'Windows': 25 self.skip = "test not supported under windows"
26
27 - def setUp(self):
28 ElisaTestCase.setUp(self) 29 self._old_hook = sys.excepthook
30
31 - def tearDown(self):
32 sys.excepthook = self._old_hook
33
35 sys.excepthook = exception_hook.ExceptionHook(format='text', logdir='/tmp', 36 file=sys.stderr, display=False) 37 try: 38 raise Exception() 39 except: 40 sys.excepthook.handle()
41 43 errors = os.tmpfile() 44 sys.excepthook = exception_hook.ExceptionHook(format='text', logdir='/tmp', 45 file=errors, display=True) 46 try: 47 raise Exception() 48 except: 49 sys.excepthook.handle() 50 errors.seek(0) 51 data = errors.read() 52 self.failUnless(data) 53 54 errors.close()
55
56 - def test_exception_hook_html(self):
57 errors = os.tmpfile() 58 sys.excepthook = exception_hook.ExceptionHook(format='html', logdir='/tmp', 59 file=errors, display=True) 60 try: 61 raise Exception() 62 except: 63 sys.excepthook.handle() 64 errors.seek(0) 65 data = errors.read() 66 self.failUnless(data) 67 68 errors.close() 69