/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.15 by John Arbash Meinel
Merge bzr.dev 5597 to resolve NEWS, aka bzr-2.3.txt
1
# Copyright (C) 2006-2009, 2011 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
16
17
"""Tests for InterRepository implementastions."""
18
1711.7.18 by John Arbash Meinel
Old repository formats didn't support double locking on win32, don't raise errors
19
import sys
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
20
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
21
import breezy
22
import breezy.errors as errors
23
import breezy.gpg
6670.4.1 by Jelmer Vernooij
Update imports.
24
from breezy.bzr.inventory import Inventory
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
25
from breezy.revision import NULL_REVISION
26
from breezy.tests import (
2814.1.1 by Robert Collins
* Pushing, pulling and branching branches with subtree references was not
27
    TestNotApplicable,
28
    TestSkipped,
29
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
30
from breezy.tests.matchers import MatchesAncestry
31
from breezy.tests.per_interrepository import (
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
32
    TestCaseWithInterRepository,
33
    )
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
34
35
2240.1.3 by Alexander Belchenko
win32: skip tests that try to use funky chars in fileid in Weave-based repositories
36
def check_repo_format_for_funky_id_on_win32(repo):
5582.9.1 by Jelmer Vernooij
Add flag for 'supports_funky_characters'.
37
    if not repo._format.supports_funky_characters and sys.platform == 'win32':
38
        raise TestSkipped("funky chars not allowed on this platform in repository"
39
                          " %s" % repo.__class__.__name__)
2240.1.3 by Alexander Belchenko
win32: skip tests that try to use funky chars in fileid in Weave-based repositories
40
41
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
42
class TestInterRepository(TestCaseWithInterRepository):
43
1534.1.30 by Robert Collins
Test that we get the right optimiser back in the InterRepository tests.
44
    def test_interrepository_get_returns_correct_optimiser(self):
45
        # we assume the optimising code paths are triggered
46
        # by the type of the repo not the transport - at this point.
47
        # we may need to update this test if this changes.
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
48
        #
49
        # XXX: This code tests that we get an InterRepository when we try to
50
        # convert between the two repositories that it wants to be tested with
51
        # -- but that's not necessarily correct.  So for now this is disabled.
52
        # mbp 20070206
53
        ## source_repo = self.make_repository("source")
54
        ## target_repo = self.make_to_repository("target")
55
        ## interrepo = repository.InterRepository.get(source_repo, target_repo)
56
        ## self.assertEqual(self.interrepo_class, interrepo.__class__)
57
        pass
1534.1.30 by Robert Collins
Test that we get the right optimiser back in the InterRepository tests.
58
1843.2.1 by Aaron Bentley
Add failing tests for funky ids
59
1534.1.34 by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method.
60
class TestCaseWithComplexRepository(TestCaseWithInterRepository):
61
62
    def setUp(self):
63
        super(TestCaseWithComplexRepository, self).setUp()
64
        tree_a = self.make_branch_and_tree('a')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
65
        self.controldir = tree_a.branch.controldir
1534.1.34 by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method.
66
        # add a corrupt inventory 'orphan'
2592.3.91 by Robert Collins
Incrementally closing in on a correct fetch for packs.
67
        tree_a.branch.repository.lock_write()
68
        tree_a.branch.repository.start_write_group()
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
69
        inv_file = tree_a.branch.repository.inventories
70
        inv_file.add_lines(('orphan',), [], [])
2592.3.91 by Robert Collins
Incrementally closing in on a correct fetch for packs.
71
        tree_a.branch.repository.commit_write_group()
72
        tree_a.branch.repository.unlock()
1534.1.34 by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method.
73
        # add a real revision 'rev1'
74
        tree_a.commit('rev1', rev_id='rev1', allow_pointless=True)
75
        # add a real revision 'rev2' based on rev1
76
        tree_a.commit('rev2', rev_id='rev2', allow_pointless=True)
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
77
        # and sign 'rev2'
2592.3.96 by Robert Collins
Merge index improvements (includes bzr.dev).
78
        tree_a.branch.repository.lock_write()
79
        tree_a.branch.repository.start_write_group()
5582.9.1 by Jelmer Vernooij
Add flag for 'supports_funky_characters'.
80
        tree_a.branch.repository.sign_revision('rev2',
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
81
            breezy.gpg.LoopbackGPGStrategy(None))
2592.3.96 by Robert Collins
Merge index improvements (includes bzr.dev).
82
        tree_a.branch.repository.commit_write_group()
83
        tree_a.branch.repository.unlock()
1534.1.34 by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method.
84
3184.1.8 by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of
85
    def test_search_missing_revision_ids(self):
1534.1.34 by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method.
86
        # revision ids in repository A but not B are returned, fake ones
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
87
        # are stripped. (fake meaning no revision object, but an inventory
2592.3.146 by Robert Collins
Typo.
88
        # as some formats keyed off inventory data in the past.)
1534.1.34 by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method.
89
        # make a repository to compare against that claims to have rev1
90
        repo_b = self.make_to_repository('rev1_only')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
91
        repo_a = self.controldir.open_repository()
1534.1.34 by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method.
92
        repo_b.fetch(repo_a, 'rev1')
93
        # check the test will be valid
94
        self.assertFalse(repo_b.has_revision('rev2'))
3184.1.8 by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of
95
        result = repo_b.search_missing_revision_ids(repo_a)
6619.3.12 by Jelmer Vernooij
Use 2to3 set_literal fixer.
96
        self.assertEqual({'rev2'}, result.get_keys())
97
        self.assertEqual(('search', {'rev2'}, {'rev1'}, 1),
4152.1.2 by Robert Collins
Add streaming from a stacked branch when the sort order is compatible with doing so.
98
            result.get_recipe())
1534.1.34 by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method.
99
6639.3.1 by Jelmer Vernooij
Shorten test names, since otherwise paths exceed 256 characters on ci.debian.net
100
    def test_absent_requested_raises(self):
3010.1.5 by Robert Collins
Test that missing_revision_ids handles the case of the source not having the requested revision correctly with and without find_ghosts.
101
        # Asking for missing revisions with a tip that is itself absent in the
102
        # source raises NoSuchRevision.
103
        repo_b = self.make_to_repository('target')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
104
        repo_a = self.controldir.open_repository()
3010.1.5 by Robert Collins
Test that missing_revision_ids handles the case of the source not having the requested revision correctly with and without find_ghosts.
105
        # No pizza revisions anywhere
106
        self.assertFalse(repo_a.has_revision('pizza'))
107
        self.assertFalse(repo_b.has_revision('pizza'))
108
        # Asking specifically for an absent revision errors.
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
109
        self.assertRaises(errors.NoSuchRevision,
5539.2.10 by Andrew Bennetts
s/NotInOtherForRev/NotInOtherForRevs/, and allow passing multiple revision_ids to search_missing_revision_ids.
110
            repo_b.search_missing_revision_ids, repo_a, revision_ids=['pizza'],
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
111
            find_ghosts=True)
112
        self.assertRaises(errors.NoSuchRevision,
5539.2.10 by Andrew Bennetts
s/NotInOtherForRev/NotInOtherForRevs/, and allow passing multiple revision_ids to search_missing_revision_ids.
113
            repo_b.search_missing_revision_ids, repo_a, revision_ids=['pizza'],
114
            find_ghosts=False)
3010.1.5 by Robert Collins
Test that missing_revision_ids handles the case of the source not having the requested revision correctly with and without find_ghosts.
115
6639.3.1 by Jelmer Vernooij
Shorten test names, since otherwise paths exceed 256 characters on ci.debian.net
116
    def test_search_missing_rev_limited(self):
1534.1.34 by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method.
117
        # revision ids in repository A that are not referenced by the
118
        # requested revision are not returned.
119
        # make a repository to compare against that is empty
120
        repo_b = self.make_to_repository('empty')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
121
        repo_a = self.controldir.open_repository()
5539.2.10 by Andrew Bennetts
s/NotInOtherForRev/NotInOtherForRevs/, and allow passing multiple revision_ids to search_missing_revision_ids.
122
        result = repo_b.search_missing_revision_ids(
123
            repo_a, revision_ids=['rev1'])
6619.3.12 by Jelmer Vernooij
Use 2to3 set_literal fixer.
124
        self.assertEqual({'rev1'}, result.get_keys())
125
        self.assertEqual(('search', {'rev1'}, {NULL_REVISION}, 1),
3184.1.8 by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of
126
            result.get_recipe())
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
127
5852.1.6 by Jelmer Vernooij
Add extra test for Repository.search_missing_revision_ids.
128
    def test_search_missing_revision_ids_limit(self):
129
        # The limit= argument makes fetch() limit
130
        # the results to the first X topo-sorted revisions.
131
        repo_b = self.make_to_repository('rev1_only')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
132
        repo_a = self.controldir.open_repository()
5852.1.6 by Jelmer Vernooij
Add extra test for Repository.search_missing_revision_ids.
133
        # check the test will be valid
134
        self.assertFalse(repo_b.has_revision('rev2'))
135
        result = repo_b.search_missing_revision_ids(repo_a, limit=1)
6619.3.12 by Jelmer Vernooij
Use 2to3 set_literal fixer.
136
        self.assertEqual(('search', {'rev1'}, {'null:'}, 1),
5852.1.10 by Jelmer Vernooij
Use get_recipe.
137
            result.get_recipe())
5852.1.6 by Jelmer Vernooij
Add extra test for Repository.search_missing_revision_ids.
138
2592.3.91 by Robert Collins
Incrementally closing in on a correct fetch for packs.
139
    def test_fetch_fetches_signatures_too(self):
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
140
        from_repo = self.controldir.open_repository()
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
141
        from_signature = from_repo.get_signature_text('rev2')
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
142
        to_repo = self.make_to_repository('target')
143
        to_repo.fetch(from_repo)
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
144
        to_signature = to_repo.get_signature_text('rev2')
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
145
        self.assertEqual(from_signature, to_signature)
146
1570.1.14 by Robert Collins
Enforce repository consistency during 'fetch' operations.
147
148
class TestCaseWithGhosts(TestCaseWithInterRepository):
149
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
150
    def test_fetch_all_fixes_up_ghost(self):
151
        # we want two repositories at this point:
1570.1.14 by Robert Collins
Enforce repository consistency during 'fetch' operations.
152
        # one with a revision that is a ghost in the other
153
        # repository.
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
154
        # 'ghost' is present in has_ghost, 'ghost' is absent in 'missing_ghost'.
155
        # 'references' is present in both repositories, and 'tip' is present
156
        # just in has_ghost.
157
        # has_ghost       missing_ghost
158
        #------------------------------
159
        # 'ghost'             -
160
        # 'references'    'references'
161
        # 'tip'               -
162
        # In this test we fetch 'tip' which should not fetch 'ghost'
163
        has_ghost = self.make_repository('has_ghost')
164
        missing_ghost = self.make_repository('missing_ghost')
165
        if [True, True] != [repo._format.supports_ghosts for repo in
166
            (has_ghost, missing_ghost)]:
167
            raise TestNotApplicable("Need ghost support.")
168
169
        def add_commit(repo, revision_id, parent_ids):
170
            repo.lock_write()
171
            repo.start_write_group()
172
            inv = Inventory(revision_id=revision_id)
173
            inv.root.revision = revision_id
174
            root_id = inv.root.file_id
175
            sha1 = repo.add_inventory(revision_id, inv, parent_ids)
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
176
            repo.texts.add_lines((root_id, revision_id), [], [])
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
177
            rev = breezy.revision.Revision(timestamp=0,
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
178
                                           timezone=None,
179
                                           committer="Foo Bar <foo@example.com>",
180
                                           message="Message",
181
                                           inventory_sha1=sha1,
182
                                           revision_id=revision_id)
183
            rev.parent_ids = parent_ids
184
            repo.add_revision(revision_id, rev)
185
            repo.commit_write_group()
186
            repo.unlock()
187
        add_commit(has_ghost, 'ghost', [])
188
        add_commit(has_ghost, 'references', ['ghost'])
189
        add_commit(missing_ghost, 'references', ['ghost'])
190
        add_commit(has_ghost, 'tip', ['references'])
191
        missing_ghost.fetch(has_ghost, 'tip', find_ghosts=True)
192
        # missing ghost now has tip and ghost.
193
        rev = missing_ghost.get_revision('tip')
194
        inv = missing_ghost.get_inventory('tip')
195
        rev = missing_ghost.get_revision('ghost')
196
        inv = missing_ghost.get_inventory('ghost')
1570.1.14 by Robert Collins
Enforce repository consistency during 'fetch' operations.
197
        # rev must not be corrupt now
5972.3.15 by Jelmer Vernooij
Use matchers.
198
        self.assertThat(['ghost', 'references', 'tip'],
199
            MatchesAncestry(missing_ghost, 'tip'))