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