/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

Branch now uses BzrDir reasonably sanely.

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
                           NoSuchFile,
 
30
                           UnknownFormatError,
 
31
                           UnsupportedFormatError,
 
32
                           )
 
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
 
38
 
 
39
 
 
40
class TestDefaultFormat(TestCase):
 
41
 
 
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.
 
48
        try:
 
49
            # directly
 
50
            control = bzrdir.BzrDir.create('memory:/')
 
51
            result = repository.Repository.create(control)
 
52
            self.assertEqual(result, 'A bzr repository dir')
 
53
        finally:
 
54
            repository.RepositoryFormat.set_default_format(old_format)
 
55
        self.assertEqual(old_format, repository.RepositoryFormat.get_default_format())
 
56
 
 
57
 
 
58
class SampleRepositoryFormat(repository.RepositoryFormat):
 
59
    """A sample format
 
60
 
 
61
    this format is initializable, unsupported to aid in testing the 
 
62
    open and open_downlevel routines.
 
63
    """
 
64
 
 
65
    def get_format_string(self):
 
66
        """See RepositoryFormat.get_format_string()."""
 
67
        return "Sample .bzr repository format."
 
68
 
 
69
    def initialize(self, a_bzrdir):
 
70
        """Initialize a repository in a BzrDir"""
 
71
        t = a_bzrdir.transport
 
72
        t.mkdir('repository')
 
73
        t.put('repository/format', StringIO(self.get_format_string()))
 
74
        return 'A bzr repository dir'
 
75
 
 
76
    def is_supported(self):
 
77
        return False
 
78
 
 
79
    def open(self, a_bzrdir):
 
80
        return "opened repository."
 
81
 
 
82
 
 
83
class TestFormat6(TestCaseWithTransport):
 
84
 
 
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,
 
92
                          'ancestry.weave')
 
93