~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/repository_implementations/test_repository.py

  • Committer: John Arbash Meinel
  • Date: 2006-02-21 16:43:22 UTC
  • mfrom: (1560 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1562.
  • Revision ID: john@arbash-meinel.com-20060221164322-b007aa882582a66e
[merge] bzr.dev, cleanup conflicts, fixup http tests for new TestCase layout.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import os
20
20
import sys
21
21
 
 
22
import bzrlib
22
23
import bzrlib.bzrdir as bzrdir
23
24
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock
24
25
from bzrlib.commit import commit
125
126
                         repository.RepositoryFormat.find_format(opened_control))
126
127
 
127
128
    def test_create_repository(self):
128
 
        # a repository can be constructedzrdir can construct a repository for itself.
 
129
        # bzrdir can construct a repository for itself.
129
130
        if not self.bzrdir_format.is_supported():
130
131
            # unsupported formats are not loopback testable
131
132
            # because the default open will not open them and
136
137
        made_repo = made_control.create_repository()
137
138
        self.failUnless(isinstance(made_repo, repository.Repository))
138
139
        self.assertEqual(made_control, made_repo.bzrdir)
 
140
        
 
141
    def test_create_repository_shared(self):
 
142
        # bzrdir can construct a shared repository.
 
143
        if not self.bzrdir_format.is_supported():
 
144
            # unsupported formats are not loopback testable
 
145
            # because the default open will not open them and
 
146
            # they may not be initializable.
 
147
            return
 
148
        t = get_transport(self.get_url())
 
149
        made_control = self.bzrdir_format.initialize(t.base)
 
150
        try:
 
151
            made_repo = made_control.create_repository(shared=True)
 
152
        except errors.IncompatibleFormat:
 
153
            # not all repository formats understand being shared, or
 
154
            # may only be shared in some circumstances.
 
155
            return
 
156
        self.failUnless(isinstance(made_repo, repository.Repository))
 
157
        self.assertEqual(made_control, made_repo.bzrdir)
 
158
        self.assertTrue(made_repo.is_shared())
139
159
 
140
160
    def test_revision_tree(self):
141
161
        wt = self.make_branch_and_tree('.')
148
168
        self.assertEqual(len(tree.list_files()), 0)
149
169
 
150
170
    def test_fetch(self):
 
171
        # smoke test fetch to ensure that the convenience function works.
 
172
        # it is defined as a convenience function with the underlying 
 
173
        # functionality provided by an InterRepository
151
174
        tree_a = self.make_branch_and_tree('a')
152
175
        self.build_tree(['a/foo'])
153
176
        tree_a.add('foo', 'file1')
154
177
        tree_a.commit('rev1', rev_id='rev1')
155
 
        def check_push_rev1(repo):
156
 
            # ensure the revision is missing.
157
 
            self.assertRaises(NoSuchRevision, repo.get_revision, 'rev1')
158
 
            # fetch with a limit of NULL_REVISION
159
 
            repo.fetch(tree_a.branch.repository, NULL_REVISION)
160
 
            # nothing should have been pushed
161
 
            self.assertFalse(repo.has_revision('rev1'))
162
 
            # fetch with a default limit (grab everything)
163
 
            repo.fetch(tree_a.branch.repository)
164
 
            # check that b now has all the data from a's first commit.
165
 
            rev = repo.get_revision('rev1')
166
 
            tree = repo.revision_tree('rev1')
167
 
            tree.get_file_text('file1')
168
 
            for file_id in tree:
169
 
                if tree.inventory[file_id].kind == "file":
170
 
                    tree.get_file(file_id).read()
171
 
 
172
 
        # makes a latest-version repo 
173
 
        repo_b = bzrdir.BzrDir.create_repository(self.get_url('b'))
174
 
        check_push_rev1(repo_b)
175
 
 
176
 
        # makes a this-version repo:
177
 
        repo_c = self.make_repository('c')
178
 
        check_push_rev1(repo_c)
 
178
        # fetch with a default limit (grab everything)
 
179
        repo = bzrdir.BzrDir.create_repository(self.get_url('b'))
 
180
        repo.fetch(tree_a.branch.repository,
 
181
                   revision_id=None,
 
182
                   pb=bzrlib.progress.DummyProgress())
179
183
 
180
184
    def test_clone_bzrdir_repository_revision(self):
181
185
        # make a repository with some revisions,
200
204
        target = source.bzrdir.clone(self.get_url('target'), basis=tree.bzrdir)
201
205
        self.assertTrue(target.open_repository().has_revision('2'))
202
206
 
 
207
    def test_clone_shared_no_tree(self):
 
208
        # cloning a shared repository keeps it shared
 
209
        # and preserves the make_working_tree setting.
 
210
        made_control = self.make_bzrdir('source')
 
211
        try:
 
212
            made_repo = made_control.create_repository(shared=True)
 
213
        except errors.IncompatibleFormat:
 
214
            # not all repository formats understand being shared, or
 
215
            # may only be shared in some circumstances.
 
216
            return
 
217
        made_repo.set_make_working_trees(False)
 
218
        result = made_control.clone(self.get_url('target'))
 
219
        self.failUnless(isinstance(made_repo, repository.Repository))
 
220
        self.assertEqual(made_control, made_repo.bzrdir)
 
221
        self.assertTrue(result.open_repository().is_shared())
 
222
        self.assertFalse(result.open_repository().make_working_trees())
 
223
 
203
224
 
204
225
class TestCaseWithComplexRepository(TestCaseWithRepository):
205
226
 
208
229
        tree_a = self.make_branch_and_tree('a')
209
230
        self.bzrdir = tree_a.branch.bzrdir
210
231
        # add a corrupt inventory 'orphan'
 
232
        # this may need some generalising for knits.
211
233
        tree_a.branch.repository.control_weaves.add_text(
212
234
            'inventory', 'orphan', [], [],
213
235
            tree_a.branch.repository.get_transaction())
221
243
        self.assertEqual(['rev1', 'rev2'],
222
244
                         self.bzrdir.open_repository().all_revision_ids())
223
245
 
224
 
    def test_missing_revision_ids(self):
225
 
        # revision ids in repository A but not B are returned, fake ones
226
 
        # are stripped. (fake meaning no revision object, but an inventory 
227
 
        # as some formats keyed off inventory data in the past.
228
 
        # make a repository to compare against that claims to have rev1
229
 
        tree_b = self.make_branch_and_tree('rev1_only')
230
 
        # add a real revision 'rev1'
231
 
        tree_b.commit('rev1', rev_id='rev1', allow_pointless=True)
232
 
        repo_a = self.bzrdir.open_repository()
233
 
        repo_b = tree_b.branch.repository
234
 
        self.assertEqual(['rev2'],
235
 
                         repo_b.missing_revision_ids(repo_a))
236
 
 
237
 
    def test_missing_revision_ids_default_format(self):
238
 
        # revision ids in repository A but not B are returned, fake ones
239
 
        # are stripped. (fake meaning no revision object, but an inventory 
240
 
        # as some formats keyed off inventory data in the past.
241
 
        # make a repository to compare against that claims to have rev1
242
 
        tree_b = bzrdir.BzrDir.create_standalone_workingtree('rev1_only')
243
 
        # add a real revision 'rev1'
244
 
        tree_b.commit('rev1', rev_id='rev1', allow_pointless=True)
245
 
        repo_a = self.bzrdir.open_repository()
246
 
        repo_b = tree_b.branch.repository
247
 
        self.assertEqual(['rev2'],
248
 
                         repo_b.missing_revision_ids(repo_a))
249
 
 
250
 
    def test_missing_revision_ids_revision_limited(self):
251
 
        # revision ids in repository A that are not referenced by the
252
 
        # requested revision are not returned.
253
 
        # make a repository to compare against that is empty
254
 
        tree_b = self.make_branch_and_tree('empty')
255
 
        repo_a = self.bzrdir.open_repository()
256
 
        repo_b = tree_b.branch.repository
257
 
        self.assertEqual(['rev1'],
258
 
                         repo_b.missing_revision_ids(repo_a, revision_id='rev1'))
259
 
 
260
246
    def test_get_ancestry_missing_revision(self):
261
 
        # get_ancestry(missing revision)-> NoSuchRevision
 
247
        # get_ancestry(revision that is in some data but not fully installed
 
248
        # -> NoSuchRevision
262
249
        self.assertRaises(errors.NoSuchRevision,
263
250
                          self.bzrdir.open_repository().get_ancestry, 'orphan')
264