~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Aaron Bentley
  • Date: 2007-02-06 14:52:16 UTC
  • mfrom: (2266 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2268.
  • Revision ID: abentley@panoramicfeedback.com-20070206145216-fcpi8o3ufvuzwbp9
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2006 Canonical Ltd
2
2
# Authors: Robert Collins <robert.collins@canonical.com>
3
 
#          and others
 
3
# -*- coding: utf-8 -*-
4
4
#
5
5
# This program is free software; you can redistribute it and/or modify
6
6
# it under the terms of the GNU General Public License as published by
20
20
 
21
21
import os
22
22
 
23
 
from bzrlib import (
24
 
    bzrdir,
25
 
    repository,
26
 
    ui,
27
 
    )
28
 
from bzrlib.tests import (
29
 
    TestCaseInTempDir,
30
 
    TestCaseWithTransport,
31
 
    TestUIFactory,
32
 
    )
 
23
import bzrlib
 
24
import bzrlib.bzrdir as bzrdir
 
25
import bzrlib.repository as repository
 
26
from bzrlib.tests import TestCaseWithTransport
 
27
from bzrlib.tests.blackbox import TestUIFactory
33
28
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
34
29
from bzrlib.transport import get_transport
35
 
from bzrlib.repofmt.knitrepo import (
36
 
    RepositoryFormatKnit1,
37
 
    )
 
30
import bzrlib.ui as ui
38
31
 
39
32
 
40
33
class TestWithUpgradableBranches(TestCaseWithTransport):
61
54
        bzrdir.BzrDirFormat._set_default_format(self.old_format)
62
55
 
63
56
    def test_readonly_url_error(self):
64
 
        (out, err) = self.run_bzr(
65
 
            ['upgrade', self.get_readonly_url('format_5_branch')], retcode=3)
 
57
        (out, err) = self.run_bzr_captured(
 
58
            ['upgrade', self.get_readonly_url('format_5_branch')], 3)
66
59
        self.assertEqual(out, "")
67
60
        self.assertEqual(err, "bzr: ERROR: Upgrade URL cannot work with readonly URLs.\n")
68
61
 
69
62
    def test_upgrade_up_to_date(self):
70
63
        # when up to date we should get a message to that effect
71
 
        (out, err) = self.run_bzr('upgrade current_format_branch', retcode=3)
 
64
        (out, err) = self.run_bzr_captured(
 
65
            ['upgrade', 'current_format_branch'], 3)
72
66
        self.assertEqual("", out)
73
67
        self.assertEqualDiff("bzr: ERROR: The branch format Bazaar-NG meta "
74
68
                             "directory, format 1 is already at the most "
78
72
        # when upgrading a checkout, the branch location and a suggestion
79
73
        # to upgrade it should be emitted even if the checkout is up to 
80
74
        # date
81
 
        (out, err) = self.run_bzr('upgrade current_format_checkout', retcode=3)
 
75
        (out, err) = self.run_bzr_captured(
 
76
            ['upgrade', 'current_format_checkout'], 3)
82
77
        self.assertEqual("This is a checkout. The branch (%s) needs to be "
83
 
                         "upgraded separately.\n"
 
78
                         "upgraded separately.\n" 
84
79
                         % get_transport(self.get_url('current_format_branch')).base,
85
80
                         out)
86
81
        self.assertEqualDiff("bzr: ERROR: The branch format Bazaar-NG meta "
105
100
        url = get_transport(self.get_url('format_5_branch')).base
106
101
        # check --format takes effect
107
102
        bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
108
 
        (out, err) = self.run_bzr(
 
103
        (out, err) = self.run_bzr_captured(
109
104
            ['upgrade', '--format=metaweave', url])
110
105
        self.assertEqualDiff("""starting upgrade of %s
111
106
making backup of tree history
112
 
%s.bzr has been backed up to %sbackup.bzr
 
107
%s.bzr has been backed up to %s.bzr.backup
113
108
if conversion fails, you can move this directory back to .bzr
114
109
if it succeeds, you can remove this directory if you wish
115
110
starting upgrade from format 5 to 6
129
124
        url = get_transport(self.get_url('metadir_weave_branch')).base
130
125
        # check --format takes effect
131
126
        bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
132
 
        (out, err) = self.run_bzr(
 
127
        (out, err) = self.run_bzr_captured(
133
128
            ['upgrade', '--format=knit', url])
134
129
        self.assertEqualDiff("""starting upgrade of %s
135
130
making backup of tree history
136
 
%s.bzr has been backed up to %sbackup.bzr
 
131
%s.bzr has been backed up to %s.bzr.backup
137
132
if conversion fails, you can move this directory back to .bzr
138
133
if it succeeds, you can remove this directory if you wish
139
134
starting repository conversion
145
140
        self.assertTrue(isinstance(converted_dir._format,
146
141
                                   bzrdir.BzrDirMetaFormat1))
147
142
        self.assertTrue(isinstance(converted_dir.open_repository()._format,
148
 
                                   RepositoryFormatKnit1))
 
143
                                   repository.RepositoryFormatKnit1))
149
144
 
150
145
    def test_upgrade_repo(self):
151
 
        self.run_bzr('init-repository --format=metaweave repo')
152
 
        self.run_bzr('upgrade --format=knit repo')
 
146
        self.run_bzr('init-repository', '--format=metaweave', 'repo')
 
147
        self.run_bzr('upgrade', '--format=knit', 'repo')
153
148
 
154
149
 
155
150
class SFTPTests(TestCaseWithSFTPServer):
166
161
        ui.ui_factory = self.old_ui_factory
167
162
 
168
163
    def test_upgrade_url(self):
169
 
        self.run_bzr('init --format=weave')
 
164
        self.run_bzr('init', '--format=weave')
170
165
        t = get_transport(self.get_url())
171
166
        url = t.base
172
 
        out, err = self.run_bzr(['upgrade', '--format=knit', url])
 
167
        out, err = self.run_bzr('upgrade', '--format=knit', url)
173
168
        self.assertEqualDiff("""starting upgrade of %s
174
169
making backup of tree history
175
 
%s.bzr has been backed up to %sbackup.bzr
 
170
%s.bzr has been backed up to %s.bzr.backup
176
171
if conversion fails, you can move this directory back to .bzr
177
172
if it succeeds, you can remove this directory if you wish
178
173
starting upgrade from format 6 to metadir
181
176
finished
182
177
""" % (url, url, url), out)
183
178
        self.assertEqual('', err)
184
 
 
185
 
 
186
 
class UpgradeRecommendedTests(TestCaseInTempDir):
187
 
 
188
 
    def test_recommend_upgrade_wt4(self):
189
 
        # using a deprecated format gives a warning
190
 
        self.run_bzr('init --knit a')
191
 
        out, err = self.run_bzr('status a')
192
 
        self.assertContainsRe(err, 'bzr upgrade .*[/\\\\]a')
193
 
 
194
 
    def test_no_upgrade_recommendation_from_bzrdir(self):
195
 
        # we should only get a recommendation to upgrade when we're accessing
196
 
        # the actual workingtree, not when we only open a bzrdir that contains
197
 
        # an old workngtree
198
 
        self.run_bzr('init --knit a')
199
 
        out, err = self.run_bzr('revno a')
200
 
        if err.find('upgrade') > -1:
201
 
            self.fail("message shouldn't suggest upgrade:\n%s" % err)