~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_uifactory/__init__.py

merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2009, 2010, 2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
62
62
        self.factory.be_quiet(False)
63
63
        self.assertEquals(False, self.factory.is_quiet())
64
64
 
 
65
    def test_confirm_action(self):
 
66
        # confirm_action should be answered by every ui factory; even
 
67
        # noninteractive ones should have a reasonable default
 
68
        self._load_responses([True])
 
69
        result = self.factory.confirm_action(
 
70
            'Break a lock?',
 
71
            'bzr.lock.break.confirm',
 
72
            {})
 
73
        # will be true either because we read it from the input or because
 
74
        # that's the default
 
75
        self.assertEquals(result, True)
 
76
 
65
77
    def test_note(self):
66
78
        self.factory.note("a note to the user")
67
79
        self._check_note("a note to the user")
150
162
        # Without a TTY, we shouldn't display anything
151
163
        self.assertEqual('', self.stderr.getvalue())
152
164
 
 
165
    def _load_responses(self, responses):
 
166
        self.factory.stdin.seek(0)
 
167
        self.factory.stdin.writelines([(r and "y\n" or "n\n") for r in responses])
 
168
        self.factory.stdin.seek(0)
 
169
 
153
170
 
154
171
class TestTTYTextUIFactory(TestTextUIFactory):
155
172
 
173
190
 
174
191
        # Remove 'TERM' == 'dumb' which causes us to *not* treat output as a
175
192
        # real terminal, even though isatty returns True
176
 
        self._captureVar('TERM', None)
 
193
        self.overrideEnv('TERM', None)
177
194
        self.stderr = TTYStringIO()
178
195
        self.stdout = TTYStringIO()
179
196
        self.factory = ui.text.TextUIFactory(self.stdin, self.stdout,
222
239
    def _check_log_transport_activity_display_no_bytes(self):
223
240
        pass
224
241
 
 
242
    def _load_responses(self, responses):
 
243
        pass
 
244
 
225
245
 
226
246
class TestCannedInputUIFactory(tests.TestCase, UIFactoryTestMixin):
227
247
    # discards output, reads input from variables
250
270
 
251
271
    def _check_log_transport_activity_display_no_bytes(self):
252
272
        pass
 
273
 
 
274
    def _load_responses(self, responses):
 
275
        self.factory.responses.extend(responses)