/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_info.py

  • Committer: Aaron Bentley
  • Date: 2007-05-18 11:42:33 UTC
  • mto: This revision was merged to the branch mainline in revision 2528.
  • Revision ID: aaron.bentley@utoronto.ca-20070518114233-dhywq002d3fi9cti
Prevent repository.get_set_default_format from corrupting inventory

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 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
 
 
18
from bzrlib import (
 
19
    branch as _mod_branch,
 
20
    bzrdir,
 
21
    info,
 
22
    tests,
 
23
    workingtree,
 
24
    repository as _mod_repository,
 
25
    )
 
26
 
 
27
 
 
28
class TestInfo(tests.TestCaseWithTransport):
 
29
 
 
30
    def test_describe_standalone_layout(self):
 
31
        tree = self.make_branch_and_tree('tree')
 
32
        self.assertEqual('Empty control directory', info.describe_layout())
 
33
        self.assertEqual('Unshared repository with trees',
 
34
            info.describe_layout(tree.branch.repository))
 
35
        tree.branch.repository.set_make_working_trees(False)
 
36
        self.assertEqual('Unshared repository',
 
37
            info.describe_layout(tree.branch.repository))
 
38
        self.assertEqual('Standalone branch',
 
39
            info.describe_layout(tree.branch.repository, tree.branch))
 
40
        self.assertEqual('Standalone branchless tree',
 
41
            info.describe_layout(tree.branch.repository, None, tree))
 
42
        self.assertEqual('Standalone tree',
 
43
            info.describe_layout(tree.branch.repository, tree.branch, tree))
 
44
        tree.branch.bind(tree.branch)
 
45
        self.assertEqual('Bound branch',
 
46
            info.describe_layout(tree.branch.repository, tree.branch))
 
47
        self.assertEqual('Checkout',
 
48
            info.describe_layout(tree.branch.repository, tree.branch, tree))
 
49
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
 
50
        self.assertEqual('Lightweight checkout',
 
51
            info.describe_layout(checkout.branch.repository, checkout.branch,
 
52
                                 checkout))
 
53
 
 
54
 
 
55
    def test_describe_repository_layout(self):
 
56
        repository = self.make_repository('.', shared=True)
 
57
        tree = bzrdir.BzrDir.create_branch_convenience('tree',
 
58
            force_new_tree=True).bzrdir.open_workingtree()
 
59
        self.assertEqual('Shared repository with trees',
 
60
            info.describe_layout(tree.branch.repository))
 
61
        repository.set_make_working_trees(False)
 
62
        self.assertEqual('Shared repository',
 
63
            info.describe_layout(tree.branch.repository))
 
64
        self.assertEqual('Repository branch',
 
65
            info.describe_layout(tree.branch.repository, tree.branch))
 
66
        self.assertEqual('Repository branchless tree',
 
67
            info.describe_layout(tree.branch.repository, None, tree))
 
68
        self.assertEqual('Repository tree',
 
69
            info.describe_layout(tree.branch.repository, tree.branch, tree))
 
70
        tree.branch.bind(tree.branch)
 
71
        self.assertEqual('Repository checkout',
 
72
            info.describe_layout(tree.branch.repository, tree.branch, tree))
 
73
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
 
74
        self.assertEqual('Lightweight checkout',
 
75
            info.describe_layout(checkout.branch.repository, checkout.branch,
 
76
                                 checkout))
 
77
 
 
78
    def assertTreeDescription(self, format):
 
79
        self.make_branch_and_tree('%s_tree' % format, format=format)
 
80
        tree = workingtree.WorkingTree.open('%s_tree' % format)
 
81
        self.assertEqual(format, info.describe_format(tree.bzrdir,
 
82
            tree.branch.repository, tree.branch, tree))
 
83
 
 
84
    def assertCheckoutDescription(self, format, expected=None):
 
85
        if expected is None:
 
86
            expected = format
 
87
        branch = self.make_branch('%s_cobranch' % format, format=format)
 
88
        # this ought to be easier...
 
89
        branch.create_checkout('%s_co' % format,
 
90
            lightweight=True).bzrdir.destroy_workingtree()
 
91
        control = bzrdir.BzrDir.open('%s_co' % format)
 
92
        old_format = control._format.workingtree_format
 
93
        try:
 
94
            control._format.workingtree_format = \
 
95
                bzrdir.format_registry.make_bzrdir(format).workingtree_format
 
96
            control.create_workingtree()
 
97
            tree = workingtree.WorkingTree.open('%s_co' % format)
 
98
            self.assertEqual(expected, info.describe_format(tree.bzrdir,
 
99
                tree.branch.repository, tree.branch, tree))
 
100
        finally:
 
101
            control._format.workingtree_format = old_format
 
102
 
 
103
    def assertBranchDescription(self, format, expected=None):
 
104
        if expected is None:
 
105
            expected = format
 
106
        self.make_branch('%s_branch' % format, format=format)
 
107
        branch = _mod_branch.Branch.open('%s_branch' % format)
 
108
        self.assertEqual(expected, info.describe_format(branch.bzrdir,
 
109
            branch.repository, branch, None))
 
110
 
 
111
    def assertRepoDescription(self, format, expected=None):
 
112
        if expected is None:
 
113
            expected = format
 
114
        self.make_repository('%s_repo' % format, format=format)
 
115
        repo = _mod_repository.Repository.open('%s_repo' % format)
 
116
        self.assertEqual(expected, info.describe_format(repo.bzrdir,
 
117
            repo, None, None))
 
118
 
 
119
    def test_describe_format(self):
 
120
        for key in bzrdir.format_registry.keys():
 
121
            if key == 'default':
 
122
                continue
 
123
            self.assertTreeDescription(key)
 
124
 
 
125
        for key in bzrdir.format_registry.keys():
 
126
            if key in ('default', 'weave'):
 
127
                continue
 
128
            expected = None
 
129
            if key in ('dirstate', 'dirstate-tags', 'dirstate-with-subtree'):
 
130
                expected = 'dirstate / dirstate-tags'
 
131
            if key in ('knit', 'metaweave'):
 
132
                expected = 'knit / metaweave'
 
133
            self.assertCheckoutDescription(key, expected)
 
134
 
 
135
        for key in bzrdir.format_registry.keys():
 
136
            if key == 'default':
 
137
                continue
 
138
            expected = None
 
139
            if key in ('dirstate', 'knit'):
 
140
                expected = 'dirstate / knit'
 
141
            self.assertBranchDescription(key, expected)
 
142
 
 
143
        for key in bzrdir.format_registry.keys():
 
144
            if key == 'default':
 
145
                continue
 
146
            expected = None
 
147
            if key in ('dirstate', 'knit', 'dirstate-tags'):
 
148
                expected = 'dirstate / dirstate-tags / knit'
 
149
            self.assertRepoDescription(key, expected)
 
150
 
 
151
        format = bzrdir.format_registry.make_bzrdir('metaweave')
 
152
        format.set_branch_format(_mod_branch.BzrBranchFormat6())
 
153
        tree = self.make_branch_and_tree('unknown', format=format)
 
154
        self.assertEqual('unnamed', info.describe_format(tree.bzrdir,
 
155
            tree.branch.repository, tree.branch, tree))