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,
30
UnsupportedFormatError,
32
import bzrlib.repository as repository
33
from bzrlib.tests import TestCase, TestCaseWithTransport
34
from bzrlib.transport import get_transport
35
from bzrlib.transport.http import HttpServer
36
from bzrlib.transport.memory import MemoryServer
39
class TestDefaultFormat(TestCase):
41
def test_get_set_default_initializer(self):
42
old_format = repository.RepositoryFormat.get_default_format()
43
# default is None - we cannot create a Repository independently yet
44
self.assertEqual(old_format, None)
45
repository.RepositoryFormat.set_default_format(SampleRepositoryFormat())
46
# creating a repository should now create an instrumented dir.
49
control = bzrdir.BzrDir.create('memory:/')
50
result = repository.Repository.create(control)
51
self.assertEqual(result, 'A bzr repository dir')
53
repository.RepositoryFormat.set_default_format(old_format)
54
self.assertEqual(old_format, repository.RepositoryFormat.get_default_format())
57
class SampleRepositoryFormat(repository.RepositoryFormat):
60
this format is initializable, unsupported to aid in testing the
61
open and open_downlevel routines.
64
def get_format_string(self):
65
"""See RepositoryFormat.get_format_string()."""
66
return "Sample .bzr repository format."
68
def initialize(self, a_bzrdir):
69
"""Initialize a repository in a BzrDir"""
70
t = a_bzrdir.transport
72
t.put('repository/format', StringIO(self.get_format_string()))
73
return 'A bzr repository dir'
75
def is_supported(self):
78
def open(self, a_bzrdir):
79
return "opened repository."