~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-04-19 08:36:50 UTC
  • mfrom: (1664.2.14 bzr.knitplanmerge)
  • Revision ID: pqm@pqm.ubuntu.com-20060419083650-f26d296f90d75d88
Implement plan_merge for knits

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 by Canonical Ltd
 
2
# Authors: Robert Collins <robert.collins@canonical.com>
 
3
# -*- coding: utf-8 -*-
 
4
 
 
5
# This program is free software; you can redistribute it and/or modify
 
6
# it under the terms of the GNU General Public License as published by
 
7
# the Free Software Foundation; either version 2 of the License, or
 
8
# (at your option) any later version.
 
9
 
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU General Public License for more details.
 
14
 
 
15
# You should have received a copy of the GNU General Public License
 
16
# along with this program; if not, write to the Free Software
 
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 
 
19
"""Black box tests for the upgrade ui."""
 
20
 
 
21
import os
 
22
 
 
23
import bzrlib.bzrdir as bzrdir
 
24
import bzrlib.repository as repository
 
25
from bzrlib.tests import TestCaseWithTransport
 
26
from bzrlib.tests.blackbox import TestUIFactory
 
27
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
 
28
from bzrlib.transport import get_transport
 
29
import bzrlib.ui as ui
 
30
 
 
31
 
 
32
class TestWithUpgradableBranches(TestCaseWithTransport):
 
33
 
 
34
    def setUp(self):
 
35
        super(TestWithUpgradableBranches, self).setUp()
 
36
        self.old_format = bzrdir.BzrDirFormat.get_default_format()
 
37
        self.old_ui_factory = ui.ui_factory
 
38
        self.addCleanup(self.restoreDefaults)
 
39
 
 
40
        ui.ui_factory = TestUIFactory()
 
41
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
42
        # FIXME RBC 20060120 we should be able to do this via ui calls only.
 
43
        # setup a format 5 branch we can upgrade from.
 
44
        t = get_transport(self.get_url())
 
45
        t.mkdir('format_5_branch')
 
46
        bzrdir.BzrDirFormat5().initialize(self.get_url('format_5_branch'))
 
47
        bzrdir.BzrDir.create_standalone_workingtree('current_format_branch')
 
48
        d = bzrdir.BzrDir.create('metadir_weave_branch')
 
49
        d.create_repository()
 
50
        d.create_branch()
 
51
        d.create_workingtree()
 
52
        self.run_bzr('checkout',
 
53
                     '--lightweight',
 
54
                     self.get_url('current_format_branch'),
 
55
                     'current_format_checkout')
 
56
 
 
57
    def restoreDefaults(self):
 
58
        bzrdir.BzrDirFormat.set_default_format(self.old_format)
 
59
        ui.ui_factory = self.old_ui_factory
 
60
 
 
61
    def test_readonly_url_error(self):
 
62
        (out, err) = self.run_bzr_captured(
 
63
            ['upgrade', self.get_readonly_url('format_5_branch')], 3)
 
64
        self.assertEqual(out, "")
 
65
        self.assertEqual(err, "bzr: ERROR: Upgrade URL cannot work with readonly URL's.\n")
 
66
 
 
67
    def test_upgrade_up_to_date(self):
 
68
        # when up to date we should get a message to that effect
 
69
        (out, err) = self.run_bzr_captured(
 
70
            ['upgrade', 'current_format_branch'], 3)
 
71
        self.assertEqual("", out)
 
72
        self.assertEqualDiff("bzr: ERROR: The branch format Bazaar-NG meta "
 
73
                             "directory, format 1 is already at the most "
 
74
                             "recent format.\n", err)
 
75
 
 
76
    def test_upgrade_up_to_date_checkout_warns_branch_left_alone(self):
 
77
        # when upgrading a checkout, the branch location and a suggestion
 
78
        # to upgrade it should be emitted even if the checkout is up to 
 
79
        # date
 
80
        (out, err) = self.run_bzr_captured(
 
81
            ['upgrade', 'current_format_checkout'], 3)
 
82
        self.assertEqual("This is a checkout. The branch (%s) needs to be "
 
83
                         "upgraded separately.\n" 
 
84
                         % get_transport(self.get_url('current_format_branch')).base,
 
85
                         out)
 
86
        self.assertEqualDiff("bzr: ERROR: The branch format Bazaar-NG meta "
 
87
                             "directory, format 1 is already at the most "
 
88
                             "recent format.\n", err)
 
89
 
 
90
    def test_upgrade_checkout(self):
 
91
        # upgrading a checkout should work
 
92
        pass
 
93
 
 
94
    def test_upgrade_repository_scans_branches(self):
 
95
        # we should get individual upgrade notes for each branch even the 
 
96
        # anonymous branch
 
97
        pass
 
98
 
 
99
    def test_ugrade_branch_in_repo(self):
 
100
        # upgrading a branch in a repo should warn about not upgrading the repo
 
101
        pass
 
102
 
 
103
    def test_upgrade_explicit_metaformat(self):
 
104
        # users can force an upgrade to metadir format.
 
105
        url = get_transport(self.get_url('format_5_branch')).base
 
106
        # check --format takes effect
 
107
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirFormat5())
 
108
        (out, err) = self.run_bzr_captured(
 
109
            ['upgrade', '--format=metadir', url])
 
110
        self.assertEqualDiff("""starting upgrade of %s
 
111
making backup of tree history
 
112
%s.bzr has been backed up to %s.bzr.backup
 
113
if conversion fails, you can move this directory back to .bzr
 
114
if it succeeds, you can remove this directory if you wish
 
115
starting upgrade from format 5 to 6
 
116
adding prefixes to weaves
 
117
adding prefixes to revision-store
 
118
starting upgrade from format 6 to metadir
 
119
finished
 
120
""" % (url, url, url), out)
 
121
        self.assertEqualDiff("", err)
 
122
        self.assertTrue(isinstance(
 
123
            bzrdir.BzrDir.open(self.get_url('format_5_branch'))._format,
 
124
            bzrdir.BzrDirMetaFormat1))
 
125
 
 
126
    def test_upgrade_explicit_knit(self):
 
127
        # users can force an upgrade to knit format from a metadir weave 
 
128
        # branch
 
129
        url = get_transport(self.get_url('metadir_weave_branch')).base
 
130
        # check --format takes effect
 
131
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirFormat5())
 
132
        (out, err) = self.run_bzr_captured(
 
133
            ['upgrade', '--format=knit', url])
 
134
        self.assertEqualDiff("""starting upgrade of %s
 
135
making backup of tree history
 
136
%s.bzr has been backed up to %s.bzr.backup
 
137
if conversion fails, you can move this directory back to .bzr
 
138
if it succeeds, you can remove this directory if you wish
 
139
starting repository conversion
 
140
repository converted
 
141
finished
 
142
""" % (url, url, url), out)
 
143
        self.assertEqualDiff("", err)
 
144
        converted_dir = bzrdir.BzrDir.open(self.get_url('metadir_weave_branch'))
 
145
        self.assertTrue(isinstance(converted_dir._format,
 
146
                                   bzrdir.BzrDirMetaFormat1))
 
147
        self.assertTrue(isinstance(converted_dir.open_repository()._format,
 
148
                                   repository.RepositoryFormatKnit1))
 
149
 
 
150
    def test_upgrade_repo(self):
 
151
        self.run_bzr('init-repository', '--format=metadir', 'repo')
 
152
        self.run_bzr('upgrade', '--format=knit', 'repo')
 
153
 
 
154
 
 
155
class SFTPTests(TestCaseWithSFTPServer):
 
156
    """Tests for upgrade over sftp."""
 
157
 
 
158
    def setUp(self):
 
159
        super(SFTPTests, self).setUp()
 
160
        self.old_ui_factory = ui.ui_factory
 
161
        self.addCleanup(self.restoreDefaults)
 
162
 
 
163
        ui.ui_factory = TestUIFactory()
 
164
 
 
165
    def restoreDefaults(self):
 
166
        ui.ui_factory = self.old_ui_factory
 
167
 
 
168
    def test_upgrade_url(self):
 
169
        self.run_bzr('init', '--format=weave')
 
170
        t = get_transport(self.get_url())
 
171
        url = t.base
 
172
        out, err = self.run_bzr('upgrade', '--format=knit', url)
 
173
        self.assertEqualDiff("""starting upgrade of %s
 
174
making backup of tree history
 
175
%s.bzr has been backed up to %s.bzr.backup
 
176
if conversion fails, you can move this directory back to .bzr
 
177
if it succeeds, you can remove this directory if you wish
 
178
starting upgrade from format 6 to metadir
 
179
starting repository conversion
 
180
repository converted
 
181
finished
 
182
""" % (url, url, url), out)
 
183
        self.assertEqual('', err)