1
# Copyright (C) 2010, 2011 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25
class TestThreadWithException(tests.TestCase):
27
def test_start_and_join_smoke_test(self):
31
tt = thread.ThreadWithException(target=do_nothing)
35
def test_exception_is_re_raised(self):
36
class MyException(Exception):
39
def raise_my_exception():
42
tt = thread.ThreadWithException(target=raise_my_exception)
44
self.assertRaises(MyException, tt.join)
46
def test_join_when_no_exception(self):
47
resume = threading.Event()
48
class MyException(Exception):
51
def raise_my_exception():
52
# Wait for the test to tell us to resume
57
tt = thread.ThreadWithException(target=raise_my_exception)
60
self.assertIs(None, tt.exception)
62
self.assertRaises(MyException, tt.join)