/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-06-10 01:35:53 UTC
  • mto: (6670.4.8 move-bzr)
  • mto: This revision was merged to the branch mainline in revision 6681.
  • Revision ID: jelmer@jelmer.uk-20170610013553-560y7mn3su4pp763
Fix remaining tests.

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))
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()
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()
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,
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])