~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/fetch.py

  • Committer: Martin Pool
  • Date: 2005-08-25 09:07:41 UTC
  • Revision ID: mbp@sourcefrog.net-20050825090741-43abcc983f9a2867
- split fetch tests into a separate file
  to be consistent and to avoid import problems

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
import bzrlib.errors
17
 
from bzrlib.selftest.testrevision import make_branches
18
17
from bzrlib.trace import mutter, note
19
18
from bzrlib.branch import Branch
20
19
from bzrlib.progress import ProgressBar
21
20
import sys
22
21
import os
23
22
 
 
23
def has_revision(branch, revision_id):
 
24
    try:
 
25
        branch.get_revision_xml(revision_id)
 
26
        return True
 
27
    except bzrlib.errors.NoSuchRevision:
 
28
        return False
 
29
 
 
30
 
24
31
def greedy_fetch(to_branch, from_branch, revision=None, pb=None):
25
32
    """Copy a revision and all available ancestors from one branch to another
26
33
    If no revision is specified, uses the last revision in the source branch's
73
80
    return count, all_failed
74
81
 
75
82
 
76
 
from testsweet import InTempDir
77
 
from bzrlib.commit import commit
78
 
def has_revision(branch, revision_id):
79
 
    try:
80
 
        branch.get_revision_xml(revision_id)
81
 
        return True
82
 
    except bzrlib.errors.NoSuchRevision:
83
 
        return False
84
 
 
85
 
class TestFetch(InTempDir):
86
 
    def runTest(self):
87
 
        def new_branch(name):
88
 
            os.mkdir(name)
89
 
            return Branch(name, init=True)
90
 
            
91
 
        #highest indices a: 5, b: 7
92
 
        br_a, br_b = make_branches()
93
 
        assert not has_revision(br_b, br_a.revision_history()[3])
94
 
        assert has_revision(br_b, br_a.revision_history()[2])
95
 
        assert len(br_b.revision_history()) == 7
96
 
        assert greedy_fetch(br_b, br_a, br_a.revision_history()[2])[0] == 0
97
 
 
98
 
        # greedy_fetch is not supposed to alter the revision history
99
 
        assert len(br_b.revision_history()) == 7
100
 
        assert not has_revision(br_b, br_a.revision_history()[3])
101
 
 
102
 
        assert len(br_b.revision_history()) == 7
103
 
        assert greedy_fetch(br_b, br_a, br_a.revision_history()[3])[0] == 1
104
 
        assert has_revision(br_b, br_a.revision_history()[3])
105
 
        assert not has_revision(br_a, br_b.revision_history()[3])
106
 
        assert not has_revision(br_a, br_b.revision_history()[4])
107
 
 
108
 
        # When a non-branch ancestor is missing, it should be a failure, not
109
 
        # exception
110
 
        br_a4 = new_branch('br_a4')
111
 
        count, failures = greedy_fetch(br_a4, br_a)
112
 
        assert count == 6
113
 
        assert failures == set((br_b.revision_history()[4],
114
 
                                br_b.revision_history()[5])) 
115
 
 
116
 
        assert greedy_fetch(br_a, br_b)[0] == 4
117
 
        assert has_revision(br_a, br_b.revision_history()[3])
118
 
        assert has_revision(br_a, br_b.revision_history()[4])
119
 
 
120
 
        br_b2 = new_branch('br_b2')
121
 
        assert greedy_fetch(br_b2, br_b)[0] == 7
122
 
        assert has_revision(br_b2, br_b.revision_history()[4])
123
 
        assert has_revision(br_b2, br_a.revision_history()[2])
124
 
        assert not has_revision(br_b2, br_a.revision_history()[3])
125
 
 
126
 
        br_a2 = new_branch('br_a2')
127
 
        assert greedy_fetch(br_a2, br_a)[0] == 9
128
 
        assert has_revision(br_a2, br_b.revision_history()[4])
129
 
        assert has_revision(br_a2, br_a.revision_history()[3])
130
 
 
131
 
        br_a3 = new_branch('br_a3')
132
 
        assert greedy_fetch(br_a3, br_a2)[0] == 0
133
 
        for revno in range(4):
134
 
            assert not has_revision(br_a3, br_a.revision_history()[revno])
135
 
        assert greedy_fetch(br_a3, br_a2, br_a.revision_history()[2])[0] == 3
136
 
        fetched = greedy_fetch(br_a3, br_a2, br_a.revision_history()[3])[0]
137
 
        assert fetched == 3, "fetched %d instead of 3" % fetched
138
 
        # InstallFailed should be raised if the branch is missing the revision
139
 
        # that was requested.
140
 
        self.assertRaises(bzrlib.errors.InstallFailed, greedy_fetch, br_a3,
141
 
                          br_a2, 'pizza')
142
 
        # InstallFailed should be raised if the branch is missing a revision
143
 
        # from its own revision history
144
 
        br_a2.append_revision('a-b-c')
145
 
        self.assertRaises(bzrlib.errors.InstallFailed, greedy_fetch, br_a3,
146
 
                          br_a2)
147
 
 
148
 
 
149
 
 
150
 
if __name__ == '__main__':
151
 
    import sys
152
 
    sys.exit(run_suite(unittest.makeSuite()))