/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2011, 2016 Canonical Ltd
5741.1.3 by Jelmer Vernooij
Move fetch tests.
2
#
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.
7
#
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.
12
#
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
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17
"""Tests for InterBranch.fetch."""
18
6876.1.1 by Jelmer Vernooij
Allow InterBranch to not implement lossless fetch.
19
from breezy.errors import FetchLimitUnsupported, NoRoundtrippingSupport
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
20
from breezy.revision import NULL_REVISION
6862.4.1 by Jelmer Vernooij
Allow InterBranch implementations to not support limit=.
21
from breezy.tests import TestNotApplicable
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
22
from breezy.tests.per_interbranch import (
5741.1.3 by Jelmer Vernooij
Move fetch tests.
23
    TestCaseWithInterBranch,
24
    )
25
26
27
class TestInterBranchFetch(TestCaseWithInterBranch):
28
29
    def test_fetch_revisions(self):
30
        """Test fetch-revision operation."""
31
        wt = self.make_from_branch_and_tree('b1')
32
        b1 = wt.branch
6855.4.1 by Jelmer Vernooij
Yet more bees.
33
        self.build_tree_contents([('b1/foo', b'hello')])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
34
        wt.add(['foo'])
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
35
        rev1 = wt.commit('lala!', allow_pointless=False)
5741.1.3 by Jelmer Vernooij
Move fetch tests.
36
37
        b2 = self.make_to_branch('b2')
6876.1.1 by Jelmer Vernooij
Allow InterBranch to not implement lossless fetch.
38
        try:
39
            b2.fetch(b1)
40
        except NoRoundtrippingSupport:
41
            raise TestNotApplicable(
42
                'lossless cross-vcs fetch %r to %r not supported' %
43
                (b1, b2))
5741.1.3 by Jelmer Vernooij
Move fetch tests.
44
45
        # fetch does not update the last revision
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
46
        self.assertEqual(NULL_REVISION, b2.last_revision())
5741.1.3 by Jelmer Vernooij
Move fetch tests.
47
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
48
        b2.repository.get_revision(rev1)
49
        tree = b2.repository.revision_tree(rev1)
5741.1.3 by Jelmer Vernooij
Move fetch tests.
50
        tree.lock_read()
51
        self.addCleanup(tree.unlock)
6973.7.3 by Jelmer Vernooij
Fix some more tests.
52
        self.assertEqual(tree.get_file_text('foo'), b'hello')
5741.1.3 by Jelmer Vernooij
Move fetch tests.
53
5852.1.2 by Jelmer Vernooij
Add test for InterBranch.fetch(limit=).
54
    def test_fetch_revisions_limit(self):
55
        """Test fetch-revision operation."""
5852.1.9 by Jelmer Vernooij
Use branch builder.
56
        builder = self.make_branch_builder('b1',
7143.15.2 by Jelmer Vernooij
Run autopep8.
57
                                           format=self.branch_format_from._matchingcontroldir)
5852.1.9 by Jelmer Vernooij
Use branch builder.
58
        builder.start_series()
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
59
        rev1 = builder.build_commit()
60
        rev2 = builder.build_commit()
61
        rev3 = builder.build_commit()
5852.1.9 by Jelmer Vernooij
Use branch builder.
62
        builder.finish_series()
63
        b1 = builder.get_branch()
5852.1.2 by Jelmer Vernooij
Add test for InterBranch.fetch(limit=).
64
        b2 = self.make_to_branch('b2')
6862.4.1 by Jelmer Vernooij
Allow InterBranch implementations to not support limit=.
65
        try:
66
            b2.fetch(b1, limit=1)
67
        except FetchLimitUnsupported:
7143.15.2 by Jelmer Vernooij
Run autopep8.
68
            raise TestNotApplicable(
69
                'interbranch does not support fetch limits')
6876.1.1 by Jelmer Vernooij
Allow InterBranch to not implement lossless fetch.
70
        except NoRoundtrippingSupport:
71
            raise TestNotApplicable(
72
                'lossless cross-vcs fetch %r to %r not supported' %
73
                (b1, b2))
5852.1.2 by Jelmer Vernooij
Add test for InterBranch.fetch(limit=).
74
75
        # fetch does not update the last revision
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
76
        self.assertEqual(NULL_REVISION, b2.last_revision())
5852.1.2 by Jelmer Vernooij
Add test for InterBranch.fetch(limit=).
77
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
78
        self.assertEqual({rev1},
79
                         b2.repository.has_revisions([rev1, rev2, rev3]))
5852.1.5 by Andrew Bennetts, Jelmer Vernooij
Support limit= for fetching between Bazaar branches.
80
81
    def test_fetch_revisions_limit_incremental(self):
82
        """Test incremental fetch-revision operation with limit."""
83
        wt = self.make_from_branch_and_tree('b1')
84
        b1 = wt.branch
6855.4.1 by Jelmer Vernooij
Yet more bees.
85
        self.build_tree_contents([('b1/foo', b'hello')])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
86
        wt.add(['foo'])
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
87
        rev1 = wt.commit('lala!', allow_pointless=False)
5852.1.5 by Andrew Bennetts, Jelmer Vernooij
Support limit= for fetching between Bazaar branches.
88
89
        b2 = self.make_to_branch('b2')
6862.4.1 by Jelmer Vernooij
Allow InterBranch implementations to not support limit=.
90
        try:
91
            b2.fetch(b1, limit=1)
92
        except FetchLimitUnsupported:
7143.15.2 by Jelmer Vernooij
Run autopep8.
93
            raise TestNotApplicable(
94
                'interbranch does not support fetch limits')
6876.1.1 by Jelmer Vernooij
Allow InterBranch to not implement lossless fetch.
95
        except NoRoundtrippingSupport:
96
            raise TestNotApplicable(
97
                'lossless cross-vcs fetch %r to %r not supported' %
98
                (b1, b2))
5852.1.5 by Andrew Bennetts, Jelmer Vernooij
Support limit= for fetching between Bazaar branches.
99
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
100
        self.assertEqual(
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
101
            {rev1},
5852.1.5 by Andrew Bennetts, Jelmer Vernooij
Support limit= for fetching between Bazaar branches.
102
            b2.repository.has_revisions(
7045.4.1 by Jelmer Vernooij
Some brz-git fixes.
103
                [rev1, b'revision-2', b'revision-3']))
5852.1.5 by Andrew Bennetts, Jelmer Vernooij
Support limit= for fetching between Bazaar branches.
104
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
105
        rev2 = wt.commit('hmm')
106
        rev3 = wt.commit('hmmm')
5852.1.5 by Andrew Bennetts, Jelmer Vernooij
Support limit= for fetching between Bazaar branches.
107
108
        b2.fetch(b1, limit=1)
109
110
        # fetch does not update the last revision
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
111
        self.assertEqual(NULL_REVISION, b2.last_revision())
5852.1.5 by Andrew Bennetts, Jelmer Vernooij
Support limit= for fetching between Bazaar branches.
112
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
113
        self.assertEqual(
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
114
            {rev1, rev2},
115
            b2.repository.has_revisions([rev1, rev2, rev3]))