bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
| 
1534.4.41
by Robert Collins
 Branch now uses BzrDir reasonably sanely.  | 
1  | 
# (C) 2005,2006 Canonical Ltd
 | 
| 
1399.1.12
by Robert Collins
 add new test script  | 
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  | 
||
| 
1534.4.26
by Robert Collins
 Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.  | 
18  | 
from cStringIO import StringIO  | 
| 
1399.1.12
by Robert Collins
 add new test script  | 
19  | 
import os  | 
| 
1534.4.26
by Robert Collins
 Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.  | 
20  | 
|
21  | 
import bzrlib  | 
|
| 
1399.1.12
by Robert Collins
 add new test script  | 
22  | 
from bzrlib.branch import Branch  | 
| 
1534.4.46
by Robert Collins
 Nearly complete .bzr/checkout splitout.  | 
23  | 
import bzrlib.bzrdir as bzrdir  | 
| 
1534.4.41
by Robert Collins
 Branch now uses BzrDir reasonably sanely.  | 
24  | 
from bzrlib.bzrdir import BzrDir  | 
| 
1534.4.35
by Robert Collins
 Give branch its own basis tree and last_revision methods; deprecated branch.working_tree()  | 
25  | 
import bzrlib.errors as errors  | 
| 
1508.1.3
by Robert Collins
 Do not consider urls to be relative paths within working trees.  | 
26  | 
from bzrlib.errors import NotBranchError, NotVersionedError  | 
| 
1534.4.46
by Robert Collins
 Nearly complete .bzr/checkout splitout.  | 
27  | 
from bzrlib.osutils import pathjoin, getcwd, has_symlinks  | 
| 
1534.4.26
by Robert Collins
 Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.  | 
28  | 
from bzrlib.tests import TestCaseWithTransport  | 
| 
1399.1.12
by Robert Collins
 add new test script  | 
29  | 
from bzrlib.trace import mutter  | 
| 
1534.4.46
by Robert Collins
 Nearly complete .bzr/checkout splitout.  | 
30  | 
from bzrlib.transport import get_transport  | 
31  | 
import bzrlib.workingtree as workingtree  | 
|
| 
1457.1.1
by Robert Collins
 rather than getting the branch inventory, WorkingTree can use the whole Branch, or make its own.  | 
32  | 
from bzrlib.workingtree import (TreeEntry, TreeDirectory, TreeFile, TreeLink,  | 
33  | 
WorkingTree)  | 
|
| 
1399.1.12
by Robert Collins
 add new test script  | 
34  | 
|
| 
1534.4.26
by Robert Collins
 Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.  | 
35  | 
class TestTreeDirectory(TestCaseWithTransport):  | 
| 
1399.1.12
by Robert Collins
 add new test script  | 
36  | 
|
37  | 
def test_kind_character(self):  | 
|
38  | 
self.assertEqual(TreeDirectory().kind_character(), '/')  | 
|
39  | 
||
40  | 
||
| 
1534.4.26
by Robert Collins
 Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.  | 
41  | 
class TestTreeEntry(TestCaseWithTransport):  | 
| 
1399.1.12
by Robert Collins
 add new test script  | 
42  | 
|
43  | 
def test_kind_character(self):  | 
|
44  | 
self.assertEqual(TreeEntry().kind_character(), '???')  | 
|
45  | 
||
46  | 
||
| 
1534.4.26
by Robert Collins
 Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.  | 
47  | 
class TestTreeFile(TestCaseWithTransport):  | 
| 
1399.1.12
by Robert Collins
 add new test script  | 
48  | 
|
49  | 
def test_kind_character(self):  | 
|
50  | 
self.assertEqual(TreeFile().kind_character(), '')  | 
|
51  | 
||
52  | 
||
| 
1534.4.26
by Robert Collins
 Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.  | 
53  | 
class TestTreeLink(TestCaseWithTransport):  | 
| 
1399.1.12
by Robert Collins
 add new test script  | 
54  | 
|
55  | 
def test_kind_character(self):  | 
|
56  | 
self.assertEqual(TreeLink().kind_character(), '')  | 
|
57  | 
||
58  | 
||
| 
1534.4.46
by Robert Collins
 Nearly complete .bzr/checkout splitout.  | 
59  | 
class TestDefaultFormat(TestCaseWithTransport):  | 
60  | 
||
61  | 
def test_get_set_default_format(self):  | 
|
62  | 
old_format = workingtree.WorkingTreeFormat.get_default_format()  | 
|
63  | 
        # default is 3
 | 
|
64  | 
self.assertTrue(isinstance(old_format, workingtree.WorkingTreeFormat3))  | 
|
65  | 
workingtree.WorkingTreeFormat.set_default_format(SampleTreeFormat())  | 
|
66  | 
try:  | 
|
67  | 
            # the default branch format is used by the meta dir format
 | 
|
68  | 
            # which is not the default bzrdir format at this point
 | 
|
69  | 
dir = bzrdir.BzrDirMetaFormat1().initialize('.')  | 
|
70  | 
dir.create_repository()  | 
|
71  | 
dir.create_branch()  | 
|
72  | 
result = dir.create_workingtree()  | 
|
73  | 
self.assertEqual(result, 'A tree')  | 
|
74  | 
finally:  | 
|
75  | 
workingtree.WorkingTreeFormat.set_default_format(old_format)  | 
|
76  | 
self.assertEqual(old_format, workingtree.WorkingTreeFormat.get_default_format())  | 
|
77  | 
||
78  | 
||
79  | 
class SampleTreeFormat(workingtree.WorkingTreeFormat):  | 
|
80  | 
"""A sample format  | 
|
81  | 
||
82  | 
    this format is initializable, unsupported to aid in testing the 
 | 
|
83  | 
    open and open_downlevel routines.
 | 
|
84  | 
    """
 | 
|
85  | 
||
86  | 
def get_format_string(self):  | 
|
87  | 
"""See WorkingTreeFormat.get_format_string()."""  | 
|
88  | 
return "Sample tree format."  | 
|
89  | 
||
90  | 
def initialize(self, a_bzrdir):  | 
|
91  | 
"""Sample branches cannot be created."""  | 
|
92  | 
t = a_bzrdir.get_workingtree_transport(self)  | 
|
93  | 
t.put('format', StringIO(self.get_format_string()))  | 
|
94  | 
return 'A tree'  | 
|
95  | 
||
96  | 
def is_supported(self):  | 
|
97  | 
return False  | 
|
98  | 
||
99  | 
def open(self, transport, _found=False):  | 
|
100  | 
return "opened tree."  | 
|
101  | 
||
102  | 
||
103  | 
class TestWorkingTreeFormat(TestCaseWithTransport):  | 
|
104  | 
"""Tests for the WorkingTreeFormat facility."""  | 
|
105  | 
||
106  | 
def test_find_format(self):  | 
|
107  | 
        # is the right format object found for a working tree?
 | 
|
108  | 
        # create a branch with a few known format objects.
 | 
|
109  | 
self.build_tree(["foo/", "bar/"])  | 
|
110  | 
def check_format(format, url):  | 
|
111  | 
dir = format._matchingbzrdir.initialize(url)  | 
|
112  | 
dir.create_repository()  | 
|
113  | 
dir.create_branch()  | 
|
114  | 
format.initialize(dir)  | 
|
115  | 
t = get_transport(url)  | 
|
116  | 
found_format = workingtree.WorkingTreeFormat.find_format(dir)  | 
|
117  | 
self.failUnless(isinstance(found_format, format.__class__))  | 
|
118  | 
check_format(workingtree.WorkingTreeFormat3(), "bar")  | 
|
119  | 
||
120  | 
def test_find_format_no_tree(self):  | 
|
121  | 
dir = bzrdir.BzrDirMetaFormat1().initialize('.')  | 
|
| 
1508.1.3
by Robert Collins
 Do not consider urls to be relative paths within working trees.  | 
122  | 
self.assertRaises(NotBranchError,  | 
| 
1534.4.46
by Robert Collins
 Nearly complete .bzr/checkout splitout.  | 
123  | 
workingtree.WorkingTreeFormat.find_format,  | 
124  | 
dir)  | 
|
125  | 
||
126  | 
def test_find_format_unknown_format(self):  | 
|
127  | 
dir = bzrdir.BzrDirMetaFormat1().initialize('.')  | 
|
128  | 
dir.create_repository()  | 
|
129  | 
dir.create_branch()  | 
|
130  | 
SampleTreeFormat().initialize(dir)  | 
|
131  | 
self.assertRaises(errors.UnknownFormatError,  | 
|
132  | 
workingtree.WorkingTreeFormat.find_format,  | 
|
133  | 
dir)  | 
|
134  | 
||
135  | 
def test_register_unregister_format(self):  | 
|
136  | 
format = SampleTreeFormat()  | 
|
137  | 
        # make a control dir
 | 
|
138  | 
dir = bzrdir.BzrDirMetaFormat1().initialize('.')  | 
|
139  | 
dir.create_repository()  | 
|
140  | 
dir.create_branch()  | 
|
141  | 
        # make a branch
 | 
|
142  | 
format.initialize(dir)  | 
|
143  | 
        # register a format for it.
 | 
|
144  | 
workingtree.WorkingTreeFormat.register_format(format)  | 
|
145  | 
        # which branch.Open will refuse (not supported)
 | 
|
146  | 
self.assertRaises(errors.UnsupportedFormatError, workingtree.WorkingTree.open, '.')  | 
|
147  | 
        # compatability
 | 
|
148  | 
self.assertRaises(errors.UnsupportedFormatError, workingtree.WorkingTree, '.')  | 
|
149  | 
        # but open_downlevel will work
 | 
|
150  | 
self.assertEqual(format.open(dir), workingtree.WorkingTree.open_downlevel('.'))  | 
|
151  | 
        # unregister the format
 | 
|
152  | 
workingtree.WorkingTreeFormat.unregister_format(format)  | 
|
| 
1534.4.51
by Robert Collins
 Test the disk layout of format3 working trees.  | 
153  | 
|
154  | 
||
155  | 
class TestWorkingTreeFormat3(TestCaseWithTransport):  | 
|
156  | 
"""Tests specific to WorkingTreeFormat3."""  | 
|
157  | 
||
158  | 
def test_disk_layout(self):  | 
|
159  | 
control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())  | 
|
160  | 
control.create_repository()  | 
|
161  | 
control.create_branch()  | 
|
162  | 
tree = workingtree.WorkingTreeFormat3().initialize(control)  | 
|
163  | 
        # we want:
 | 
|
164  | 
        # format 'Bazaar-NG Working Tree format 3'
 | 
|
165  | 
        # lock ''
 | 
|
166  | 
        # inventory = blank inventory
 | 
|
167  | 
        # pending-merges = ''
 | 
|
168  | 
        # stat-cache = ??
 | 
|
169  | 
        # no inventory.basis yet
 | 
|
170  | 
t = control.get_workingtree_transport(None)  | 
|
171  | 
self.assertEqualDiff('Bazaar-NG Working Tree format 3',  | 
|
172  | 
t.get('format').read())  | 
|
173  | 
self.assertEqualDiff('', t.get('lock').read())  | 
|
174  | 
self.assertEqualDiff('<inventory format="5">\n'  | 
|
175  | 
'</inventory>\n',  | 
|
176  | 
t.get('inventory').read())  | 
|
177  | 
self.assertEqualDiff('### bzr hashcache v5\n',  | 
|
178  | 
t.get('stat-cache').read())  | 
|
179  | 
self.assertFalse(t.has('inventory.basis'))  | 
|
180  | 
        # TODO RBC 20060210 do a commit, check the inventory.basis is created 
 | 
|
181  | 
        # correctly.
 |