/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
905 by Martin Pool
- merge aaron's append_multiple.patch
1
# (C) 2005 Canonical Ltd
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
17
import os
1391 by Robert Collins
merge from integration
18
from bzrlib.branch import Branch, copy_branch
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
19
from bzrlib.commit import commit
20
from bzrlib.errors import NoSuchRevision, UnlistableBranch
1141 by Martin Pool
- rename FunctionalTest to TestCaseInTempDir
21
from bzrlib.selftest import TestCaseInTempDir
1260 by Martin Pool
- some updates for fetch/update function
22
from bzrlib.trace import mutter
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
23
24
class TestBranch(TestCaseInTempDir):
25
1102 by Martin Pool
- merge test refactoring from robertc
26
    def test_append_revisions(self):
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
27
        """Test appending more than one revision"""
1185.2.9 by Lalo Martins
getting rid of everything that calls the Branch constructor directly
28
        br = Branch.initialize(".")
905 by Martin Pool
- merge aaron's append_multiple.patch
29
        br.append_revision("rev1")
30
        self.assertEquals(br.revision_history(), ["rev1",])
31
        br.append_revision("rev2", "rev3")
32
        self.assertEquals(br.revision_history(), ["rev1", "rev2", "rev3"])
1110 by Martin Pool
- merge aaron's merge improvements:
33
34
1260 by Martin Pool
- some updates for fetch/update function
35
class TestFetch(TestCaseInTempDir):
1391 by Robert Collins
merge from integration
36
1260 by Martin Pool
- some updates for fetch/update function
37
    def test_fetch_revisions(self):
38
        """Test fetch-revision operation."""
39
        from bzrlib.fetch import Fetcher
40
        os.mkdir('b1')
41
        os.mkdir('b2')
1390 by Robert Collins
pair programming worx... merge integration and weave
42
        b1 = Branch.initialize('b1')
43
        b2 = Branch.initialize('b2')
1260 by Martin Pool
- some updates for fetch/update function
44
        file(os.sep.join(['b1', 'foo']), 'w').write('hello')
45
        b1.add(['foo'], ['foo-id'])
46
        b1.commit('lala!', rev_id='revision-1', allow_pointless=False)
47
48
        mutter('start fetch')
49
        f = Fetcher(from_branch=b1, to_branch=b2)
50
        eq = self.assertEquals
51
        eq(f.count_copied, 1)
52
        eq(f.last_revision, 'revision-1')
53
54
        rev = b2.get_revision('revision-1')
55
        tree = b2.revision_tree('revision-1')
56
        eq(tree.get_file_text('foo-id'), 'hello')
57
1391 by Robert Collins
merge from integration
58
    def test_push_stores(self):
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
59
        """Copy the stores from one branch to another"""
60
        os.mkdir('a')
61
        br_a = Branch.initialize("a")
62
        file('a/b', 'wb').write('b')
63
        br_a.add('b')
64
        commit(br_a, "silly commit")
65
66
        os.mkdir('b')
67
        br_b = Branch.initialize("b")
68
        self.assertRaises(NoSuchRevision, br_b.get_revision, 
69
                          br_a.revision_history()[0])
1391 by Robert Collins
merge from integration
70
        br_a.push_stores(br_b)
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
71
        rev = br_b.get_revision(br_a.revision_history()[0])
72
        tree = br_b.revision_tree(br_a.revision_history()[0])
73
        for file_id in tree:
74
            if tree.inventory[file_id].kind == "file":
75
                tree.get_file(file_id).read()
76
        return br_a, br_b
77
78
    def test_copy_branch(self):
79
        """Copy the stores from one branch to another"""
1391 by Robert Collins
merge from integration
80
        br_a, br_b = self.test_push_stores()
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
81
        commit(br_b, "silly commit")
82
        os.mkdir('c')
83
        br_c = copy_branch(br_a, 'c', basis_branch=br_b)
84
        self.assertEqual(br_a.revision_history(), br_c.revision_history())
1391 by Robert Collins
merge from integration
85
        assert br_b.last_revision() not in br_c.revision_history()
86
        br_c.get_revision(br_b.last_revision())
1110 by Martin Pool
- merge aaron's merge improvements:
87
# TODO: rewrite this as a regular unittest, without relying on the displayed output        
88
#         >>> from bzrlib.commit import commit
89
#         >>> bzrlib.trace.silent = True
90
#         >>> br1 = ScratchBranch(files=['foo', 'bar'])
91
#         >>> br1.add('foo')
92
#         >>> br1.add('bar')
93
#         >>> commit(br1, "lala!", rev_id="REVISION-ID-1", verbose=False)
94
#         >>> br2 = ScratchBranch()
95
#         >>> br2.update_revisions(br1)
96
#         Added 2 texts.
97
#         Added 1 inventories.
98
#         Added 1 revisions.
99
#         >>> br2.revision_history()
100
#         [u'REVISION-ID-1']
101
#         >>> br2.update_revisions(br1)
102
#         Added 0 revisions.
103
#         >>> br1.text_store.total_size() == br2.text_store.total_size()
104
#         True