14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18
from StringIO import StringIO
19
20
from bzrlib.progress import (
173
174
pb.update('x', count+100, 200)
175
176
self.assertEqual(pb._max_last_updates, len(pb.last_updates))
178
def test_tty_progress(self):
179
# Make sure the ProgressBarStack thinks it is
180
# writing out to a terminal, and thus uses a TTYProgressBar
181
class TTYStringIO(StringIO):
184
orig_term = os.environ.get('TERM')
186
os.environ['TERM'] = 'xterm'
188
stack = ProgressBarStack(to_file=out)
189
pb = stack.get_nested()
190
self.assertIsInstance(pb, TTYProgressBar)
194
pb.update('foo', 1, 2)
195
pb.update('bar', 2, 2)
199
if orig_term is None:
200
del os.environ['TERM']
202
os.environ['TERM'] = orig_term
204
self.assertEqual('\r/ [==== ] foo 1/2'
205
'\r- [=======] bar 2/2'
209
def test_dots_progress(self):
210
# Make sure the ProgressBarStack thinks it is
211
# not writing out to a terminal, and thus uses a
213
class NonTTYStringIO(StringIO):
216
orig_term = os.environ.get('TERM')
218
os.environ['TERM'] = 'xterm'
219
out = NonTTYStringIO()
220
stack = ProgressBarStack(to_file=out)
221
pb = stack.get_nested()
225
pb.update('foo', 1, 2)
226
pb.update('bar', 2, 2)
230
if orig_term is None:
231
del os.environ['TERM']
233
os.environ['TERM'] = orig_term
235
self.assertEqual('foo: .'
240
def test_dumb_progress(self):
241
# Make sure the ProgressBarStack thinks it is writing out to a
242
# terminal, but it is the emacs 'dumb' terminal, so it uses
244
class TTYStringIO(StringIO):
247
orig_term = os.environ.get('TERM')
249
os.environ['TERM'] = 'dumb'
251
stack = ProgressBarStack(to_file=out)
252
pb = stack.get_nested()
253
self.assertIsInstance(pb, DotsProgressBar)
257
pb.update('foo', 1, 2)
258
pb.update('bar', 2, 2)
262
if orig_term is None:
263
del os.environ['TERM']
265
os.environ['TERM'] = orig_term
267
self.assertEqual('foo: .'