/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/blackbox/test_init.py

  • Committer: John Arbash Meinel
  • Date: 2009-06-18 18:18:36 UTC
  • mto: This revision was merged to the branch mainline in revision 4461.
  • Revision ID: john@arbash-meinel.com-20090618181836-biodfkat9a8eyzjz
The new add_inventory_by_delta is returning a CHKInventory when mapping from NULL
Which is completely valid, but 'broke' one of the tests.
So to fix it, changed the test to use CHKInventories on both sides, and add an __eq__
member. The nice thing is that CHKInventory.__eq__ is fairly cheap, since it only
has to check the root keys.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006, 2007, 2009 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
 
 
18
"""Test "bzr init"""
 
19
 
 
20
import os
 
21
import re
 
22
 
 
23
from bzrlib import (
 
24
    branch as _mod_branch,
 
25
    urlutils,
 
26
    )
 
27
from bzrlib.bzrdir import BzrDirMetaFormat1
 
28
from bzrlib.tests import TestSkipped
 
29
from bzrlib.tests.blackbox import ExternalBase
 
30
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
 
31
from bzrlib.workingtree import WorkingTree
 
32
 
 
33
 
 
34
class TestInit(ExternalBase):
 
35
 
 
36
    def test_init_with_format(self):
 
37
        # Verify bzr init --format constructs something plausible
 
38
        t = self.get_transport()
 
39
        self.run_bzr('init --format default')
 
40
        self.assertIsDirectory('.bzr', t)
 
41
        self.assertIsDirectory('.bzr/checkout', t)
 
42
        self.assertIsDirectory('.bzr/checkout/lock', t)
 
43
 
 
44
    def test_init_weave(self):
 
45
        # --format=weave should be accepted to allow interoperation with
 
46
        # old releases when desired.
 
47
        out, err = self.run_bzr('init --format=weave')
 
48
        self.assertEqual("""Created a standalone tree (format: weave)\n""",
 
49
            out)
 
50
        self.assertEqual('', err)
 
51
 
 
52
    def test_init_format_2a(self):
 
53
        """Smoke test for constructing a format 2a repoistory."""
 
54
        out, err = self.run_bzr('init --format=2a')
 
55
        self.assertEqual("""Created a standalone tree (format: 2a)\n""",
 
56
            out)
 
57
        self.assertEqual('', err)
 
58
 
 
59
    def test_init_at_repository_root(self):
 
60
        # bzr init at the root of a repository should create a branch
 
61
        # and working tree even when creation of working trees is disabled.
 
62
        t = self.get_transport()
 
63
        t.mkdir('repo')
 
64
        format = BzrDirMetaFormat1()
 
65
        newdir = format.initialize(t.abspath('repo'))
 
66
        repo = newdir.create_repository(shared=True)
 
67
        repo.set_make_working_trees(False)
 
68
        out, err = self.run_bzr('init repo')
 
69
        self.assertEqual("""Created a repository tree (format: pack-0.92)
 
70
Using shared repository: %s
 
71
""" % urlutils.local_path_from_url(
 
72
            repo.bzrdir.root_transport.external_url()), out)
 
73
        self.assertEndsWith(out, "bzrlib.tests.blackbox.test_init.TestInit."
 
74
            "test_init_at_repository_root/work/repo/\n")
 
75
        self.assertEqual('', err)
 
76
        newdir.open_branch()
 
77
        newdir.open_workingtree()
 
78
 
 
79
    def test_init_branch(self):
 
80
        out, err = self.run_bzr('init')
 
81
        self.assertEqual("""Created a standalone tree (format: pack-0.92)\n""",
 
82
            out)
 
83
        self.assertEqual('', err)
 
84
 
 
85
        # Can it handle subdirectories of branches too ?
 
86
        out, err = self.run_bzr('init subdir1')
 
87
        self.assertEqual("""Created a standalone tree (format: pack-0.92)\n""",
 
88
            out)
 
89
        self.assertEqual('', err)
 
90
        WorkingTree.open('subdir1')
 
91
 
 
92
        self.run_bzr_error(['Parent directory of subdir2/nothere does not exist'],
 
93
                            'init subdir2/nothere')
 
94
        out, err = self.run_bzr('init subdir2/nothere', retcode=3)
 
95
        self.assertEqual('', out)
 
96
 
 
97
        os.mkdir('subdir2')
 
98
        out, err = self.run_bzr('init subdir2')
 
99
        self.assertEqual("""Created a standalone tree (format: pack-0.92)\n""",
 
100
            out)
 
101
        self.assertEqual('', err)
 
102
        # init an existing branch.
 
103
        out, err = self.run_bzr('init subdir2', retcode=3)
 
104
        self.assertEqual('', out)
 
105
        self.failUnless(err.startswith('bzr: ERROR: Already a branch:'))
 
106
 
 
107
    def test_init_branch_quiet(self):
 
108
        out, err = self.run_bzr('init -q')
 
109
        self.assertEqual('', out)
 
110
        self.assertEqual('', err)
 
111
 
 
112
    def test_init_existing_branch(self):
 
113
        self.run_bzr('init')
 
114
        out, err = self.run_bzr('init', retcode=3)
 
115
        self.assertContainsRe(err, 'Already a branch')
 
116
        # don't suggest making a checkout, there's already a working tree
 
117
        self.assertFalse(re.search(r'checkout', err))
 
118
 
 
119
    def test_init_existing_without_workingtree(self):
 
120
        # make a repository
 
121
        repo = self.make_repository('.', shared=True)
 
122
        repo.set_make_working_trees(False)
 
123
        # make a branch; by default without a working tree
 
124
        self.run_bzr('init subdir')
 
125
        # fail
 
126
        out, err = self.run_bzr('init subdir', retcode=3)
 
127
        # suggests using checkout
 
128
        self.assertContainsRe(err,
 
129
                              'ontains a branch.*but no working tree.*checkout')
 
130
 
 
131
    def test_no_defaults(self):
 
132
        """Init creates no default ignore rules."""
 
133
        self.run_bzr('init')
 
134
        self.assertFalse(os.path.exists('.bzrignore'))
 
135
 
 
136
    def test_init_unicode(self):
 
137
        # Make sure getcwd can handle unicode filenames
 
138
        try:
 
139
            os.mkdir(u'mu-\xb5')
 
140
        except UnicodeError:
 
141
            raise TestSkipped("Unable to create Unicode filename")
 
142
        # try to init unicode dir
 
143
        self.run_bzr(['init', '-q', u'mu-\xb5'])
 
144
 
 
145
    def create_simple_tree(self):
 
146
        tree = self.make_branch_and_tree('tree')
 
147
        self.build_tree(['tree/a'])
 
148
        tree.add(['a'], ['a-id'])
 
149
        tree.commit('one', rev_id='r1')
 
150
        return tree
 
151
 
 
152
    def test_init_create_prefix(self):
 
153
        """'bzr init --create-prefix; will create leading directories."""
 
154
        tree = self.create_simple_tree()
 
155
 
 
156
        self.run_bzr_error(['Parent directory of ../new/tree does not exist'],
 
157
                            'init ../new/tree', working_dir='tree')
 
158
        self.run_bzr('init ../new/tree --create-prefix', working_dir='tree')
 
159
        self.failUnlessExists('new/tree/.bzr')
 
160
 
 
161
 
 
162
class TestSFTPInit(TestCaseWithSFTPServer):
 
163
 
 
164
    def test_init(self):
 
165
        # init on a remote url should succeed.
 
166
        out, err = self.run_bzr(['init', self.get_url()])
 
167
        self.assertEqual(out,
 
168
            """Created a standalone branch (format: pack-0.92)\n""")
 
169
        self.assertEqual('', err)
 
170
 
 
171
    def test_init_existing_branch(self):
 
172
        # when there is already a branch present, make mention
 
173
        self.make_branch('.')
 
174
 
 
175
        # rely on SFTPServer get_url() pointing at '.'
 
176
        out, err = self.run_bzr_error(['Already a branch'],
 
177
                                      ['init', self.get_url()])
 
178
 
 
179
        # make sure using 'bzr checkout' is not suggested
 
180
        # for remote locations missing a working tree
 
181
        self.assertFalse(re.search(r'use bzr checkout', err))
 
182
 
 
183
    def test_init_existing_branch_with_workingtree(self):
 
184
        # don't distinguish between the branch having a working tree or not
 
185
        # when the branch itself is remote.
 
186
        self.make_branch_and_tree('.')
 
187
 
 
188
        # rely on SFTPServer get_url() pointing at '.'
 
189
        self.run_bzr_error(['Already a branch'], ['init', self.get_url()])
 
190
 
 
191
    def test_init_append_revisions_only(self):
 
192
        self.run_bzr('init --dirstate-tags normal_branch6')
 
193
        branch = _mod_branch.Branch.open('normal_branch6')
 
194
        self.assertEqual(False, branch._get_append_revisions_only())
 
195
        self.run_bzr('init --append-revisions-only --dirstate-tags branch6')
 
196
        branch = _mod_branch.Branch.open('branch6')
 
197
        self.assertEqual(True, branch._get_append_revisions_only())
 
198
        self.run_bzr_error(['cannot be set to append-revisions-only'],
 
199
                           'init --append-revisions-only --knit knit')