~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

MergeĀ inĀ upstream.

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.transport import get_transport
 
28
import bzrlib.ui as ui
 
29
 
 
30
 
 
31
class TestWithUpgradableBranches(TestCaseWithTransport):
 
32
 
 
33
    def setUp(self):
 
34
        super(TestWithUpgradableBranches, self).setUp()
 
35
        self.old_format = bzrdir.BzrDirFormat.get_default_format()
 
36
        self.old_ui_factory = ui.ui_factory
 
37
        self.addCleanup(self.restoreDefaults)
 
38
 
 
39
        ui.ui_factory = TestUIFactory()
 
40
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
41
        # FIXME RBC 20060120 we should be able to do this via ui calls only.
 
42
        # setup a format 5 branch we can upgrade from.
 
43
        t = get_transport(self.get_url())
 
44
        t.mkdir('format_5_branch')
 
45
        bzrdir.BzrDirFormat5().initialize(self.get_url('format_5_branch'))
 
46
        bzrdir.BzrDir.create_standalone_workingtree('current_format_branch')
 
47
        d = bzrdir.BzrDir.create('metadir_weave_branch')
 
48
        d.create_repository()
 
49
        d.create_branch()
 
50
        d.create_workingtree()
 
51
        self.run_bzr('checkout',
 
52
                     self.get_url('current_format_branch'),
 
53
                     'current_format_checkout')
 
54
 
 
55
    def restoreDefaults(self):
 
56
        bzrdir.BzrDirFormat.set_default_format(self.old_format)
 
57
        ui.ui_factory = self.old_ui_factory
 
58
 
 
59
    def test_readonly_url_error(self):
 
60
        (out, err) = self.run_bzr_captured(
 
61
            ['upgrade', self.get_readonly_url('format_5_branch')], 3)
 
62
        self.assertEqual(out, "")
 
63
        self.assertEqual(err, "bzr: ERROR: Upgrade URL cannot work with readonly URL's.\n")
 
64
 
 
65
    def test_upgrade_up_to_date(self):
 
66
        # when up to date we should get a message to that effect
 
67
        (out, err) = self.run_bzr_captured(
 
68
            ['upgrade', 'current_format_branch'], 3)
 
69
        self.assertEqual("", out)
 
70
        self.assertEqualDiff("bzr: ERROR: The branch format Bazaar-NG meta "
 
71
                             "directory, format 1 is already at the most "
 
72
                             "recent format.\n", err)
 
73
 
 
74
    def test_upgrade_up_to_date_checkout_warns_branch_left_alone(self):
 
75
        # when upgrading a checkout, the branch location and a suggestion
 
76
        # to upgrade it should be emitted even if the checkout is up to 
 
77
        # date
 
78
        (out, err) = self.run_bzr_captured(
 
79
            ['upgrade', 'current_format_checkout'], 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 Bazaar-NG meta "
 
85
                             "directory, format 1 is already at the most "
 
86
                             "recent format.\n", err)
 
87
 
 
88
    def test_upgrade_checkout(self):
 
89
        # upgrading a checkout should work
 
90
        pass
 
91
 
 
92
    def test_upgrade_repository_scans_branches(self):
 
93
        # we should get individual upgrade notes for each branch even the 
 
94
        # anonymous branch
 
95
        pass
 
96
 
 
97
    def test_ugrade_branch_in_repo(self):
 
98
        # upgrading a branch in a repo should warn about not upgrading the repo
 
99
        pass
 
100
 
 
101
    def test_upgrade_explicit_metaformat(self):
 
102
        # users can force an upgrade to metadir format.
 
103
        url = get_transport(self.get_url('format_5_branch')).base
 
104
        # check --format takes effect
 
105
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirFormat5())
 
106
        (out, err) = self.run_bzr_captured(
 
107
            ['upgrade', '--format=metadir', url])
 
108
        self.assertEqualDiff("""starting upgrade of %s
 
109
making backup of tree history
 
110
%s.bzr has been backed up to %s.bzr.backup
 
111
if conversion fails, you can move this directory back to .bzr
 
112
if it succeeds, you can remove this directory if you wish
 
113
starting upgrade from format 5 to 6
 
114
adding prefixes to weaves
 
115
adding prefixes to revision-store
 
116
starting upgrade from format 6 to metadir
 
117
finished
 
118
""" % (url, url, url), out)
 
119
        self.assertEqualDiff("", err)
 
120
        self.assertTrue(isinstance(
 
121
            bzrdir.BzrDir.open(self.get_url('format_5_branch'))._format,
 
122
            bzrdir.BzrDirMetaFormat1))
 
123
 
 
124
    def test_upgrade_explicit_knit(self):
 
125
        # users can force an upgrade to knit format from a metadir weave 
 
126
        # branch
 
127
        url = get_transport(self.get_url('metadir_weave_branch')).base
 
128
        # check --format takes effect
 
129
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirFormat5())
 
130
        (out, err) = self.run_bzr_captured(
 
131
            ['upgrade', '--format=knit', url])
 
132
        self.assertEqualDiff("""starting upgrade of %s
 
133
making backup of tree history
 
134
%s.bzr has been backed up to %s.bzr.backup
 
135
if conversion fails, you can move this directory back to .bzr
 
136
if it succeeds, you can remove this directory if you wish
 
137
starting repository conversion
 
138
repository converted
 
139
finished
 
140
""" % (url, url, url), out)
 
141
        self.assertEqualDiff("", err)
 
142
        converted_dir = bzrdir.BzrDir.open(self.get_url('metadir_weave_branch'))
 
143
        self.assertTrue(isinstance(converted_dir._format,
 
144
                                   bzrdir.BzrDirMetaFormat1))
 
145
        self.assertTrue(isinstance(converted_dir.open_repository()._format,
 
146
                                   repository.RepositoryFormatKnit1))