~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-09-01 08:02:42 UTC
  • mfrom: (5390.3.3 faster-revert-593560)
  • Revision ID: pqm@pqm.ubuntu.com-20100901080242-esg62ody4frwmy66
(spiv) Avoid repeatedly calling self.target.all_file_ids() in
 InterTree.iter_changes. (Andrew Bennetts)

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
 
 
148
103
    def test_text_ui_get_boolean(self):
149
104
        stdin = tests.StringIOWrapper("y\n" # True
150
105
                                      "n\n" # False
193
148
        factory = _mod_ui_text.TextUIFactory(
194
149
            stdin=tests.StringIOWrapper("yada\ny\n"),
195
150
            stdout=out, stderr=out)
 
151
        factory._avail_width = lambda: 79
196
152
        pb = factory.nested_progress_bar()
197
153
        pb.show_bar = False
198
154
        pb.show_spinner = False
204
160
                                               factory.get_boolean,
205
161
                                               "what do you want"))
206
162
        output = out.getvalue()
207
 
        self.assertContainsRe(factory.stdout.getvalue(),
208
 
            "foo *\r\r  *\r*")
209
 
        self.assertContainsRe(factory.stdout.getvalue(),
 
163
        self.assertContainsRe(output,
 
164
            "| foo *\r\r  *\r*")
 
165
        self.assertContainsRe(output,
210
166
            r"what do you want\? \[y/n\]: what do you want\? \[y/n\]: ")
211
167
        # stdin should have been totally consumed
212
168
        self.assertEqual('', factory.stdin.readline())