/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: Vincent Ladeuil
  • Date: 2010-01-25 15:55:48 UTC
  • mto: (4985.1.4 add-attr-cleanup)
  • mto: This revision was merged to the branch mainline in revision 4988.
  • Revision ID: v.ladeuil+lp@free.fr-20100125155548-0l352pujvt5bzl5e
Deploy addAttrCleanup on the whole test suite.

Several use case worth mentioning:

- setting a module or any other object attribute is the majority
by far. In some cases the setting itself is deferred but most of
the time we want to set at the same time we add the cleanup.

- there multiple occurrences of protecting hooks or ui factory
which are now useless (the test framework takes care of that now),

- there was some lambda uses that can now be avoided.

That first cleanup already simplifies things a lot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2009 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
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Black box tests for the upgrade ui."""
 
18
 
18
19
import os
19
 
import stat
20
20
 
21
21
from bzrlib import (
22
22
    bzrdir,
23
23
    repository,
 
24
    ui,
24
25
    )
25
26
from bzrlib.tests import (
26
 
    features,
27
27
    TestCaseInTempDir,
28
28
    TestCaseWithTransport,
 
29
    TestUIFactory,
29
30
    )
30
31
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
31
32
from bzrlib.transport import get_transport
40
41
        super(TestWithUpgradableBranches, self).setUp()
41
42
        self.addCleanup(bzrdir.BzrDirFormat._set_default_format,
42
43
                        bzrdir.BzrDirFormat.get_default_format())
 
44
        self.addAttrCleanup(ui, 'ui_factory')
 
45
        ui.ui_factory = TestUIFactory()
43
46
 
44
47
    def make_current_format_branch_and_checkout(self):
45
48
        current_tree = self.make_branch_and_tree('current_format_branch',
104
107
        url = get_transport(self.get_url('format_5_branch')).base
105
108
        # check --format takes effect
106
109
        bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
107
 
        backup_dir = 'backup.bzr.~1~'
108
110
        (out, err) = self.run_bzr(
109
111
            ['upgrade', '--format=metaweave', url])
110
112
        self.assertEqualDiff("""starting upgrade of %s
111
113
making backup of %s.bzr
112
 
  to %s%s
 
114
  to %sbackup.bzr
113
115
starting upgrade from format 5 to 6
114
116
adding prefixes to weaves
115
117
adding prefixes to revision-store
116
118
starting upgrade from format 6 to metadir
117
119
finished
118
 
""" % (url, url, url, backup_dir), out)
 
120
""" % (url, url, url), out)
119
121
        self.assertEqualDiff("", err)
120
122
        self.assertTrue(isinstance(
121
123
            bzrdir.BzrDir.open(self.get_url('format_5_branch'))._format,
128
130
        url = get_transport(self.get_url('metadir_weave_branch')).base
129
131
        # check --format takes effect
130
132
        bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
131
 
        backup_dir = 'backup.bzr.~1~'
132
133
        (out, err) = self.run_bzr(
133
134
            ['upgrade', '--format=knit', url])
134
135
        self.assertEqualDiff("""starting upgrade of %s
135
136
making backup of %s.bzr
136
 
  to %s%s
 
137
  to %sbackup.bzr
137
138
starting repository conversion
138
139
repository converted
139
140
finished
140
 
""" % (url, url, url, backup_dir), out)
 
141
""" % (url, url, url), out)
141
142
        self.assertEqualDiff("", err)
142
143
        converted_dir = bzrdir.BzrDir.open(self.get_url('metadir_weave_branch'))
143
144
        self.assertTrue(isinstance(converted_dir._format,
149
150
        self.run_bzr('init-repository --format=metaweave repo')
150
151
        self.run_bzr('upgrade --format=knit repo')
151
152
 
152
 
    def test_upgrade_permission_check(self):
153
 
        """'backup.bzr' should retain permissions of .bzr. Bug #262450"""
154
 
        self.requireFeature(features.posix_permissions_feature)
155
 
        old_perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
156
 
        backup_dir = 'backup.bzr.~1~'
157
 
        self.run_bzr('init --format=1.6')
158
 
        os.chmod('.bzr', old_perms)
159
 
        self.run_bzr('upgrade')
160
 
        new_perms = os.stat(backup_dir).st_mode & 0777
161
 
        self.assertTrue(new_perms == old_perms)
162
 
 
163
 
 
164
 
    def test_upgrade_with_existing_backup_dir(self):
165
 
        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())
169
 
        backup_dir1 = 'backup.bzr.~1~'
170
 
        backup_dir2 = 'backup.bzr.~2~'
171
 
        # explicitly create backup_dir1. bzr should create the .~2~ directory
172
 
        # as backup
173
 
        transport.mkdir(backup_dir1)
174
 
        (out, err) = self.run_bzr(
175
 
            ['upgrade', '--format=metaweave', url])
176
 
        self.assertEqualDiff("""starting upgrade of %s
177
 
making backup of %s.bzr
178
 
  to %s%s
179
 
starting upgrade from format 5 to 6
180
 
adding prefixes to weaves
181
 
adding prefixes to revision-store
182
 
starting upgrade from format 6 to metadir
183
 
finished
184
 
""" % (url, url, url, backup_dir2), out)
185
 
        self.assertEqualDiff("", err)
186
 
        self.assertTrue(isinstance(
187
 
            bzrdir.BzrDir.open(self.get_url('format_5_branch'))._format,
188
 
            bzrdir.BzrDirMetaFormat1))
189
 
        self.assertTrue(transport.has(backup_dir2))
190
153
 
191
154
class SFTPTests(TestCaseWithSFTPServer):
192
155
    """Tests for upgrade over sftp."""
193
156
 
 
157
    def setUp(self):
 
158
        super(SFTPTests, self).setUp()
 
159
        self.addAttrCleanup(ui, 'ui_factory')
 
160
        ui.ui_factory = TestUIFactory()
 
161
 
194
162
    def test_upgrade_url(self):
195
163
        self.run_bzr('init --format=weave')
196
164
        t = get_transport(self.get_url())
197
165
        url = t.base
198
166
        out, err = self.run_bzr(['upgrade', '--format=knit', url])
199
 
        backup_dir = 'backup.bzr.~1~'
200
167
        self.assertEqualDiff("""starting upgrade of %s
201
168
making backup of %s.bzr
202
 
  to %s%s
 
169
  to %sbackup.bzr
203
170
starting upgrade from format 6 to metadir
204
171
starting repository conversion
205
172
repository converted
206
173
finished
207
 
""" % (url, url, url,backup_dir), out)
 
174
""" % (url, url, url), out)
208
175
        self.assertEqual('', err)
209
176
 
210
177