~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: 2010-07-16 14:02:58 UTC
  • mfrom: (5346.2.3 doc)
  • Revision ID: pqm@pqm.ubuntu.com-20100716140258-js1p8i24w8nodz6t
(mbp) developer docs about transports and symlinks (Martin Pool)

Show diffs side-by-side

added added

removed removed

Lines of Context:
100
100
        finally:
101
101
            pb.finished()
102
102
 
 
103
    def test_progress_note(self):
 
104
        stderr = tests.StringIOWrapper()
 
105
        stdout = tests.StringIOWrapper()
 
106
        ui_factory = _mod_ui_text.TextUIFactory(stdin=tests.StringIOWrapper(''),
 
107
                                                stderr=stderr,
 
108
                                                stdout=stdout)
 
109
        pb = ui_factory.nested_progress_bar()
 
110
        try:
 
111
            result = self.applyDeprecated(deprecated_in((2, 1, 0)),
 
112
                pb.note,
 
113
                't')
 
114
            self.assertEqual(None, result)
 
115
            self.assertEqual("t\n", stdout.getvalue())
 
116
            # Since there was no update() call, there should be no clear() call
 
117
            self.failIf(re.search(r'^\r {10,}\r$',
 
118
                                  stderr.getvalue()) is not None,
 
119
                        'We cleared the stderr without anything to put there')
 
120
        finally:
 
121
            pb.finished()
 
122
 
 
123
    def test_progress_note_clears(self):
 
124
        stderr = test_progress._TTYStringIO()
 
125
        stdout = test_progress._TTYStringIO()
 
126
        # so that we get a TextProgressBar
 
127
        os.environ['TERM'] = 'xterm'
 
128
        ui_factory = _mod_ui_text.TextUIFactory(
 
129
            stdin=tests.StringIOWrapper(''),
 
130
            stdout=stdout, stderr=stderr)
 
131
        self.assertIsInstance(ui_factory._progress_view,
 
132
                              _mod_ui_text.TextProgressView)
 
133
        pb = ui_factory.nested_progress_bar()
 
134
        try:
 
135
            # Create a progress update that isn't throttled
 
136
            pb.update('x', 1, 1)
 
137
            result = self.applyDeprecated(deprecated_in((2, 1, 0)),
 
138
                pb.note, 't')
 
139
            self.assertEqual(None, result)
 
140
            self.assertEqual("t\n", stdout.getvalue())
 
141
            # the exact contents will depend on the terminal width and we don't
 
142
            # care about that right now - but you're probably running it on at
 
143
            # least a 10-character wide terminal :)
 
144
            self.assertContainsRe(stderr.getvalue(), r'\r {10,}\r$')
 
145
        finally:
 
146
            pb.finished()
 
147
 
103
148
    def test_text_ui_get_boolean(self):
104
149
        stdin = tests.StringIOWrapper("y\n" # True
105
150
                                      "n\n" # False
148
193
        factory = _mod_ui_text.TextUIFactory(
149
194
            stdin=tests.StringIOWrapper("yada\ny\n"),
150
195
            stdout=out, stderr=out)
151
 
        factory._avail_width = lambda: 79
152
196
        pb = factory.nested_progress_bar()
153
197
        pb.show_bar = False
154
198
        pb.show_spinner = False
160
204
                                               factory.get_boolean,
161
205
                                               "what do you want"))
162
206
        output = out.getvalue()
163
 
        self.assertContainsRe(output,
164
 
            "| foo *\r\r  *\r*")
165
 
        self.assertContainsRe(output,
 
207
        self.assertContainsRe(factory.stdout.getvalue(),
 
208
            "foo *\r\r  *\r*")
 
209
        self.assertContainsRe(factory.stdout.getvalue(),
166
210
            r"what do you want\? \[y/n\]: what do you want\? \[y/n\]: ")
167
211
        # stdin should have been totally consumed
168
212
        self.assertEqual('', factory.stdin.readline())