262
259
ui = ui_testing.TextUIFactory()
263
260
remote_fmt = remote.RemoteRepositoryFormat()
264
261
remote_fmt._network_name = RepositoryFormatKnitPack5().network_name()
265
ui.show_user_warning(
266
'cross_format_fetch', from_format=RepositoryFormat2a(),
262
ui.show_user_warning('cross_format_fetch', from_format=RepositoryFormat2a(),
267
263
to_format=remote_fmt)
268
264
self.assertEqual('', ui.stdout.getvalue())
269
265
self.assertContainsRe(
270
266
ui.stderr.getvalue(),
271
267
"^Doing on-the-fly conversion from RepositoryFormat2a\\(\\) to "
272
"RemoteRepositoryFormat\\(_network_name="
273
"b?'Bazaar RepositoryFormatKnitPack5 \\(bzr 1.6\\)\\\\n'\\)\\.\n"
268
"RemoteRepositoryFormat\\(_network_name="
269
"b?'Bazaar RepositoryFormatKnitPack5 \\(bzr 1.6\\)\\\\n'\\)\\.\n"
274
270
"This may take some time. Upgrade the repositories to "
275
"the same format for better performance\\.\n$")
271
"the same format for better performance\\.\n$")
276
272
# and now with it suppressed please
277
273
ui = ui_testing.TextUIFactory()
278
274
ui.suppressed_warnings.add('cross_format_fetch')
279
ui.show_user_warning(
280
'cross_format_fetch', from_format=RepositoryFormat2a(),
275
ui.show_user_warning('cross_format_fetch', from_format=RepositoryFormat2a(),
281
276
to_format=remote_fmt)
282
277
self.assertEqual('', ui.stdout.getvalue())
283
278
self.assertEqual('', ui.stderr.getvalue())
289
284
def test_output_clears_terminal(self):
292
uif = ui_testing.TextUIFactory()
287
uif = ui_testing.TextUIFactory()
293
288
uif.clear_term = lambda: clear_calls.append('clear')
295
stream = _mod_ui_text.TextUIOutputStream(
296
uif, uif.stdout, 'utf-8', 'strict')
290
stream = _mod_ui_text.TextUIOutputStream(uif, uif.stdout, 'utf-8', 'strict')
297
291
stream.write(u"Hello world!\n")
298
292
stream.write(u"there's more...\n")
299
293
stream.writelines([u"1\n", u"2\n", u"3\n"])
301
295
self.assertEqual(uif.stdout.getvalue(),
305
299
self.assertEqual(['clear', 'clear', 'clear'],
316
310
FileStringIO = ui_testing.StringIOWithEncoding
317
311
TTYStringIO = ui_testing.StringIOAsTTY
318
312
for (file_class, term, pb, expected_pb_class) in (
319
# on an xterm, either use them or not as the user requests,
320
# otherwise default on
321
(TTYStringIO, 'xterm', 'none', _mod_ui_text.NullProgressView),
322
(TTYStringIO, 'xterm', 'text', _mod_ui_text.TextProgressView),
323
(TTYStringIO, 'xterm', None, _mod_ui_text.TextProgressView),
324
# on a dumb terminal, again if there's explicit configuration
325
# do it, otherwise default off
326
(TTYStringIO, 'dumb', 'none', _mod_ui_text.NullProgressView),
327
(TTYStringIO, 'dumb', 'text', _mod_ui_text.TextProgressView),
328
(TTYStringIO, 'dumb', None, _mod_ui_text.NullProgressView),
329
# on a non-tty terminal, it's null regardless of $TERM
330
(FileStringIO, 'xterm', None, _mod_ui_text.NullProgressView),
331
(FileStringIO, 'dumb', None, _mod_ui_text.NullProgressView),
332
# however, it can still be forced on
333
(FileStringIO, 'dumb', 'text', _mod_ui_text.TextProgressView),
313
# on an xterm, either use them or not as the user requests,
314
# otherwise default on
315
(TTYStringIO, 'xterm', 'none', _mod_ui_text.NullProgressView),
316
(TTYStringIO, 'xterm', 'text', _mod_ui_text.TextProgressView),
317
(TTYStringIO, 'xterm', None, _mod_ui_text.TextProgressView),
318
# on a dumb terminal, again if there's explicit configuration do
319
# it, otherwise default off
320
(TTYStringIO, 'dumb', 'none', _mod_ui_text.NullProgressView),
321
(TTYStringIO, 'dumb', 'text', _mod_ui_text.TextProgressView),
322
(TTYStringIO, 'dumb', None, _mod_ui_text.NullProgressView),
323
# on a non-tty terminal, it's null regardless of $TERM
324
(FileStringIO, 'xterm', None, _mod_ui_text.NullProgressView),
325
(FileStringIO, 'dumb', None, _mod_ui_text.NullProgressView),
326
# however, it can still be forced on
327
(FileStringIO, 'dumb', 'text', _mod_ui_text.TextProgressView),
335
329
self.overrideEnv('TERM', term)
336
330
self.overrideEnv('BRZ_PROGRESS_BAR', pb)
337
331
stdin = file_class(u'')
338
332
stderr = file_class()
339
333
stdout = file_class()
340
334
uif = _mod_ui.make_ui_for_terminal(stdin, stdout, stderr)
341
self.assertIsInstance(
342
uif, _mod_ui_text.TextUIFactory,
335
self.assertIsInstance(uif, _mod_ui_text.TextUIFactory,
343
336
"TERM=%s BRZ_PROGRESS_BAR=%s uif=%r" % (term, pb, uif,))
344
self.assertIsInstance(
345
uif.make_progress_view(),
337
self.assertIsInstance(uif.make_progress_view(),
346
338
expected_pb_class,
347
339
"TERM=%s BRZ_PROGRESS_BAR=%s uif=%r" % (term, pb, uif,))
476
468
for specific_answer in [True, False]:
477
469
for conf_id in ['given_id', 'other_id']:
478
470
wrapper = _mod_ui.ConfirmationUserInterfacePolicy(
479
base_ui, default_answer,
480
dict(given_id=specific_answer))
481
result = wrapper.confirm_action(
482
"Do something?", conf_id, {})
471
base_ui, default_answer, dict(given_id=specific_answer))
472
result = wrapper.confirm_action("Do something?", conf_id, {})
483
473
if conf_id == 'given_id':
484
474
self.assertEqual(result, specific_answer)