~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

(parthm) Better regex compile errors (Parth Malwankar)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2006-2010 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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,
25
27
    )
26
28
from bzrlib.bzrdir import BzrDirMetaFormat1
27
29
from bzrlib.tests import TestSkipped
28
 
from bzrlib.tests.blackbox import ExternalBase
 
30
from bzrlib.tests import TestCaseWithTransport
29
31
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
30
32
from bzrlib.workingtree import WorkingTree
31
33
 
32
34
 
33
 
class TestInit(ExternalBase):
 
35
class TestInit(TestCaseWithTransport):
 
36
 
 
37
    def setUp(self):
 
38
        TestCaseWithTransport.setUp(self)
 
39
        self._default_label = '2a'
34
40
 
35
41
    def test_init_with_format(self):
36
42
        # Verify bzr init --format constructs something plausible
44
50
        # --format=weave should be accepted to allow interoperation with
45
51
        # old releases when desired.
46
52
        out, err = self.run_bzr('init --format=weave')
47
 
        self.assertEqual('', out)
 
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)
48
62
        self.assertEqual('', err)
49
63
 
50
64
    def test_init_at_repository_root(self):
57
71
        repo = newdir.create_repository(shared=True)
58
72
        repo.set_make_working_trees(False)
59
73
        out, err = self.run_bzr('init repo')
60
 
        self.assertEqual('', out)
 
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')
61
80
        self.assertEqual('', err)
62
81
        newdir.open_branch()
63
82
        newdir.open_workingtree()
64
 
        
 
83
 
65
84
    def test_init_branch(self):
66
85
        out, err = self.run_bzr('init')
67
 
        self.assertEqual('', out)
 
86
        self.assertEqual("Created a standalone tree (format: %s)\n" % (
 
87
            self._default_label,), out)
68
88
        self.assertEqual('', err)
69
89
 
70
90
        # Can it handle subdirectories of branches too ?
71
91
        out, err = self.run_bzr('init subdir1')
72
 
        self.assertEqual('', out)
 
92
        self.assertEqual("Created a standalone tree (format: %s)\n" % (
 
93
            self._default_label,), out)
73
94
        self.assertEqual('', err)
74
95
        WorkingTree.open('subdir1')
75
 
        
 
96
 
76
97
        self.run_bzr_error(['Parent directory of subdir2/nothere does not exist'],
77
98
                            'init subdir2/nothere')
78
99
        out, err = self.run_bzr('init subdir2/nothere', retcode=3)
79
100
        self.assertEqual('', out)
80
 
        
 
101
 
81
102
        os.mkdir('subdir2')
82
103
        out, err = self.run_bzr('init subdir2')
83
 
        self.assertEqual('', out)
 
104
        self.assertEqual("Created a standalone tree (format: %s)\n" % (
 
105
            self._default_label,), out)
84
106
        self.assertEqual('', err)
85
107
        # init an existing branch.
86
108
        out, err = self.run_bzr('init subdir2', retcode=3)
87
109
        self.assertEqual('', out)
88
110
        self.failUnless(err.startswith('bzr: ERROR: Already a branch:'))
89
111
 
 
112
    def test_init_branch_quiet(self):
 
113
        out, err = self.run_bzr('init -q')
 
114
        self.assertEqual('', out)
 
115
        self.assertEqual('', err)
 
116
 
90
117
    def test_init_existing_branch(self):
91
118
        self.run_bzr('init')
92
119
        out, err = self.run_bzr('init', retcode=3)
118
145
        except UnicodeError:
119
146
            raise TestSkipped("Unable to create Unicode filename")
120
147
        # try to init unicode dir
121
 
        self.run_bzr(['init', u'mu-\xb5'])
 
148
        self.run_bzr(['init', '-q', u'mu-\xb5'])
122
149
 
123
150
    def create_simple_tree(self):
124
151
        tree = self.make_branch_and_tree('tree')
141
168
 
142
169
    def test_init(self):
143
170
        # init on a remote url should succeed.
144
 
        out, err = self.run_bzr(['init', self.get_url()])
145
 
        self.assertEqual('', out)
 
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""")
146
174
        self.assertEqual('', err)
147
 
    
 
175
 
148
176
    def test_init_existing_branch(self):
149
177
        # when there is already a branch present, make mention
150
178
        self.make_branch('.')
168
196
    def test_init_append_revisions_only(self):
169
197
        self.run_bzr('init --dirstate-tags normal_branch6')
170
198
        branch = _mod_branch.Branch.open('normal_branch6')
171
 
        self.assertEqual(False, branch._get_append_revisions_only())
 
199
        self.assertEqual(None, branch._get_append_revisions_only())
172
200
        self.run_bzr('init --append-revisions-only --dirstate-tags branch6')
173
201
        branch = _mod_branch.Branch.open('branch6')
174
202
        self.assertEqual(True, branch._get_append_revisions_only())
175
203
        self.run_bzr_error(['cannot be set to append-revisions-only'],
176
204
                           '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'))