259
262
ui = ui_testing.TextUIFactory()
260
263
remote_fmt = remote.RemoteRepositoryFormat()
261
264
remote_fmt._network_name = RepositoryFormatKnitPack5().network_name()
262
ui.show_user_warning('cross_format_fetch', from_format=RepositoryFormat2a(),
265
ui.show_user_warning(
266
'cross_format_fetch', from_format=RepositoryFormat2a(),
263
267
to_format=remote_fmt)
264
268
self.assertEqual('', ui.stdout.getvalue())
265
269
self.assertContainsRe(
266
270
ui.stderr.getvalue(),
267
271
"^Doing on-the-fly conversion from RepositoryFormat2a\\(\\) to "
268
"RemoteRepositoryFormat\\(_network_name="
269
"b?'Bazaar RepositoryFormatKnitPack5 \\(bzr 1.6\\)\\\\n'\\)\\.\n"
272
"RemoteRepositoryFormat\\(_network_name="
273
"b?'Bazaar RepositoryFormatKnitPack5 \\(bzr 1.6\\)\\\\n'\\)\\.\n"
270
274
"This may take some time. Upgrade the repositories to "
271
"the same format for better performance\\.\n$")
275
"the same format for better performance\\.\n$")
272
276
# and now with it suppressed please
273
277
ui = ui_testing.TextUIFactory()
274
278
ui.suppressed_warnings.add('cross_format_fetch')
275
ui.show_user_warning('cross_format_fetch', from_format=RepositoryFormat2a(),
279
ui.show_user_warning(
280
'cross_format_fetch', from_format=RepositoryFormat2a(),
276
281
to_format=remote_fmt)
277
282
self.assertEqual('', ui.stdout.getvalue())
278
283
self.assertEqual('', ui.stderr.getvalue())
284
289
def test_output_clears_terminal(self):
287
uif = ui_testing.TextUIFactory()
292
uif = ui_testing.TextUIFactory()
288
293
uif.clear_term = lambda: clear_calls.append('clear')
290
stream = _mod_ui_text.TextUIOutputStream(uif, uif.stdout, 'utf-8', 'strict')
295
stream = _mod_ui_text.TextUIOutputStream(
296
uif, uif.stdout, 'utf-8', 'strict')
291
297
stream.write(u"Hello world!\n")
292
298
stream.write(u"there's more...\n")
293
299
stream.writelines([u"1\n", u"2\n", u"3\n"])
295
301
self.assertEqual(uif.stdout.getvalue(),
299
305
self.assertEqual(['clear', 'clear', 'clear'],
310
316
FileStringIO = ui_testing.StringIOWithEncoding
311
317
TTYStringIO = ui_testing.StringIOAsTTY
312
318
for (file_class, term, pb, expected_pb_class) in (
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),
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),
329
335
self.overrideEnv('TERM', term)
330
336
self.overrideEnv('BRZ_PROGRESS_BAR', pb)
331
337
stdin = file_class(u'')
332
338
stderr = file_class()
333
339
stdout = file_class()
334
340
uif = _mod_ui.make_ui_for_terminal(stdin, stdout, stderr)
335
self.assertIsInstance(uif, _mod_ui_text.TextUIFactory,
341
self.assertIsInstance(
342
uif, _mod_ui_text.TextUIFactory,
336
343
"TERM=%s BRZ_PROGRESS_BAR=%s uif=%r" % (term, pb, uif,))
337
self.assertIsInstance(uif.make_progress_view(),
344
self.assertIsInstance(
345
uif.make_progress_view(),
338
346
expected_pb_class,
339
347
"TERM=%s BRZ_PROGRESS_BAR=%s uif=%r" % (term, pb, uif,))
468
476
for specific_answer in [True, False]:
469
477
for conf_id in ['given_id', 'other_id']:
470
478
wrapper = _mod_ui.ConfirmationUserInterfacePolicy(
471
base_ui, default_answer, dict(given_id=specific_answer))
472
result = wrapper.confirm_action("Do something?", conf_id, {})
479
base_ui, default_answer,
480
dict(given_id=specific_answer))
481
result = wrapper.confirm_action(
482
"Do something?", conf_id, {})
473
483
if conf_id == 'given_id':
474
484
self.assertEqual(result, specific_answer)