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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-01-12 18:39:25 UTC
  • mfrom: (5598.1.1 bzr)
  • Revision ID: pqm@pqm.ubuntu.com-20110112183925-rnn12p6xp91441r0
(vila) Fix PEP-8 violation in PythonVersionInfoBuilder's output (Soren
 Hansen)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 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
20
20
 
21
21
from bzrlib import (
22
22
    bzrdir,
23
 
    repository,
 
23
    controldir,
 
24
    transport,
24
25
    )
25
26
from bzrlib.tests import (
26
27
    features,
27
 
    TestCaseInTempDir,
28
28
    TestCaseWithTransport,
29
29
    )
30
30
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
31
 
from bzrlib.transport import get_transport
32
31
from bzrlib.repofmt.knitrepo import (
33
32
    RepositoryFormatKnit1,
34
33
    )
38
37
 
39
38
    def setUp(self):
40
39
        super(TestWithUpgradableBranches, self).setUp()
41
 
        self.addCleanup(bzrdir.BzrDirFormat._set_default_format,
42
 
                        bzrdir.BzrDirFormat.get_default_format())
 
40
        self.addCleanup(controldir.ControlDirFormat._set_default_format,
 
41
                        controldir.ControlDirFormat.get_default_format())
43
42
 
44
43
    def make_current_format_branch_and_checkout(self):
45
44
        current_tree = self.make_branch_and_tree('current_format_branch',
59
58
        self.make_format_5_branch()
60
59
        (out, err) = self.run_bzr(
61
60
            ['upgrade', self.get_readonly_url('format_5_branch')], retcode=3)
62
 
        self.assertEqual(out, "")
63
 
        self.assertEqual(err, "bzr: ERROR: Upgrade URL cannot work with readonly URLs.\n")
 
61
        err_msg = 'Upgrade URL cannot work with readonly URLs.'
 
62
        self.assertEqualDiff('conversion error: %s\nbzr: ERROR: %s\n'
 
63
                             % (err_msg, err_msg),
 
64
                             err)
64
65
 
65
66
    def test_upgrade_up_to_date(self):
66
67
        self.make_current_format_branch_and_checkout()
67
68
        # when up to date we should get a message to that effect
68
69
        (out, err) = self.run_bzr('upgrade current_format_branch', retcode=3)
69
 
        self.assertEqual("", out)
70
 
        self.assertEqualDiff("bzr: ERROR: The branch format Meta "
71
 
                             "directory format 1 is already at the most "
72
 
                             "recent format.\n", err)
 
70
        err_msg = ('The branch format %s is already at the most recent format.'
 
71
                   % ('Meta directory format 1'))
 
72
        self.assertEqualDiff('conversion error: %s\nbzr: ERROR: %s\n'
 
73
                             % (err_msg, err_msg),
 
74
                             err)
73
75
 
74
76
    def test_upgrade_up_to_date_checkout_warns_branch_left_alone(self):
75
77
        self.make_current_format_branch_and_checkout()
76
78
        # when upgrading a checkout, the branch location and a suggestion
77
79
        # to upgrade it should be emitted even if the checkout is up to
78
80
        # date
 
81
        burl = self.get_transport('current_format_branch').base
 
82
        curl = self.get_transport('current_format_checkout').base
79
83
        (out, err) = self.run_bzr('upgrade current_format_checkout', retcode=3)
80
 
        self.assertEqual("This is a checkout. The branch (%s) needs to be "
81
 
                         "upgraded separately.\n"
82
 
                         % get_transport(self.get_url('current_format_branch')).base,
83
 
                         out)
84
 
        self.assertEqualDiff("bzr: ERROR: The branch format Meta "
85
 
                             "directory format 1 is already at the most "
86
 
                             "recent format.\n", err)
 
84
        self.assertEqual(
 
85
            'Upgrading branch %s ...\nThis is a checkout.'
 
86
            ' The branch (%s) needs to be upgraded separately.\n'
 
87
            % (curl, burl),
 
88
            out)
 
89
        msg = 'The branch format %s is already at the most recent format.' % (
 
90
            'Meta directory format 1')
 
91
        self.assertEqualDiff('conversion error: %s\nbzr: ERROR: %s\n'
 
92
                             % (msg, msg),
 
93
                             err)
87
94
 
88
95
    def test_upgrade_checkout(self):
89
96
        # upgrading a checkout should work
101
108
    def test_upgrade_explicit_metaformat(self):
102
109
        # users can force an upgrade to metadir format.
103
110
        self.make_format_5_branch()
104
 
        url = get_transport(self.get_url('format_5_branch')).base
 
111
        url = transport.get_transport(self.get_url('format_5_branch')).base
105
112
        # check --format takes effect
106
 
        bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
 
113
        controldir.ControlDirFormat._set_default_format(bzrdir.BzrDirFormat5())
107
114
        backup_dir = 'backup.bzr.~1~'
108
115
        (out, err) = self.run_bzr(
109
116
            ['upgrade', '--format=metaweave', url])
110
 
        self.assertEqualDiff("""starting upgrade of %s
 
117
        self.assertEqualDiff("""Upgrading branch %s ...
 
118
starting upgrade of %s
111
119
making backup of %s.bzr
112
120
  to %s%s
113
121
starting upgrade from format 5 to 6
115
123
adding prefixes to revision-store
116
124
starting upgrade from format 6 to metadir
117
125
finished
118
 
""" % (url, url, url, backup_dir), out)
 
126
""" % (url, url, url, url, backup_dir), out)
119
127
        self.assertEqualDiff("", err)
120
128
        self.assertTrue(isinstance(
121
129
            bzrdir.BzrDir.open(self.get_url('format_5_branch'))._format,
125
133
        # users can force an upgrade to knit format from a metadir weave
126
134
        # branch
127
135
        self.make_metadir_weave_branch()
128
 
        url = get_transport(self.get_url('metadir_weave_branch')).base
 
136
        url = transport.get_transport(self.get_url('metadir_weave_branch')).base
129
137
        # check --format takes effect
130
 
        bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
 
138
        controldir.ControlDirFormat._set_default_format(bzrdir.BzrDirFormat5())
131
139
        backup_dir = 'backup.bzr.~1~'
132
140
        (out, err) = self.run_bzr(
133
141
            ['upgrade', '--format=knit', url])
134
 
        self.assertEqualDiff("""starting upgrade of %s
 
142
        self.assertEqualDiff("""Upgrading branch %s ...
 
143
starting upgrade of %s
135
144
making backup of %s.bzr
136
145
  to %s%s
137
146
starting repository conversion
138
147
repository converted
139
148
finished
140
 
""" % (url, url, url, backup_dir), out)
 
149
""" % (url, url, url, url, backup_dir),
 
150
                             out)
141
151
        self.assertEqualDiff("", err)
142
152
        converted_dir = bzrdir.BzrDir.open(self.get_url('metadir_weave_branch'))
143
153
        self.assertTrue(isinstance(converted_dir._format,
149
159
        self.run_bzr('init-repository --format=metaweave repo')
150
160
        self.run_bzr('upgrade --format=knit repo')
151
161
 
 
162
    def assertLegalOption(self, option_str):
 
163
        # Confirm that an option is legal. (Lower level tests are
 
164
        # expected to validate the actual functionality.)
 
165
        self.run_bzr('init --format=pack-0.92 branch-foo')
 
166
        self.run_bzr('upgrade --format=2a branch-foo %s' % (option_str,))
 
167
 
 
168
    def assertBranchFormat(self, dir, format):
 
169
        branch = bzrdir.BzrDir.open_tree_or_branch(self.get_url(dir))[1]
 
170
        branch_format = branch._format
 
171
        meta_format = bzrdir.format_registry.make_bzrdir(format)
 
172
        expected_format = meta_format.get_branch_format()
 
173
        self.assertEqual(expected_format, branch_format)
 
174
 
 
175
    def test_upgrade_clean_supported(self):
 
176
        self.assertLegalOption('--clean')
 
177
        self.assertBranchFormat('branch-foo', '2a')
 
178
        backup_bzr_dir = os.path.join("branch-foo", "backup.bzr.~1~")
 
179
        self.assertFalse(os.path.exists(backup_bzr_dir))
 
180
 
 
181
    def test_upgrade_dry_run_supported(self):
 
182
        self.assertLegalOption('--dry-run')
 
183
        self.assertBranchFormat('branch-foo', 'pack-0.92')
 
184
 
152
185
    def test_upgrade_permission_check(self):
153
186
        """'backup.bzr' should retain permissions of .bzr. Bug #262450"""
154
187
        self.requireFeature(features.posix_permissions_feature)
163
196
 
164
197
    def test_upgrade_with_existing_backup_dir(self):
165
198
        self.make_format_5_branch()
166
 
        transport = get_transport(self.get_url('format_5_branch'))
167
 
        url = transport.base
168
 
        bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
 
199
        t = transport.get_transport(self.get_url('format_5_branch'))
 
200
        url = t.base
 
201
        controldir.ControlDirFormat._set_default_format(bzrdir.BzrDirFormat5())
169
202
        backup_dir1 = 'backup.bzr.~1~'
170
203
        backup_dir2 = 'backup.bzr.~2~'
171
204
        # explicitly create backup_dir1. bzr should create the .~2~ directory
172
205
        # as backup
173
 
        transport.mkdir(backup_dir1)
 
206
        t.mkdir(backup_dir1)
174
207
        (out, err) = self.run_bzr(
175
208
            ['upgrade', '--format=metaweave', url])
176
 
        self.assertEqualDiff("""starting upgrade of %s
 
209
        self.assertEqualDiff("""Upgrading branch %s ...
 
210
starting upgrade of %s
177
211
making backup of %s.bzr
178
212
  to %s%s
179
213
starting upgrade from format 5 to 6
181
215
adding prefixes to revision-store
182
216
starting upgrade from format 6 to metadir
183
217
finished
184
 
""" % (url, url, url, backup_dir2), out)
 
218
""" % (url, url, url, url, backup_dir2), out)
185
219
        self.assertEqualDiff("", err)
186
220
        self.assertTrue(isinstance(
187
221
            bzrdir.BzrDir.open(self.get_url('format_5_branch'))._format,
188
222
            bzrdir.BzrDirMetaFormat1))
189
 
        self.assertTrue(transport.has(backup_dir2))
 
223
        self.assertTrue(t.has(backup_dir2))
190
224
 
191
225
class SFTPTests(TestCaseWithSFTPServer):
192
226
    """Tests for upgrade over sftp."""
193
227
 
194
228
    def test_upgrade_url(self):
195
229
        self.run_bzr('init --format=weave')
196
 
        t = get_transport(self.get_url())
 
230
        t = transport.get_transport(self.get_url())
197
231
        url = t.base
198
232
        out, err = self.run_bzr(['upgrade', '--format=knit', url])
199
233
        backup_dir = 'backup.bzr.~1~'
200
 
        self.assertEqualDiff("""starting upgrade of %s
 
234
        self.assertEqualDiff("""Upgrading branch %s ...
 
235
starting upgrade of %s
201
236
making backup of %s.bzr
202
237
  to %s%s
203
238
starting upgrade from format 6 to metadir
204
239
starting repository conversion
205
240
repository converted
206
241
finished
207
 
""" % (url, url, url,backup_dir), out)
 
242
""" % (url, url, url, url,backup_dir), out)
208
243
        self.assertEqual('', err)
209
244
 
210
245