/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 tests/test_repository.py

Fix bugs in two lookup_tree_id implementations and add a test for it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
class TestGitRepositoryFeatures(tests.TestCaseInTempDir):
51
51
    """Feature tests for GitRepository."""
52
52
 
53
 
    def _do_commit(self):
54
 
        builder = tests.GitBranchBuilder()
55
 
        builder.set_file('a', 'text for a\n', False)
56
 
        commit_handle = builder.commit('Joe Foo <joe@foo.com>', u'message')
57
 
        mapping = builder.finish()
58
 
        return mapping[commit_handle]
 
53
    _test_needs_features = [tests.GitCommandFeature]
59
54
 
60
55
    def test_open_existing(self):
61
56
        GitRepo.init(self.test_dir)
67
62
        GitRepo.init(self.test_dir)
68
63
 
69
64
        repo = Repository.open('.')
70
 
        self.assertIsInstance(repo._git, dulwich.repo.BaseRepo)
71
 
 
72
 
    def test_has_revision(self):
73
 
        GitRepo.init(self.test_dir)
74
 
        commit_id = self._do_commit()
75
 
        repo = Repository.open('.')
76
 
        self.assertFalse(repo.has_revision('foobar'))
77
 
        revid = default_mapping.revision_id_foreign_to_bzr(commit_id)
78
 
        self.assertTrue(repo.has_revision(revid))
79
 
 
80
 
    def test_has_revisions(self):
81
 
        GitRepo.init(self.test_dir)
82
 
        commit_id = self._do_commit()
83
 
        repo = Repository.open('.')
84
 
        self.assertEquals(set(), repo.has_revisions(['foobar']))
85
 
        revid = default_mapping.revision_id_foreign_to_bzr(commit_id)
86
 
        self.assertEquals(set([revid]), repo.has_revisions(['foobar', revid]))
 
65
        self.assertIsInstance(repo._git, dulwich.repo.Repo)
87
66
 
88
67
    def test_get_revision(self):
89
68
        # GitRepository.get_revision gives a Revision object.
90
69
 
91
70
        # Create a git repository with a revision.
92
71
        GitRepo.init(self.test_dir)
93
 
        commit_id = self._do_commit()
 
72
        builder = tests.GitBranchBuilder()
 
73
        builder.set_file('a', 'text for a\n', False)
 
74
        commit_handle = builder.commit('Joe Foo <joe@foo.com>', u'message')
 
75
        mapping = builder.finish()
 
76
        commit_id = mapping[commit_handle]
94
77
 
95
78
        # Get the corresponding Revision object.
96
79
        revid = default_mapping.revision_id_foreign_to_bzr(commit_id)
117
100
        mapping = builder.finish()
118
101
        return mapping[commit_handle]
119
102
 
120
 
    def test_pack(self):
121
 
        commit_id = self.simple_commit()
122
 
        repo = Repository.open('.')
123
 
        repo.pack()
124
 
 
125
103
    def test_revision_tree(self):
126
104
        commit_id = self.simple_commit()
127
105
        revid = default_mapping.revision_id_foreign_to_bzr(commit_id)
165
143
 
166
144
class TestGitRepository(tests.TestCaseWithTransport):
167
145
 
168
 
    def _do_commit(self):
169
 
        builder = tests.GitBranchBuilder()
170
 
        builder.set_file('a', 'text for a\n', False)
171
 
        commit_handle = builder.commit('Joe Foo <joe@foo.com>', u'message')
172
 
        mapping = builder.finish()
173
 
        return mapping[commit_handle]
174
 
 
175
146
    def setUp(self):
176
147
        tests.TestCaseWithTransport.setUp(self)
177
148
        dulwich.repo.Repo.create(self.test_dir)
190
161
    def test_all_revision_ids_none(self):
191
162
        self.assertEquals(set([]), self.git_repo.all_revision_ids())
192
163
 
193
 
    def test_all_revision_ids(self):
194
 
        commit_id = self._do_commit()
195
 
        self.assertEquals(
196
 
                set([default_mapping.revision_id_foreign_to_bzr(commit_id)]),
197
 
                self.git_repo.all_revision_ids())
198
 
 
199
164
    def test_get_ancestry_null(self):
200
165
        self.assertEquals([None, revision.NULL_REVISION], self.git_repo.get_ancestry(revision.NULL_REVISION))
201
166
 
255
220
        store, store_iter = self.object_iter()
256
221
        store._cache.idmap.start_write_group()
257
222
        try:
258
 
            return store_iter.import_revision(revid, roundtrip=False)
 
223
            return store_iter.import_revision(revid)
259
224
        except:
260
225
            store._cache.idmap.abort_write_group()
261
226
            raise
275
240
class ForeignTestsRepositoryFactory(object):
276
241
 
277
242
    def make_repository(self, transport):
278
 
        return dir.LocalGitControlDirFormat().initialize_on_transport(transport).open_repository()
 
243
        return dir.LocalGitBzrDirFormat().initialize_on_transport(transport).open_repository()