/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_cleanup.py

  • Committer: Jelmer Vernooij
  • Date: 2017-07-23 15:59:57 UTC
  • mto: This revision was merged to the branch mainline in revision 6740.
  • Revision ID: jelmer@jelmer.uk-20170723155957-rw4kqurf44fqx4x0
Move AlreadyBuilding/NotBuilding errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
from cStringIO import StringIO
18
17
import re
19
18
 
20
 
from bzrlib.cleanup import (
 
19
from ..cleanup import (
21
20
    _do_with_cleanups,
22
21
    _run_cleanup,
 
22
    ObjectWithCleanups,
23
23
    OperationWithCleanups,
24
24
    )
25
 
from bzrlib.tests import TestCase
26
 
from bzrlib import (
 
25
from ..sixish import (
 
26
    BytesIO,
 
27
    )
 
28
from . import TestCase
 
29
from .. import (
27
30
    debug,
28
31
    trace,
29
32
    )
80
83
        """The -Dcleanup debug flag causes cleanup errors to be reported to the
81
84
        user.
82
85
        """
83
 
        log = StringIO()
 
86
        log = BytesIO()
84
87
        trace.push_log_file(log)
85
88
        debug.debug_flags.add('cleanup')
86
89
        self.assertFalse(_run_cleanup(self.failing_cleanup))
87
90
        self.assertContainsRe(
88
91
            log.getvalue(),
89
 
            "bzr: warning: Cleanup failed:.*failing_cleanup goes boom")
 
92
            "brz: warning: Cleanup failed:.*failing_cleanup goes boom")
90
93
 
91
94
    def test_prior_error_cleanup_succeeds(self):
92
95
        """Calling _run_cleanup from a finally block will not interfere with an
193
196
        return [(raise_a, (), {}), (raise_b, (), {})]
194
197
 
195
198
    def test_multiple_cleanup_failures_debug_flag(self):
196
 
        log = StringIO()
 
199
        log = BytesIO()
197
200
        trace.push_log_file(log)
198
201
        debug.debug_flags.add('cleanup')
199
202
        cleanups = self.make_two_failing_cleanup_funcs()
200
203
        self.assertRaises(ErrorA, _do_with_cleanups, cleanups,
201
204
            self.trivial_func)
202
205
        self.assertContainsRe(
203
 
            log.getvalue(), "bzr: warning: Cleanup failed:.*Error B\n")
204
 
        self.assertEqual(1, log.getvalue().count('bzr: warning:'),
 
206
            log.getvalue(), "brz: warning: Cleanup failed:.*Error B\n")
 
207
        self.assertEqual(1, log.getvalue().count('brz: warning:'),
205
208
                log.getvalue())
206
209
 
207
210
    def test_func_and_cleanup_errors_debug_flag(self):
208
 
        log = StringIO()
 
211
        log = BytesIO()
209
212
        trace.push_log_file(log)
210
213
        debug.debug_flags.add('cleanup')
211
214
        cleanups = self.make_two_failing_cleanup_funcs()
212
215
        self.assertRaises(ZeroDivisionError, _do_with_cleanups, cleanups,
213
216
            self.failing_func)
214
217
        self.assertContainsRe(
215
 
            log.getvalue(), "bzr: warning: Cleanup failed:.*Error A\n")
 
218
            log.getvalue(), "brz: warning: Cleanup failed:.*Error A\n")
216
219
        self.assertContainsRe(
217
 
            log.getvalue(), "bzr: warning: Cleanup failed:.*Error B\n")
218
 
        self.assertEqual(2, log.getvalue().count('bzr: warning:'))
 
220
            log.getvalue(), "brz: warning: Cleanup failed:.*Error B\n")
 
221
        self.assertEqual(2, log.getvalue().count('brz: warning:'))
219
222
 
220
223
    def test_func_may_mutate_cleanups(self):
221
224
        """The main func may mutate the cleanups before it returns.
238
241
        """The -Dcleanup debug flag causes cleanup errors to be reported to the
239
242
        user.
240
243
        """
241
 
        log = StringIO()
 
244
        log = BytesIO()
242
245
        trace.push_log_file(log)
243
246
        debug.debug_flags.add('cleanup')
244
247
        self.assertRaises(ZeroDivisionError, _do_with_cleanups,
245
248
            [(self.failing_cleanup, (), {})], self.failing_func)
246
249
        self.assertContainsRe(
247
250
            log.getvalue(),
248
 
            "bzr: warning: Cleanup failed:.*failing_cleanup goes boom")
249
 
        self.assertEqual(1, log.getvalue().count('bzr: warning:'))
 
251
            "brz: warning: Cleanup failed:.*failing_cleanup goes boom")
 
252
        self.assertEqual(1, log.getvalue().count('brz: warning:'))
250
253
 
251
254
 
252
255
class ErrorA(Exception): pass
276
279
            [('func called', 'foo'), 'cleanup 1', 'cleanup 2', 'cleanup 3',
277
280
            'cleanup 4'], call_log)
278
281
 
 
282
 
 
283
class SampleWithCleanups(ObjectWithCleanups):
 
284
 
 
285
    pass
 
286
 
 
287
 
 
288
class TestObjectWithCleanups(TestCase):
 
289
 
 
290
    def test_object_with_cleanups(self):
 
291
        a = []
 
292
        s = SampleWithCleanups()
 
293
        s.add_cleanup(a.append, 42)
 
294
        s.cleanup_now()
 
295
        self.assertEqual(a, [42])