~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2010-09-09 07:49:00 UTC
  • mto: This revision was merged to the branch mainline in revision 5426.
  • Revision ID: mbp@sourcefrog.net-20100909074900-c45pkc029ax9as26
Use a structured ui_factory.confirm_action rather than just get_boolean

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
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)