/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1399.1.12 by Robert Collins
add new test script
1
# (C) 2005 Canonical Ltd
2
# Authors:  Robert Collins <robert.collins@canonical.com>
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18
import os
19
from bzrlib.branch import Branch
1508.1.3 by Robert Collins
Do not consider urls to be relative paths within working trees.
20
from bzrlib.errors import NotBranchError, NotVersionedError
1185.31.25 by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py
21
from bzrlib.tests import TestCaseInTempDir
1399.1.12 by Robert Collins
add new test script
22
from bzrlib.trace import mutter
1185.31.49 by John Arbash Meinel
Some corrections using the new osutils.rename. **ALL TESTS PASS**
23
from bzrlib.osutils import pathjoin, getcwd, has_symlinks
1457.1.1 by Robert Collins
rather than getting the branch inventory, WorkingTree can use the whole Branch, or make its own.
24
from bzrlib.workingtree import (TreeEntry, TreeDirectory, TreeFile, TreeLink,
25
                                WorkingTree)
1399.1.12 by Robert Collins
add new test script
26
27
class TestTreeDirectory(TestCaseInTempDir):
28
29
    def test_kind_character(self):
30
        self.assertEqual(TreeDirectory().kind_character(), '/')
31
32
33
class TestTreeEntry(TestCaseInTempDir):
34
35
    def test_kind_character(self):
36
        self.assertEqual(TreeEntry().kind_character(), '???')
37
38
39
class TestTreeFile(TestCaseInTempDir):
40
41
    def test_kind_character(self):
42
        self.assertEqual(TreeFile().kind_character(), '')
43
44
45
class TestTreeLink(TestCaseInTempDir):
46
47
    def test_kind_character(self):
48
        self.assertEqual(TreeLink().kind_character(), '')
49
50
51
class TestWorkingTree(TestCaseInTempDir):
52
53
    def test_listfiles(self):
1185.33.66 by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko)
54
        branch = Branch.initialize(u'.')
1399.1.12 by Robert Collins
add new test script
55
        os.mkdir('dir')
56
        print >> open('file', 'w'), "content"
1185.31.49 by John Arbash Meinel
Some corrections using the new osutils.rename. **ALL TESTS PASS**
57
        if has_symlinks():
58
            os.symlink('target', 'symlink')
1399.1.12 by Robert Collins
add new test script
59
        tree = branch.working_tree()
60
        files = list(tree.list_files())
61
        self.assertEqual(files[0], ('dir', '?', 'directory', None, TreeDirectory()))
62
        self.assertEqual(files[1], ('file', '?', 'file', None, TreeFile()))
1185.31.49 by John Arbash Meinel
Some corrections using the new osutils.rename. **ALL TESTS PASS**
63
        if has_symlinks():
64
            self.assertEqual(files[2], ('symlink', '?', 'symlink', None, TreeLink()))
1457.1.1 by Robert Collins
rather than getting the branch inventory, WorkingTree can use the whole Branch, or make its own.
65
1508.1.1 by Robert Collins
Provide a open_containing for WorkingTree.
66
    def test_open_containing(self):
1185.33.66 by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko)
67
        branch = Branch.initialize(u'.')
1508.1.1 by Robert Collins
Provide a open_containing for WorkingTree.
68
        wt, relpath = WorkingTree.open_containing()
69
        self.assertEqual('', relpath)
1530.1.3 by Robert Collins
transport implementations now tested consistently.
70
        self.assertEqual(wt.basedir + '/', branch.base)
1185.33.66 by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko)
71
        wt, relpath = WorkingTree.open_containing(u'.')
1508.1.1 by Robert Collins
Provide a open_containing for WorkingTree.
72
        self.assertEqual('', relpath)
1530.1.3 by Robert Collins
transport implementations now tested consistently.
73
        self.assertEqual(wt.basedir + '/', branch.base)
1508.1.1 by Robert Collins
Provide a open_containing for WorkingTree.
74
        wt, relpath = WorkingTree.open_containing('./foo')
75
        self.assertEqual('foo', relpath)
1530.1.3 by Robert Collins
transport implementations now tested consistently.
76
        self.assertEqual(wt.basedir + '/', branch.base)
1508.1.3 by Robert Collins
Do not consider urls to be relative paths within working trees.
77
        # paths that are urls are just plain wrong for working trees.
78
        self.assertRaises(NotBranchError,
79
                          WorkingTree.open_containing, 
1185.31.39 by John Arbash Meinel
Replacing os.getcwdu() with osutils.getcwd(),
80
                          'file:///' + getcwd())
1508.1.1 by Robert Collins
Provide a open_containing for WorkingTree.
81
1457.1.1 by Robert Collins
rather than getting the branch inventory, WorkingTree can use the whole Branch, or make its own.
82
    def test_construct_with_branch(self):
1185.33.66 by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko)
83
        branch = Branch.initialize(u'.')
1457.1.1 by Robert Collins
rather than getting the branch inventory, WorkingTree can use the whole Branch, or make its own.
84
        tree = WorkingTree(branch.base, branch)
85
        self.assertEqual(branch, tree.branch)
1530.1.3 by Robert Collins
transport implementations now tested consistently.
86
        self.assertEqual(branch.base, tree.basedir + '/')
1457.1.1 by Robert Collins
rather than getting the branch inventory, WorkingTree can use the whole Branch, or make its own.
87
    
88
    def test_construct_without_branch(self):
1185.33.66 by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko)
89
        branch = Branch.initialize(u'.')
1457.1.1 by Robert Collins
rather than getting the branch inventory, WorkingTree can use the whole Branch, or make its own.
90
        tree = WorkingTree(branch.base)
91
        self.assertEqual(branch.base, tree.branch.base)
1530.1.3 by Robert Collins
transport implementations now tested consistently.
92
        self.assertEqual(branch.base, tree.basedir + '/')
1457.1.3 by Robert Collins
make Branch.relpath delegate to the working tree.
93
94
    def test_basic_relpath(self):
95
        # for comprehensive relpath tests, see whitebox.py.
1185.33.66 by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko)
96
        branch = Branch.initialize(u'.')
1457.1.3 by Robert Collins
make Branch.relpath delegate to the working tree.
97
        tree = WorkingTree(branch.base)
98
        self.assertEqual('child',
1185.31.39 by John Arbash Meinel
Replacing os.getcwdu() with osutils.getcwd(),
99
                         tree.relpath(pathjoin(getcwd(), 'child')))
1442.1.65 by Robert Collins
Branch.remove has been moved to WorkingTree.
100
101
    def test_lock_locks_branch(self):
1185.33.66 by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko)
102
        branch = Branch.initialize(u'.')
1442.1.65 by Robert Collins
Branch.remove has been moved to WorkingTree.
103
        tree = WorkingTree(branch.base)
104
        tree.lock_read()
1185.70.3 by Martin Pool
Various updates to make storage branch mergeable:
105
        self.assertEqual('r', tree.branch.peek_lock_mode())
1442.1.65 by Robert Collins
Branch.remove has been moved to WorkingTree.
106
        tree.unlock()
1185.70.3 by Martin Pool
Various updates to make storage branch mergeable:
107
        self.assertEqual(None, tree.branch.peek_lock_mode())
1442.1.65 by Robert Collins
Branch.remove has been moved to WorkingTree.
108
        tree.lock_write()
1185.70.3 by Martin Pool
Various updates to make storage branch mergeable:
109
        self.assertEqual('w', tree.branch.peek_lock_mode())
1442.1.65 by Robert Collins
Branch.remove has been moved to WorkingTree.
110
        tree.unlock()
1185.70.3 by Martin Pool
Various updates to make storage branch mergeable:
111
        self.assertEqual(None, tree.branch.peek_lock_mode())
1442.1.68 by Robert Collins
'bzr pull' now accepts '--clobber'.
112
 
113
    def get_pullable_branches(self):
1442.1.67 by Robert Collins
Factor out the guts of 'pull' from the command into WorkingTree.pull().
114
        self.build_tree(['from/', 'from/file', 'to/'])
115
        br_a = Branch.initialize('from')
1508.1.5 by Robert Collins
Move add from Branch to WorkingTree.
116
        tree = br_a.working_tree()
117
        tree.add('file')
118
        tree.commit('foo', rev_id='A')
1442.1.67 by Robert Collins
Factor out the guts of 'pull' from the command into WorkingTree.pull().
119
        br_b = Branch.initialize('to')
1442.1.68 by Robert Collins
'bzr pull' now accepts '--clobber'.
120
        return br_a, br_b
121
 
122
    def test_pull(self):
123
        br_a, br_b = self.get_pullable_branches()
1442.1.67 by Robert Collins
Factor out the guts of 'pull' from the command into WorkingTree.pull().
124
        br_b.working_tree().pull(br_a)
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
125
        self.failUnless(br_b.repository.has_revision('A'))
1442.1.67 by Robert Collins
Factor out the guts of 'pull' from the command into WorkingTree.pull().
126
        self.assertEqual(['A'], br_b.revision_history())
1442.1.68 by Robert Collins
'bzr pull' now accepts '--clobber'.
127
1185.12.92 by Aaron Bentley
Fixed pull help, renamed clobber to overwrite
128
    def test_pull_overwrites(self):
1442.1.68 by Robert Collins
'bzr pull' now accepts '--clobber'.
129
        br_a, br_b = self.get_pullable_branches()
1457.1.17 by Robert Collins
Branch.commit() has moved to WorkingTree.commit(). (Robert Collins)
130
        br_b.working_tree().commit('foo', rev_id='B')
1442.1.68 by Robert Collins
'bzr pull' now accepts '--clobber'.
131
        self.assertEqual(['B'], br_b.revision_history())
1185.12.92 by Aaron Bentley
Fixed pull help, renamed clobber to overwrite
132
        br_b.working_tree().pull(br_a, overwrite=True)
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
133
        self.failUnless(br_b.repository.has_revision('A'))
134
        self.failUnless(br_b.repository.has_revision('B'))
1442.1.68 by Robert Collins
'bzr pull' now accepts '--clobber'.
135
        self.assertEqual(['A'], br_b.revision_history())
1501 by Robert Collins
Move revert from Branch to WorkingTree.
136
137
    def test_revert(self):
138
        """Test selected-file revert"""
1185.33.66 by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko)
139
        b = Branch.initialize(u'.')
1501 by Robert Collins
Move revert from Branch to WorkingTree.
140
141
        self.build_tree(['hello.txt'])
142
        file('hello.txt', 'w').write('initial hello')
143
144
        self.assertRaises(NotVersionedError,
145
                          b.working_tree().revert, ['hello.txt'])
1508.1.5 by Robert Collins
Move add from Branch to WorkingTree.
146
        tree = WorkingTree(b.base, b)
147
        tree.add(['hello.txt'])
148
        tree.commit('create initial hello.txt')
1501 by Robert Collins
Move revert from Branch to WorkingTree.
149
150
        self.check_file_contents('hello.txt', 'initial hello')
151
        file('hello.txt', 'w').write('new hello')
152
        self.check_file_contents('hello.txt', 'new hello')
153
154
        # revert file modified since last revision
1508.1.5 by Robert Collins
Move add from Branch to WorkingTree.
155
        tree.revert(['hello.txt'])
1501 by Robert Collins
Move revert from Branch to WorkingTree.
156
        self.check_file_contents('hello.txt', 'initial hello')
157
        self.check_file_contents('hello.txt~', 'new hello')
158
1457.1.8 by Robert Collins
Replace the WorkingTree.revert method algorithm with a call to merge_inner.
159
        # reverting again does not clobber the backup
1508.1.5 by Robert Collins
Move add from Branch to WorkingTree.
160
        tree.revert(['hello.txt'])
1501 by Robert Collins
Move revert from Branch to WorkingTree.
161
        self.check_file_contents('hello.txt', 'initial hello')
1457.1.8 by Robert Collins
Replace the WorkingTree.revert method algorithm with a call to merge_inner.
162
        self.check_file_contents('hello.txt~', 'new hello')
1508.1.6 by Robert Collins
Move Branch.unknowns() to WorkingTree.
163
164
    def test_unknowns(self):
1185.33.66 by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko)
165
        b = Branch.initialize(u'.')
166
        tree = WorkingTree(u'.', b)
1508.1.6 by Robert Collins
Move Branch.unknowns() to WorkingTree.
167
        self.build_tree(['hello.txt',
168
                         'hello.txt~'])
169
        self.assertEquals(list(tree.unknowns()),
170
                          ['hello.txt'])
171
1185.60.6 by Aaron Bentley
Fixed hashcache
172
    def test_hashcache(self):
173
        from bzrlib.tests.test_hashcache import pause
174
        b = Branch.initialize(u'.')
175
        tree = WorkingTree(u'.', b)
176
        self.build_tree(['hello.txt',
177
                         'hello.txt~'])
178
        tree.add('hello.txt')
179
        pause()
180
        sha = tree.get_file_sha1(tree.path2id('hello.txt'))
181
        self.assertEqual(1, tree._hashcache.miss_count)
182
        tree2 = WorkingTree(u'.', b)
183
        sha2 = tree2.get_file_sha1(tree2.path2id('hello.txt'))
184
        self.assertEqual(0, tree2._hashcache.miss_count)
185
        self.assertEqual(1, tree2._hashcache.hit_count)