~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_cleanup.py

(jelmer) Use the absolute_import feature everywhere in bzrlib,
 and add a source test to make sure it's used everywhere. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009 Canonical Ltd
 
1
# Copyright (C) 2009, 2010 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,
23
24
    OperationWithCleanups,
24
25
    )
25
26
from bzrlib.tests import TestCase
39
40
        self.call_log.append('no_op_cleanup')
40
41
 
41
42
    def assertLogContains(self, regex):
42
 
        log = self._get_log(keep_log_file=True)
43
 
        self.assertContainsRe(log, regex, re.DOTALL)
 
43
        self.assertContainsRe(self.get_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
 
        log = self._get_log(keep_log_file=True)
188
 
        self.assertFalse('ErrorA' in log)
 
187
        self.assertFalse('ErrorA' in self.get_log())
189
188
 
190
189
    def make_two_failing_cleanup_funcs(self):
191
190
        def raise_a():
278
277
            [('func called', 'foo'), 'cleanup 1', 'cleanup 2', 'cleanup 3',
279
278
            'cleanup 4'], call_log)
280
279
 
 
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])