~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_test_server.py

  • Committer: Vincent Ladeuil
  • Date: 2011-02-08 15:54:40 UTC
  • mto: This revision was merged to the branch mainline in revision 5655.
  • Revision ID: v.ladeuil+lp@free.fr-20110208155440-lns0pivfv8vskxji
Split ThreadWithException out of the tests hierarchy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
load_tests = load_tests_apply_scenarios
31
31
 
32
32
 
33
 
class TestThreadWithException(tests.TestCase):
34
 
 
35
 
    def test_start_and_join_smoke_test(self):
36
 
        def do_nothing():
37
 
            pass
38
 
 
39
 
        tt = test_server.ThreadWithException(target=do_nothing)
40
 
        tt.start()
41
 
        tt.join()
42
 
 
43
 
    def test_exception_is_re_raised(self):
44
 
        class MyException(Exception):
45
 
            pass
46
 
 
47
 
        def raise_my_exception():
48
 
            raise MyException()
49
 
 
50
 
        tt = test_server.ThreadWithException(target=raise_my_exception)
51
 
        tt.start()
52
 
        self.assertRaises(MyException, tt.join)
53
 
 
54
 
    def test_join_when_no_exception(self):
55
 
        resume = threading.Event()
56
 
        class MyException(Exception):
57
 
            pass
58
 
 
59
 
        def raise_my_exception():
60
 
            # Wait for the test to tell us to resume
61
 
            resume.wait()
62
 
            # Now we can raise
63
 
            raise MyException()
64
 
 
65
 
        tt = test_server.ThreadWithException(target=raise_my_exception)
66
 
        tt.start()
67
 
        tt.join(timeout=0)
68
 
        self.assertIs(None, tt.exception)
69
 
        resume.set()
70
 
        self.assertRaises(MyException, tt.join)
71
 
 
72
 
 
73
33
class TCPClient(object):
74
34
 
75
35
    def __init__(self):