103
def test_progress_construction(self):
104
"""TextUIFactory constructs the right progress view.
106
for (file_class, term, pb, expected_pb_class) in (
107
# on an xterm, either use them or not as the user requests,
108
# otherwise default on
109
(_TTYStringIO, 'xterm', 'none', NullProgressView),
110
(_TTYStringIO, 'xterm', 'text', TextProgressView),
111
(_TTYStringIO, 'xterm', None, TextProgressView),
112
# on a dumb terminal, again if there's explicit configuration do
113
# it, otherwise default off
114
(_TTYStringIO, 'dumb', 'none', NullProgressView),
115
(_TTYStringIO, 'dumb', 'text', TextProgressView),
116
(_TTYStringIO, 'dumb', None, NullProgressView),
117
# on a non-tty terminal, it's null regardless of $TERM
118
(StringIO, 'xterm', None, NullProgressView),
119
(StringIO, 'dumb', None, NullProgressView),
120
# however, it can still be forced on
121
(StringIO, 'dumb', 'text', TextProgressView),
123
os.environ['TERM'] = term
125
if 'BZR_PROGRESS_BAR' in os.environ:
126
del os.environ['BZR_PROGRESS_BAR']
128
os.environ['BZR_PROGRESS_BAR'] = pb
129
stdin = file_class('')
130
stderr = file_class()
131
stdout = file_class()
132
uif = make_ui_for_terminal(stdin, stdout, stderr)
133
self.assertIsInstance(uif, TextUIFactory,
134
"TERM=%s BZR_PROGRESS_BAR=%s uif=%r" % (term, pb, uif,))
135
self.assertIsInstance(uif.make_progress_view(),
137
"TERM=%s BZR_PROGRESS_BAR=%s uif=%r" % (term, pb, uif,))
139
def test_text_ui_non_terminal(self):
140
"""Even on non-ttys, make_ui_for_terminal gives a text ui."""
141
stdin = _NonTTYStringIO('')
142
stderr = _NonTTYStringIO()
143
stdout = _NonTTYStringIO()
144
for term_type in ['dumb', None, 'xterm']:
145
if term_type is None:
146
del os.environ['TERM']
148
os.environ['TERM'] = term_type
149
uif = make_ui_for_terminal(stdin, stdout, stderr)
150
self.assertIsInstance(uif, TextUIFactory,
151
'TERM=%r' % (term_type,))
153
102
def test_progress_note(self):
154
103
stderr = StringIO()
155
104
stdout = StringIO()
307
class CLIUITests(TestCase):
309
def test_cli_factory_deprecated(self):
310
uif = self.applyDeprecated(deprecated_in((1, 18, 0)),
312
StringIO(), StringIO(), StringIO())
313
self.assertIsInstance(uif, UIFactory)
256
class UITests(tests.TestCase):
258
def test_progress_construction(self):
259
"""TextUIFactory constructs the right progress view.
261
for (file_class, term, pb, expected_pb_class) in (
262
# on an xterm, either use them or not as the user requests,
263
# otherwise default on
264
(_TTYStringIO, 'xterm', 'none', NullProgressView),
265
(_TTYStringIO, 'xterm', 'text', TextProgressView),
266
(_TTYStringIO, 'xterm', None, TextProgressView),
267
# on a dumb terminal, again if there's explicit configuration do
268
# it, otherwise default off
269
(_TTYStringIO, 'dumb', 'none', NullProgressView),
270
(_TTYStringIO, 'dumb', 'text', TextProgressView),
271
(_TTYStringIO, 'dumb', None, NullProgressView),
272
# on a non-tty terminal, it's null regardless of $TERM
273
(StringIO, 'xterm', None, NullProgressView),
274
(StringIO, 'dumb', None, NullProgressView),
275
# however, it can still be forced on
276
(StringIO, 'dumb', 'text', TextProgressView),
278
os.environ['TERM'] = term
280
if 'BZR_PROGRESS_BAR' in os.environ:
281
del os.environ['BZR_PROGRESS_BAR']
283
os.environ['BZR_PROGRESS_BAR'] = pb
284
stdin = file_class('')
285
stderr = file_class()
286
stdout = file_class()
287
uif = make_ui_for_terminal(stdin, stdout, stderr)
288
self.assertIsInstance(uif, TextUIFactory,
289
"TERM=%s BZR_PROGRESS_BAR=%s uif=%r" % (term, pb, uif,))
290
self.assertIsInstance(uif.make_progress_view(),
292
"TERM=%s BZR_PROGRESS_BAR=%s uif=%r" % (term, pb, uif,))
294
def test_text_ui_non_terminal(self):
295
"""Even on non-ttys, make_ui_for_terminal gives a text ui."""
296
stdin = _NonTTYStringIO('')
297
stderr = _NonTTYStringIO()
298
stdout = _NonTTYStringIO()
299
for term_type in ['dumb', None, 'xterm']:
300
if term_type is None:
301
del os.environ['TERM']
303
os.environ['TERM'] = term_type
304
uif = make_ui_for_terminal(stdin, stdout, stderr)
305
self.assertIsInstance(uif, TextUIFactory,
306
'TERM=%r' % (term_type,))
316
309
class SilentUITests(TestCase):