1
# (C) 2005, 2006 Canonical Ltd
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.
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.
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
17
"""Tests for bzrdir implementations - tests a bzrdir format."""
22
import bzrlib.branch as branch
23
import bzrlib.bzrdir as bzrdir
24
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock
25
from bzrlib.commit import commit
26
import bzrlib.errors as errors
27
from bzrlib.errors import (FileExists,
30
UninitializableFormat,
34
from bzrlib.osutils import getcwd
35
from bzrlib.revision import NULL_REVISION
36
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
37
from bzrlib.trace import mutter
38
import bzrlib.transactions as transactions
39
from bzrlib.transport import get_transport
40
from bzrlib.upgrade import upgrade
41
from bzrlib.workingtree import WorkingTree
44
class TestCaseWithBzrDir(TestCaseWithTransport):
47
super(TestCaseWithBzrDir, self).setUp()
51
if self.bzrdir is None:
52
self.bzrdir = self.make_bzrdir(None)
55
def make_bzrdir(self, relpath):
57
url = self.get_url(relpath)
58
segments = url.split('/')
59
if segments and segments[-1] not in ('', '.'):
60
parent = '/'.join(segments[:-1])
61
t = get_transport(parent)
66
return self.bzrdir_format.initialize(url)
67
except UninitializableFormat:
68
raise TestSkipped("Format %s is not initializable.")
71
class TestBzrDir(TestCaseWithBzrDir):
73
def test_clone_bzrdir(self):
74
#TODO: Test that we can create a clone of a bzr dir
76
#... and all its contents verbatim.
77
raise AssertionError('not tested yet.')
79
# a bunch of tests needed::
80
# create a bzr dir with nothing, clone it check result has nothing
81
# create a bzr dir with storage only, clone it check result has same
83
# create bzr dir with branch with no storage, clone, check resulting
84
# dir also has no storage but does have branch
85
# create bzr dir with a tree but no storage or branch (on local disk
86
# as thats how workingtree works) clone and check no branch or
88
# create a standalone_branch , clone that and check all bits are
90
# features that are not supported (like detached working trees for
91
# older formats, should catch the error and silently pass the test
92
# as they are honouring the format.
94
def test_new_line_of_development_bzrdir(self):
95
#TODO: Test that we can create a line of development from a
96
raise AssertionError('not tested yet.')
98
# same permutations as clone_bzrdir, or nearly so, but we want to
99
# have checkouts force creation of a new branch because thats the
103
def test_format_initialize_find_open(self):
104
# loopback test to check the current format initializes to itself.
105
if not self.bzrdir_format.is_supported():
106
# unsupported formats are not loopback testable
107
# because the default open will not open them and
108
# they may not be initializable.
110
# supported formats must be able to init and open
111
t = get_transport(self.get_url())
112
readonly_t = get_transport(self.get_readonly_url())
113
made_control = self.bzrdir_format.initialize(t.base)
114
self.failUnless(isinstance(made_control, bzrdir.BzrDir))
115
self.assertEqual(self.bzrdir_format,
116
bzrdir.BzrDirFormat.find_format(readonly_t))
117
direct_opened_dir = self.bzrdir_format.open(readonly_t)
118
opened_dir = bzrdir.BzrDir.open(t.base)
119
self.assertEqual(made_control._format,
121
self.assertEqual(direct_opened_dir._format,
123
self.failUnless(isinstance(opened_dir, bzrdir.BzrDir))
125
def test_open_not_bzrdir(self):
126
# test the formats specific behaviour for no-content or similar dirs.
127
self.assertRaises(NotBranchError,
128
self.bzrdir_format.open,
129
get_transport(self.get_readonly_url()))