~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_init.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-03-16 14:01:20 UTC
  • mfrom: (3280.2.5 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20080316140120-i3yq8yr1l66m11h7
Start 1.4 development

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
18
"""Test "bzr init"""
22
22
 
23
23
from bzrlib import (
24
24
    branch as _mod_branch,
25
 
    osutils,
26
 
    urlutils,
27
25
    )
28
26
from bzrlib.bzrdir import BzrDirMetaFormat1
29
27
from bzrlib.tests import TestSkipped
30
 
from bzrlib.tests import TestCaseWithTransport
 
28
from bzrlib.tests.blackbox import ExternalBase
31
29
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
32
30
from bzrlib.workingtree import WorkingTree
33
31
 
34
32
 
35
 
class TestInit(TestCaseWithTransport):
36
 
 
37
 
    def setUp(self):
38
 
        TestCaseWithTransport.setUp(self)
39
 
        self._default_label = '2a'
 
33
class TestInit(ExternalBase):
40
34
 
41
35
    def test_init_with_format(self):
42
36
        # Verify bzr init --format constructs something plausible
50
44
        # --format=weave should be accepted to allow interoperation with
51
45
        # old releases when desired.
52
46
        out, err = self.run_bzr('init --format=weave')
53
 
        self.assertEqual("""Created a standalone tree (format: weave)\n""",
54
 
            out)
55
 
        self.assertEqual('', err)
56
 
 
57
 
    def test_init_format_2a(self):
58
 
        """Smoke test for constructing a format 2a repoistory."""
59
 
        out, err = self.run_bzr('init --format=2a')
60
 
        self.assertEqual("""Created a standalone tree (format: 2a)\n""",
61
 
            out)
 
47
        self.assertEqual('', out)
62
48
        self.assertEqual('', err)
63
49
 
64
50
    def test_init_at_repository_root(self):
71
57
        repo = newdir.create_repository(shared=True)
72
58
        repo.set_make_working_trees(False)
73
59
        out, err = self.run_bzr('init repo')
74
 
        self.assertEqual("""Created a repository tree (format: %s)
75
 
Using shared repository: %s
76
 
""" % (self._default_label, urlutils.local_path_from_url(
77
 
            repo.bzrdir.root_transport.external_url())), out)
78
 
        cwd = osutils.getcwd()
79
 
        self.assertEndsWith(out, cwd + '/repo/\n')
 
60
        self.assertEqual('', out)
80
61
        self.assertEqual('', err)
81
62
        newdir.open_branch()
82
63
        newdir.open_workingtree()
83
 
 
 
64
        
84
65
    def test_init_branch(self):
85
66
        out, err = self.run_bzr('init')
86
 
        self.assertEqual("Created a standalone tree (format: %s)\n" % (
87
 
            self._default_label,), out)
 
67
        self.assertEqual('', out)
88
68
        self.assertEqual('', err)
89
69
 
90
70
        # Can it handle subdirectories of branches too ?
91
71
        out, err = self.run_bzr('init subdir1')
92
 
        self.assertEqual("Created a standalone tree (format: %s)\n" % (
93
 
            self._default_label,), out)
 
72
        self.assertEqual('', out)
94
73
        self.assertEqual('', err)
95
74
        WorkingTree.open('subdir1')
96
 
 
 
75
        
97
76
        self.run_bzr_error(['Parent directory of subdir2/nothere does not exist'],
98
77
                            'init subdir2/nothere')
99
78
        out, err = self.run_bzr('init subdir2/nothere', retcode=3)
100
79
        self.assertEqual('', out)
101
 
 
 
80
        
102
81
        os.mkdir('subdir2')
103
82
        out, err = self.run_bzr('init subdir2')
104
 
        self.assertEqual("Created a standalone tree (format: %s)\n" % (
105
 
            self._default_label,), out)
 
83
        self.assertEqual('', out)
106
84
        self.assertEqual('', err)
107
85
        # init an existing branch.
108
86
        out, err = self.run_bzr('init subdir2', retcode=3)
109
87
        self.assertEqual('', out)
110
88
        self.failUnless(err.startswith('bzr: ERROR: Already a branch:'))
111
89
 
112
 
    def test_init_branch_quiet(self):
113
 
        out, err = self.run_bzr('init -q')
114
 
        self.assertEqual('', out)
115
 
        self.assertEqual('', err)
116
 
 
117
90
    def test_init_existing_branch(self):
118
91
        self.run_bzr('init')
119
92
        out, err = self.run_bzr('init', retcode=3)
145
118
        except UnicodeError:
146
119
            raise TestSkipped("Unable to create Unicode filename")
147
120
        # try to init unicode dir
148
 
        self.run_bzr(['init', '-q', u'mu-\xb5'])
 
121
        self.run_bzr(['init', u'mu-\xb5'])
149
122
 
150
123
    def create_simple_tree(self):
151
124
        tree = self.make_branch_and_tree('tree')
168
141
 
169
142
    def test_init(self):
170
143
        # init on a remote url should succeed.
171
 
        out, err = self.run_bzr(['init', '--pack-0.92', self.get_url()])
172
 
        self.assertEqual(out,
173
 
            """Created a standalone branch (format: pack-0.92)\n""")
 
144
        out, err = self.run_bzr(['init', self.get_url()])
 
145
        self.assertEqual('', out)
174
146
        self.assertEqual('', err)
175
 
 
 
147
    
176
148
    def test_init_existing_branch(self):
177
149
        # when there is already a branch present, make mention
178
150
        self.make_branch('.')
196
168
    def test_init_append_revisions_only(self):
197
169
        self.run_bzr('init --dirstate-tags normal_branch6')
198
170
        branch = _mod_branch.Branch.open('normal_branch6')
199
 
        self.assertEqual(None, branch._get_append_revisions_only())
 
171
        self.assertEqual(False, branch._get_append_revisions_only())
200
172
        self.run_bzr('init --append-revisions-only --dirstate-tags branch6')
201
173
        branch = _mod_branch.Branch.open('branch6')
202
174
        self.assertEqual(True, branch._get_append_revisions_only())
203
175
        self.run_bzr_error(['cannot be set to append-revisions-only'],
204
176
                           'init --append-revisions-only --knit knit')
205
 
 
206
 
    def test_init_without_username(self):
207
 
        """Ensure init works if username is not set.
208
 
        """
209
 
        # bzr makes user specified whoami mandatory for operations
210
 
        # like commit as whoami is recorded. init however is not so final
211
 
        # and uses whoami only in a lock file. Without whoami the login name
212
 
        # is used. This test is to ensure that init passes even when whoami
213
 
        # is not available.
214
 
        osutils.set_or_unset_env('EMAIL', None)
215
 
        osutils.set_or_unset_env('BZR_EMAIL', None)
216
 
        out, err = self.run_bzr(['init', 'foo'])
217
 
        self.assertEqual(err, '')
218
 
        self.assertTrue(os.path.exists('foo'))