~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_controldir.py

  • Committer: Jelmer Vernooij
  • Date: 2011-05-10 07:46:15 UTC
  • mfrom: (5844 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5845.
  • Revision ID: jelmer@samba.org-20110510074615-eptod049ndjxc4i7
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
    controldir,
24
24
    errors,
25
25
    tests,
 
26
    ui,
26
27
    )
27
28
from bzrlib.tests.scenarios import load_tests_apply_scenarios
28
29
 
180
181
                break
181
182
        else:
182
183
            self.fail("No NotBzrDirFormat in %s" % formats)
 
184
 
 
185
 
 
186
class UnsupportedControlComponentFormat(controldir.ControlComponentFormat):
 
187
 
 
188
    def is_supported(self):
 
189
        return False
 
190
 
 
191
 
 
192
class OldControlComponentFormat(controldir.ControlComponentFormat):
 
193
 
 
194
    def get_format_description(self):
 
195
        return "An old format that is slow"
 
196
 
 
197
    upgrade_recommended = True
 
198
 
 
199
 
 
200
class DefaultControlComponentFormatTests(tests.TestCase):
 
201
    """Tests for default ControlComponentFormat implementation."""
 
202
 
 
203
    def test_check_support_status_unsupported(self):
 
204
        self.assertRaises(errors.UnsupportedFormatError,
 
205
            UnsupportedControlComponentFormat().check_support_status,
 
206
            allow_unsupported=False)
 
207
        UnsupportedControlComponentFormat().check_support_status(
 
208
            allow_unsupported=True)
 
209
 
 
210
    def test_check_support_status_supported(self):
 
211
        controldir.ControlComponentFormat().check_support_status(
 
212
            allow_unsupported=False)
 
213
        controldir.ControlComponentFormat().check_support_status(
 
214
            allow_unsupported=True)
 
215
 
 
216
    def test_recommend_upgrade_current_format(self):
 
217
        stderr = tests.StringIOWrapper()
 
218
        ui.ui_factory = tests.TestUIFactory(stderr=stderr)
 
219
        format = controldir.ControlComponentFormat()
 
220
        format.check_support_status(allow_unsupported=False,
 
221
            recommend_upgrade=True)
 
222
        self.assertEquals("", stderr.getvalue())
 
223
 
 
224
    def test_recommend_upgrade_old_format(self):
 
225
        stderr = tests.StringIOWrapper()
 
226
        ui.ui_factory = tests.TestUIFactory(stderr=stderr)
 
227
        format = OldControlComponentFormat()
 
228
        format.check_support_status(allow_unsupported=False,
 
229
            recommend_upgrade=False)
 
230
        self.assertEquals("", stderr.getvalue())
 
231
        format.check_support_status(allow_unsupported=False,
 
232
            recommend_upgrade=True, basedir='apath')
 
233
        self.assertEquals(
 
234
            'An old format that is slow is deprecated and a better format '
 
235
            'is available.\nIt is recommended that you upgrade by running '
 
236
            'the command\n  bzr upgrade apath\n',
 
237
            stderr.getvalue())