1
# (C) 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 the Repository facility that are not interface tests.
19
For interface tests see tests/repository_implementations/*.py.
21
For concrete class tests see this file, and for storage formats tests
25
from StringIO import StringIO
27
import bzrlib.bzrdir as bzrdir
28
from bzrlib.errors import (NotBranchError,
31
UnsupportedFormatError,
33
import bzrlib.repository as repository
34
from bzrlib.tests import TestCase, TestCaseWithTransport
35
from bzrlib.transport import get_transport
36
from bzrlib.transport.http import HttpServer
37
from bzrlib.transport.memory import MemoryServer
40
class TestDefaultFormat(TestCase):
42
def test_get_set_default_format(self):
43
old_format = repository.RepositoryFormat.get_default_format()
44
# default is None - we cannot create a Repository independently yet
45
self.assertEqual(old_format, None)
46
repository.RepositoryFormat.set_default_format(SampleRepositoryFormat())
47
# creating a repository should now create an instrumented dir.
50
control = bzrdir.BzrDir.create('memory:/')
51
result = repository.Repository.create(control)
52
self.assertEqual(result, 'A bzr repository dir')
54
repository.RepositoryFormat.set_default_format(old_format)
55
self.assertEqual(old_format, repository.RepositoryFormat.get_default_format())
58
class SampleRepositoryFormat(repository.RepositoryFormat):
61
this format is initializable, unsupported to aid in testing the
62
open and open_downlevel routines.
65
def get_format_string(self):
66
"""See RepositoryFormat.get_format_string()."""
67
return "Sample .bzr repository format."
69
def initialize(self, a_bzrdir):
70
"""Initialize a repository in a BzrDir"""
71
t = a_bzrdir.transport
73
t.put('repository/format', StringIO(self.get_format_string()))
74
return 'A bzr repository dir'
76
def is_supported(self):
79
def open(self, a_bzrdir):
80
return "opened repository."
83
class TestFormat6(TestCaseWithTransport):
85
def test_no_ancestry_weave(self):
86
control = bzrdir.BzrDirFormat6().initialize(self.get_url())
87
repo = repository.RepositoryFormat6().initialize(control)
88
# We no longer need to create the ancestry.weave file
89
# since it is *never* used.
90
self.assertRaises(NoSuchFile,
91
control.transport.get,