/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: Jelmer Vernooij
  • Date: 2011-03-11 15:36:12 UTC
  • mfrom: (5712.4.8 bzrdir-weave)
  • mto: This revision was merged to the branch mainline in revision 5718.
  • Revision ID: jelmer@samba.org-20110311153612-7xniucwst6rrjshk
merge bzrdir-weave.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
from bzrlib import (
23
23
    controldir,
 
24
    errors,
24
25
    tests,
25
26
    )
 
27
from bzrlib.tests.scenarios import load_tests_apply_scenarios
 
28
 
 
29
 
 
30
load_tests = load_tests_apply_scenarios
26
31
 
27
32
 
28
33
class SampleComponentFormat(controldir.ControlComponentFormat):
79
84
        self.assertIsInstance(formats[0], SampleExtraComponentFormat)
80
85
 
81
86
 
82
 
class ControlDirFormatTest1(controldir.ControlDirFormat):
83
 
    """A test control dir format."""
84
 
 
85
 
 
86
 
class TestControlDirFormat(tests.TestCaseWithTransport):
87
 
    """Tests for the ControlDirFormat facility."""
88
 
 
89
 
    def test_register_unregister_format(self):
90
 
        format = ControlDirFormatTest1()
91
 
        controldir.ControlDirFormat.register_format(format)
92
 
        self.assertTrue(format in controldir.ControlDirFormat.known_formats())
93
 
        controldir.ControlDirFormat.unregister_format(format)
94
 
        self.assertFalse(format in controldir.ControlDirFormat.known_formats())
95
 
 
96
 
    def test_register_unregister_format_lazy(self):
97
 
        controldir.ControlDirFormat.register_lazy_format(
98
 
            "bzrlib.tests.test_controldir", "ControlDirFormatTest1")
99
 
        self.assertTrue(
100
 
            ControlDirFormatTest1 in
101
 
            controldir.ControlDirFormat.known_formats())
102
 
        controldir.ControlDirFormat.unregister_lazy_format(
103
 
            "bzrlib.tests.test_controldir", "ControlDirFormatTest1")
104
 
        self.assertFalse(
105
 
            ControlDirFormatTest1 in
106
 
            controldir.ControlDirFormat.known_formats())
 
87
class TestControlDirFormatDeprecated(tests.TestCaseWithTransport):
 
88
    """Tests for removed registration method in the ControlDirFormat facility."""
 
89
 
 
90
    def test_register_format(self):
 
91
        self.assertRaises(errors.BzrError,
 
92
            controldir.ControlDirFormat.register_format, object())
 
93
 
 
94
 
 
95
class TestProber(tests.TestCaseWithTransport):
 
96
    """Per-prober tests."""
 
97
 
 
98
    scenarios = [
 
99
        (prober_cls.__name__, {'prober_cls': prober_cls})
 
100
        for prober_cls in controldir.ControlDirFormat._probers]
 
101
 
 
102
    def setUp(self):
 
103
        super(TestProber, self).setUp()
 
104
        self.prober = self.prober_cls()
 
105
 
 
106
    def test_probe_transport_empty(self):
 
107
        transport = self.get_transport(".")
 
108
        self.assertRaises(errors.NotBranchError,
 
109
            self.prober.probe_transport, transport)
 
110
 
 
111
    def test_known_formats(self):
 
112
        known_formats = self.prober_cls.known_formats()
 
113
        self.assertIsInstance(known_formats, set)
 
114
        for format in known_formats:
 
115
            self.assertIsInstance(format, controldir.ControlDirFormat,
 
116
                repr(format))
 
117
 
 
118
 
 
119
class NotBzrDir(controldir.ControlDir):
 
120
    """A non .bzr based control directory."""
 
121
 
 
122
    def __init__(self, transport, format):
 
123
        self._format = format
 
124
        self.root_transport = transport
 
125
        self.transport = transport.clone('.not')
 
126
 
 
127
 
 
128
class NotBzrDirFormat(controldir.ControlDirFormat):
 
129
    """A test class representing any non-.bzr based disk format."""
 
130
 
 
131
    def initialize_on_transport(self, transport):
 
132
        """Initialize a new .not dir in the base directory of a Transport."""
 
133
        transport.mkdir('.not')
 
134
        return self.open(transport)
 
135
 
 
136
    def open(self, transport):
 
137
        """Open this directory."""
 
138
        return NotBzrDir(transport, self)
 
139
 
 
140
 
 
141
class NotBzrDirProber(controldir.Prober):
 
142
 
 
143
    def probe_transport(self, transport):
 
144
        """Our format is present if the transport ends in '.not/'."""
 
145
        if transport.has('.not'):
 
146
            return NotBzrDirFormat()
 
147
 
 
148
    @classmethod
 
149
    def known_formats(cls):
 
150
        return set([NotBzrDirFormat()])
 
151
 
 
152
 
 
153
class TestNotBzrDir(tests.TestCaseWithTransport):
 
154
    """Tests for using the controldir api with a non .bzr based disk format.
 
155
 
 
156
    If/when one of these is in the core, we can let the implementation tests
 
157
    verify this works.
 
158
    """
 
159
 
 
160
    def test_create_and_find_format(self):
 
161
        # create a .notbzr dir
 
162
        format = NotBzrDirFormat()
 
163
        dir = format.initialize(self.get_url())
 
164
        self.assertIsInstance(dir, NotBzrDir)
 
165
        # now probe for it.
 
166
        controldir.ControlDirFormat.register_prober(NotBzrDirProber)
 
167
        try:
 
168
            found = controldir.ControlDirFormat.find_format(self.get_transport())
 
169
            self.assertIsInstance(found, NotBzrDirFormat)
 
170
        finally:
 
171
            controldir.ControlDirFormat.unregister_prober(NotBzrDirProber)
 
172
 
 
173
    def test_included_in_known_formats(self):
 
174
        controldir.ControlDirFormat.register_prober(NotBzrDirProber)
 
175
        self.addCleanup(controldir.ControlDirFormat.unregister_prober, NotBzrDirProber)
 
176
        formats = controldir.ControlDirFormat.known_formats()
 
177
        self.assertIsInstance(formats, set)
 
178
        for format in formats:
 
179
            if isinstance(format, NotBzrDirFormat):
 
180
                break
 
181
        else:
 
182
            self.fail("No NotBzrDirFormat in %s" % formats)