~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_progress.py

  • Committer: Martin Pool
  • Date: 2007-07-11 06:47:30 UTC
  • mto: This revision was merged to the branch mainline in revision 2612.
  • Revision ID: mbp@sourcefrog.net-20070711064730-pwnhisgp2caf7nar
Don't show dots progress indicatiors in noninteractive mode

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 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
19
19
 
20
20
from bzrlib import errors
21
21
from bzrlib.progress import (
22
 
        DummyProgress, ChildProgress,
 
22
        DummyProgress,
 
23
        ChildProgress,
23
24
        TTYProgressBar,
24
25
        DotsProgressBar,
25
26
        ProgressBarStack,
243
244
                         '\r                   \r',
244
245
                         out.getvalue())
245
246
 
 
247
    def test_noninteractive_progress(self):
 
248
        out = _NonTTYStringIO()
 
249
        pb = self.get_nested(out, 'xterm')
 
250
        self.assertIsInstance(pb, DummyProgress)
 
251
        try:
 
252
            pb.update('foo', 1, 2)
 
253
            pb.update('bar', 2, 2)
 
254
        finally:
 
255
            pb.finished()
 
256
        self.assertEqual('', out.getvalue())
 
257
 
246
258
    def test_dots_progress(self):
247
 
        # Make sure the ProgressBarStack thinks it is
248
 
        # not writing out to a terminal, and thus uses a 
249
 
        # DotsProgressBar
 
259
        # make sure we get the right progress bar when not on a terminal
250
260
        out = _NonTTYStringIO()
251
 
        pb = self.get_nested(out, 'xterm')
 
261
        pb = self.get_nested(out, 'xterm', 'dots')
252
262
        self.assertIsInstance(pb, DotsProgressBar)
253
263
        try:
254
264
            pb.update('foo', 1, 2)
255
265
            pb.update('bar', 2, 2)
256
266
        finally:
257
267
            pb.finished()
258
 
 
259
268
        self.assertEqual('foo: .'
260
269
                         '\nbar: .'
261
270
                         '\n',
267
276
        out = cStringIO.StringIO()
268
277
        pb = self.get_nested(out, 'xterm')
269
278
        pb.finished()
270
 
        self.assertIsInstance(pb, DotsProgressBar)
 
279
        self.assertIsInstance(pb, DummyProgress)
271
280
 
272
281
    def test_dumb_progress(self):
273
 
        # Make sure the ProgressBarStack thinks it is writing out to a 
274
 
        # terminal, but it is the emacs 'dumb' terminal, so it uses
275
 
        # Dots
 
282
        # using a terminal that can't do cursor movement
276
283
        out = _TTYStringIO()
277
284
        pb = self.get_nested(out, 'dumb')
278
285
        pb.finished()
279
 
        self.assertIsInstance(pb, DotsProgressBar)
 
286
        self.assertIsInstance(pb, DummyProgress)
280
287
 
281
288
    def test_progress_env_tty(self):
282
289
        # The environ variable BZR_PROGRESS_BAR controls what type of
290
297
        # Even though we are not a tty, the env_var will override
291
298
        self.assertIsInstance(pb, TTYProgressBar)
292
299
 
293
 
    def test_progress_env_dots(self):
294
 
        # Even though we are in a tty, the env_var will override
295
 
        out = _TTYStringIO()
296
 
        pb = self.get_nested(out, 'xterm', 'dots')
297
 
        pb.finished()
298
 
        self.assertIsInstance(pb, DotsProgressBar)
299
 
 
300
300
    def test_progress_env_none(self):
301
301
        # Even though we are in a valid tty, no progress
302
302
        out = _TTYStringIO()