/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_controldir.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2011, 2016 Canonical Ltd
 
1
# Copyright (C) 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
19
19
For interface contract tests, see tests/per_control_dir.
20
20
"""
21
21
 
22
 
from .. import (
 
22
from bzrlib import (
23
23
    controldir,
24
24
    errors,
25
25
    tests,
26
26
    ui,
27
27
    )
28
 
from .scenarios import load_tests_apply_scenarios
 
28
from bzrlib.tests.scenarios import load_tests_apply_scenarios
29
29
 
30
30
 
31
31
load_tests = load_tests_apply_scenarios
32
32
 
33
33
 
34
 
class TestErrors(tests.TestCase):
35
 
 
36
 
    def test_must_have_working_tree(self):
37
 
        err = controldir.MustHaveWorkingTree('foo', 'bar')
38
 
        self.assertEqual(str(err), "Branching 'bar'(foo) must create a"
39
 
                                   " working tree.")
40
 
 
41
 
 
42
34
class SampleComponentFormat(controldir.ControlComponentFormat):
43
35
 
44
36
    def get_format_string(self):
45
 
        return b"Example component format."
 
37
        return "Example component format."
46
38
 
47
39
 
48
40
class SampleExtraComponentFormat(controldir.ControlComponentFormat):
58
50
    def test_register_unregister_format(self):
59
51
        format = SampleComponentFormat()
60
52
        self.registry.register(format)
61
 
        self.assertEqual(format,
62
 
            self.registry.get(b"Example component format."))
 
53
        self.assertEquals(format,
 
54
            self.registry.get("Example component format."))
63
55
        self.registry.remove(format)
64
56
        self.assertRaises(KeyError, self.registry.get,
65
 
            b"Example component format.")
 
57
            "Example component format.")
66
58
 
67
59
    def test_get_all(self):
68
60
        format = SampleComponentFormat()
69
 
        self.assertEqual([], self.registry._get_all())
 
61
        self.assertEquals([], self.registry._get_all())
70
62
        self.registry.register(format)
71
 
        self.assertEqual([format], self.registry._get_all())
 
63
        self.assertEquals([format], self.registry._get_all())
72
64
 
73
65
    def test_get_all_modules(self):
74
66
        format = SampleComponentFormat()
75
 
        self.assertEqual(set(), self.registry._get_all_modules())
 
67
        self.assertEquals(set(), self.registry._get_all_modules())
76
68
        self.registry.register(format)
77
 
        self.assertEqual(
78
 
            {"breezy.tests.test_controldir"},
 
69
        self.assertEquals(
 
70
            set(["bzrlib.tests.test_controldir"]),
79
71
            self.registry._get_all_modules())
80
72
 
81
73
    def test_register_extra(self):
82
74
        format = SampleExtraComponentFormat()
83
 
        self.assertEqual([], self.registry._get_all())
 
75
        self.assertEquals([], self.registry._get_all())
84
76
        self.registry.register_extra(format)
85
 
        self.assertEqual([format], self.registry._get_all())
 
77
        self.assertEquals([format], self.registry._get_all())
86
78
 
87
79
    def test_register_extra_lazy(self):
88
 
        self.assertEqual([], self.registry._get_all())
89
 
        self.registry.register_extra_lazy("breezy.tests.test_controldir",
 
80
        self.assertEquals([], self.registry._get_all())
 
81
        self.registry.register_extra_lazy("bzrlib.tests.test_controldir",
90
82
            "SampleExtraComponentFormat")
91
83
        formats = self.registry._get_all()
92
 
        self.assertEqual(1, len(formats))
 
84
        self.assertEquals(1, len(formats))
93
85
        self.assertIsInstance(formats[0], SampleExtraComponentFormat)
94
86
 
95
87
 
 
88
class TestControlDirFormatDeprecated(tests.TestCaseWithTransport):
 
89
    """Tests for removed registration method in the ControlDirFormat facility."""
 
90
 
 
91
    def test_register_format(self):
 
92
        self.assertRaises(errors.BzrError,
 
93
            controldir.ControlDirFormat.register_format, object())
 
94
 
 
95
 
96
96
class TestProber(tests.TestCaseWithTransport):
97
97
    """Per-prober tests."""
98
98
 
148
148
 
149
149
    @classmethod
150
150
    def known_formats(cls):
151
 
        return {NotBzrDirFormat()}
 
151
        return set([NotBzrDirFormat()])
152
152
 
153
153
 
154
154
class TestNotBzrDir(tests.TestCaseWithTransport):
214
214
            allow_unsupported=True)
215
215
 
216
216
    def test_recommend_upgrade_current_format(self):
217
 
        ui.ui_factory = tests.TestUIFactory()
 
217
        stderr = tests.StringIOWrapper()
 
218
        ui.ui_factory = tests.TestUIFactory(stderr=stderr)
218
219
        format = controldir.ControlComponentFormat()
219
220
        format.check_support_status(allow_unsupported=False,
220
221
            recommend_upgrade=True)
221
 
        self.assertEqual("", ui.ui_factory.stderr.getvalue())
 
222
        self.assertEquals("", stderr.getvalue())
222
223
 
223
224
    def test_recommend_upgrade_old_format(self):
224
 
        ui.ui_factory = tests.TestUIFactory()
 
225
        stderr = tests.StringIOWrapper()
 
226
        ui.ui_factory = tests.TestUIFactory(stderr=stderr)
225
227
        format = OldControlComponentFormat()
226
228
        format.check_support_status(allow_unsupported=False,
227
229
            recommend_upgrade=False)
228
 
        self.assertEqual("", ui.ui_factory.stderr.getvalue())
 
230
        self.assertEquals("", stderr.getvalue())
229
231
        format.check_support_status(allow_unsupported=False,
230
232
            recommend_upgrade=True, basedir='apath')
231
 
        self.assertEqual(
 
233
        self.assertEquals(
232
234
            'An old format that is slow is deprecated and a better format '
233
235
            'is available.\nIt is recommended that you upgrade by running '
234
 
            'the command\n  brz upgrade apath\n',
235
 
            ui.ui_factory.stderr.getvalue())
236
 
 
237
 
 
238
 
class IsControlFilenameTest(tests.TestCase):
239
 
 
240
 
    def test_is_bzrdir(self):
241
 
        self.assertTrue(controldir.is_control_filename('.bzr'))
242
 
 
243
 
    def test_is_not_bzrdir(self):
244
 
        self.assertFalse(controldir.is_control_filename('.git'))
245
 
        self.assertFalse(controldir.is_control_filename('bla'))
 
236
            'the command\n  bzr upgrade apath\n',
 
237
            stderr.getvalue())