/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_repository.py

Add RepositoryFormats and allow bzrdir.open or create _repository to be used.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# (C) 2006 Canonical Ltd
 
2
 
 
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.
 
7
 
 
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.
 
12
 
 
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
 
16
 
 
17
"""Tests for the Repository facility that are not interface tests.
 
18
 
 
19
For interface tests see tests/repository_implementations/*.py.
 
20
 
 
21
For concrete class tests see this file, and for storage formats tests
 
22
also see this file.
 
23
"""
 
24
 
 
25
from StringIO import StringIO
 
26
 
 
27
import bzrlib.bzrdir as bzrdir
 
28
from bzrlib.errors import (NotBranchError,
 
29
                           UnknownFormatError,
 
30
                           UnsupportedFormatError,
 
31
                           )
 
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
 
37
 
 
38
 
 
39
class TestDefaultFormat(TestCase):
 
40
 
 
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.
 
47
        try:
 
48
            # directly
 
49
            control = bzrdir.BzrDir.create('memory:/')
 
50
            result = repository.Repository.create(control)
 
51
            self.assertEqual(result, 'A bzr repository dir')
 
52
        finally:
 
53
            repository.RepositoryFormat.set_default_format(old_format)
 
54
        self.assertEqual(old_format, repository.RepositoryFormat.get_default_format())
 
55
 
 
56
 
 
57
class SampleRepositoryFormat(repository.RepositoryFormat):
 
58
    """A sample format
 
59
 
 
60
    this format is initializable, unsupported to aid in testing the 
 
61
    open and open_downlevel routines.
 
62
    """
 
63
 
 
64
    def get_format_string(self):
 
65
        """See RepositoryFormat.get_format_string()."""
 
66
        return "Sample .bzr repository format."
 
67
 
 
68
    def initialize(self, a_bzrdir):
 
69
        """Initialize a repository in a BzrDir"""
 
70
        t = a_bzrdir.transport
 
71
        t.mkdir('repository')
 
72
        t.put('repository/format', StringIO(self.get_format_string()))
 
73
        return 'A bzr repository dir'
 
74
 
 
75
    def is_supported(self):
 
76
        return False
 
77
 
 
78
    def open(self, a_bzrdir):
 
79
        return "opened repository."