~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_ui.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-05-05 08:29:29 UTC
  • mfrom: (1697.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060505082929-a037ee137f1ff240
Merge break-lock command.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
class UITests(TestCase):
33
33
 
34
34
    def test_silent_factory(self):
35
 
 
36
35
        ui = SilentUIFactory()
37
36
        pb = ui.nested_progress_bar()
38
37
        try:
116
115
        bar = factory.nested_progress_bar()
117
116
        bar.finished()
118
117
        self.assertIsInstance(bar, bzrlib.progress.DotsProgressBar)
 
118
 
 
119
    def test_cli_stdin_is_default_stdin(self):
 
120
        factory = bzrlib.ui.CLIUIFactory()
 
121
        self.assertEqual(sys.stdin, factory.stdin)
 
122
 
 
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())
 
132
 
 
133
    def test_silent_ui_getbool(self):
 
134
        factory = bzrlib.ui.SilentUIFactory()
 
135
        self.assert_get_bool_acceptance_of_user_input(factory)
 
136
 
 
137
    def test_silent_factory_prompts_silently(self):
 
138
        factory = bzrlib.ui.SilentUIFactory()
 
139
        stdout = StringIO()
 
140
        factory.stdin = StringIO("y\n")
 
141
        self.assertEqual(
 
142
            True,
 
143
            self.apply_redirected(
 
144
                None, stdout, stdout, factory.get_boolean, "foo")
 
145
            )
 
146
        self.assertEqual("", stdout.getvalue())
 
147
        
 
148
    def test_text_ui_getbool(self):
 
149
        factory = bzrlib.ui.text.TextUIFactory()
 
150
        self.assert_get_bool_acceptance_of_user_input(factory)
 
151
 
 
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)
 
161
        self.assertEqual(
 
162
            True,
 
163
            self.apply_redirected(
 
164
                None, factory.stdout, factory.stdout, factory.get_boolean, "what do you want")
 
165
            )
 
166
        self.assertEqual(
 
167
            "\r/ [                                                                   ] foo 0/1"
 
168
            "\r                                                                               "
 
169
            "\rwhat do you want? [y/n]:what do you want? [y/n]:", factory.stdout.getvalue())