~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_cleanup.py

  • Committer: Andrew Bennetts
  • Date: 2009-11-25 07:27:43 UTC
  • mto: This revision was merged to the branch mainline in revision 4825.
  • Revision ID: andrew.bennetts@canonical.com-20091125072743-v6sv4m2mkt9iyslp
Terminate SSHSubprocesses when no refs to them are left, in case .close is never called.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
20
20
from bzrlib.cleanup import (
21
21
    _do_with_cleanups,
22
22
    _run_cleanup,
23
 
    ObjectWithCleanups,
24
23
    OperationWithCleanups,
25
24
    )
26
25
from bzrlib.tests import TestCase
40
39
        self.call_log.append('no_op_cleanup')
41
40
 
42
41
    def assertLogContains(self, regex):
43
 
        self.assertContainsRe(self.get_log(), regex, re.DOTALL)
 
42
        log = self._get_log(keep_log_file=True)
 
43
        self.assertContainsRe(log, regex, re.DOTALL)
44
44
 
45
45
    def failing_cleanup(self):
46
46
        self.call_log.append('failing_cleanup')
184
184
        self.assertRaises(ErrorA, _do_with_cleanups, cleanups,
185
185
            self.trivial_func)
186
186
        self.assertLogContains('Cleanup failed:.*ErrorB')
187
 
        self.assertFalse('ErrorA' in self.get_log())
 
187
        log = self._get_log(keep_log_file=True)
 
188
        self.assertFalse('ErrorA' in log)
188
189
 
189
190
    def make_two_failing_cleanup_funcs(self):
190
191
        def raise_a():
277
278
            [('func called', 'foo'), 'cleanup 1', 'cleanup 2', 'cleanup 3',
278
279
            'cleanup 4'], call_log)
279
280
 
280
 
 
281
 
class SampleWithCleanups(ObjectWithCleanups):
282
 
 
283
 
    pass
284
 
 
285
 
 
286
 
class TestObjectWithCleanups(TestCase):
287
 
 
288
 
    def test_object_with_cleanups(self):
289
 
        a = []
290
 
        s = SampleWithCleanups()
291
 
        s.add_cleanup(a.append, 42)
292
 
        s.cleanup_now()
293
 
        self.assertEqual(a, [42])