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
103
def test_progress_note(self):
154
104
stderr = StringIO()
155
105
stdout = StringIO()
254
class UITests(tests.TestCase):
256
def test_progress_construction(self):
257
"""TextUIFactory constructs the right progress view.
259
for (file_class, term, pb, expected_pb_class) in (
260
# on an xterm, either use them or not as the user requests,
261
# otherwise default on
262
(_TTYStringIO, 'xterm', 'none', NullProgressView),
263
(_TTYStringIO, 'xterm', 'text', TextProgressView),
264
(_TTYStringIO, 'xterm', None, TextProgressView),
265
# on a dumb terminal, again if there's explicit configuration do
266
# it, otherwise default off
267
(_TTYStringIO, 'dumb', 'none', NullProgressView),
268
(_TTYStringIO, 'dumb', 'text', TextProgressView),
269
(_TTYStringIO, 'dumb', None, NullProgressView),
270
# on a non-tty terminal, it's null regardless of $TERM
271
(StringIO, 'xterm', None, NullProgressView),
272
(StringIO, 'dumb', None, NullProgressView),
273
# however, it can still be forced on
274
(StringIO, 'dumb', 'text', TextProgressView),
276
os.environ['TERM'] = term
278
if 'BZR_PROGRESS_BAR' in os.environ:
279
del os.environ['BZR_PROGRESS_BAR']
281
os.environ['BZR_PROGRESS_BAR'] = pb
282
stdin = file_class('')
283
stderr = file_class()
284
stdout = file_class()
285
uif = make_ui_for_terminal(stdin, stdout, stderr)
286
self.assertIsInstance(uif, TextUIFactory,
287
"TERM=%s BZR_PROGRESS_BAR=%s uif=%r" % (term, pb, uif,))
288
self.assertIsInstance(uif.make_progress_view(),
290
"TERM=%s BZR_PROGRESS_BAR=%s uif=%r" % (term, pb, uif,))
292
def test_text_ui_non_terminal(self):
293
"""Even on non-ttys, make_ui_for_terminal gives a text ui."""
294
stdin = _NonTTYStringIO('')
295
stderr = _NonTTYStringIO()
296
stdout = _NonTTYStringIO()
297
for term_type in ['dumb', None, 'xterm']:
298
if term_type is None:
299
del os.environ['TERM']
301
os.environ['TERM'] = term_type
302
uif = make_ui_for_terminal(stdin, stdout, stderr)
303
self.assertIsInstance(uif, TextUIFactory,
304
'TERM=%r' % (term_type,))
304
307
class CLIUITests(TestCase):
306
309
def test_cli_factory_deprecated(self):