99
110
self.assertEqual(None, result)
100
111
self.assertEqual("t\n", stdout.getvalue())
101
112
# Since there was no update() call, there should be no clear() call
102
self.failIf(re.search(r'^\r {10,}\r$', stderr.getvalue()) is not None,
113
self.failIf(re.search(r'^\r {10,}\r$',
114
stderr.getvalue()) is not None,
103
115
'We cleared the stderr without anything to put there')
162
174
def test_text_factory_setting_progress_bar(self):
163
175
# we should be able to choose the progress bar type used.
164
factory = bzrlib.ui.text.TextUIFactory(
165
bar_type=DotsProgressBar)
176
factory = TextUIFactory(bar_type=DotsProgressBar)
166
177
bar = factory.nested_progress_bar()
168
179
self.assertIsInstance(bar, DotsProgressBar)
170
181
def test_cli_stdin_is_default_stdin(self):
171
factory = bzrlib.ui.CLIUIFactory()
182
factory = CLIUIFactory()
172
183
self.assertEqual(sys.stdin, factory.stdin)
174
185
def assert_get_bool_acceptance_of_user_input(self, factory):
175
factory.stdin = StringIO("y\nyes with garbage\nyes\nn\nnot an answer\nno\nfoo\n")
186
factory.stdin = StringIO("y\nyes with garbage\n"
187
"yes\nn\nnot an answer\n"
176
189
factory.stdout = StringIO()
177
190
# there is no output from the base factory
178
191
self.assertEqual(True, factory.get_boolean(""))
180
193
self.assertEqual(False, factory.get_boolean(""))
181
194
self.assertEqual(False, factory.get_boolean(""))
182
195
self.assertEqual("foo\n", factory.stdin.read())
196
# stdin should be empty
197
self.assertEqual('', factory.stdin.readline())
184
199
def test_silent_ui_getbool(self):
185
factory = bzrlib.ui.SilentUIFactory()
200
factory = SilentUIFactory()
186
201
self.assert_get_bool_acceptance_of_user_input(factory)
188
203
def test_silent_factory_prompts_silently(self):
189
factory = bzrlib.ui.SilentUIFactory()
204
factory = SilentUIFactory()
190
205
stdout = StringIO()
191
206
factory.stdin = StringIO("y\n")
194
self.apply_redirected(
195
None, stdout, stdout, factory.get_boolean, "foo")
207
self.assertEqual(True,
208
self.apply_redirected(None, stdout, stdout,
209
factory.get_boolean, "foo"))
197
210
self.assertEqual("", stdout.getvalue())
211
# stdin should be empty
212
self.assertEqual('', factory.stdin.readline())
199
214
def test_text_ui_getbool(self):
200
factory = bzrlib.ui.text.TextUIFactory()
215
factory = TextUIFactory()
201
216
self.assert_get_bool_acceptance_of_user_input(factory)
203
218
def test_text_factory_prompts_and_clears(self):
204
219
# a get_boolean call should clear the pb before prompting
205
factory = bzrlib.ui.text.TextUIFactory(bar_type=DotsProgressBar)
220
factory = TextUIFactory(bar_type=DotsProgressBar)
206
221
factory.stdout = _TTYStringIO()
207
222
factory.stdin = StringIO("yada\ny\n")
208
pb = self.apply_redirected(
209
factory.stdin, factory.stdout, factory.stdout, factory.nested_progress_bar)
223
pb = self.apply_redirected(factory.stdin, factory.stdout,
224
factory.stdout, factory.nested_progress_bar)
210
225
pb.start_time = None
211
self.apply_redirected(
212
factory.stdin, factory.stdout, factory.stdout, pb.update, "foo", 0, 1)
215
self.apply_redirected(
216
None, factory.stdout, factory.stdout, factory.get_boolean, "what do you want")
226
self.apply_redirected(factory.stdin, factory.stdout,
227
factory.stdout, pb.update, "foo", 0, 1)
228
self.assertEqual(True,
229
self.apply_redirected(None, factory.stdout,
218
233
output = factory.stdout.getvalue()
219
234
self.assertEqual("foo: .\n"
220
235
"what do you want? [y/n]: what do you want? [y/n]: ",
221
236
factory.stdout.getvalue())
237
# stdin should be empty
238
self.assertEqual('', factory.stdin.readline())