116
115
bar = factory.nested_progress_bar()
118
117
self.assertIsInstance(bar, bzrlib.progress.DotsProgressBar)
119
def test_cli_stdin_is_default_stdin(self):
120
factory = bzrlib.ui.CLIUIFactory()
121
self.assertEqual(sys.stdin, factory.stdin)
123
def assert_get_bool_acceptance_of_user_input(self, factory):
124
factory.stdin = StringIO("y\nyes with garbage\nyes\nn\nnot an answer\nno\nfoo\n")
125
factory.stdout = StringIO()
126
# there is no output from the base factory
127
self.assertEqual(True, factory.get_boolean(""))
128
self.assertEqual(True, factory.get_boolean(""))
129
self.assertEqual(False, factory.get_boolean(""))
130
self.assertEqual(False, factory.get_boolean(""))
131
self.assertEqual("foo\n", factory.stdin.read())
133
def test_silent_ui_getbool(self):
134
factory = bzrlib.ui.SilentUIFactory()
135
self.assert_get_bool_acceptance_of_user_input(factory)
137
def test_silent_factory_prompts_silently(self):
138
factory = bzrlib.ui.SilentUIFactory()
140
factory.stdin = StringIO("y\n")
143
self.apply_redirected(
144
None, stdout, stdout, factory.get_boolean, "foo")
146
self.assertEqual("", stdout.getvalue())
148
def test_text_ui_getbool(self):
149
factory = bzrlib.ui.text.TextUIFactory()
150
self.assert_get_bool_acceptance_of_user_input(factory)
152
def test_text_factory_prompts_and_clears(self):
153
# a get_boolean call should clear the pb before prompting
154
factory = bzrlib.ui.text.TextUIFactory()
155
factory.stdout = StringIO()
156
factory.stdin = StringIO("yada\ny\n")
157
pb = self.apply_redirected(
158
factory.stdin, factory.stdout, factory.stdout, factory.nested_progress_bar)
159
self.apply_redirected(
160
factory.stdin, factory.stdout, factory.stdout, pb.update, "foo", 0, 1)
163
self.apply_redirected(
164
None, factory.stdout, factory.stdout, factory.get_boolean, "what do you want")
169
"\rwhat do you want? [y/n]:what do you want? [y/n]:", factory.stdout.getvalue())