~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil, Patch Queue Manager, Jelmer Vernooij
  • Date: 2017-01-17 16:20:41 UTC
  • mfrom: (6619.1.2 trunk)
  • Revision ID: tarmac-20170117162041-oo62uk1qsmgc9j31
Merge 2.7 into trunk including fixes for bugs #1622039, #1644003, #1579093 and #1645017. [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2011, 2016 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
 
 
18
from bzrlib import (
 
19
    branch,
 
20
    urlutils,
 
21
    )
 
22
from bzrlib.tests import (
 
23
    script,
 
24
    )
 
25
 
 
26
 
 
27
class TestRememberMixin(object):
 
28
    """--remember and --no-remember set locations or not."""
 
29
 
 
30
    # the command to run (expecting additional arguments from the tests
 
31
    command = []
 
32
    # the dir where the command should be run (it should contain a branch for
 
33
    # which the tested locations are/will be set)
 
34
    working_dir = None
 
35
    # argument list for the first command invocation
 
36
    first_use_args = []
 
37
    # argument list for the next command invocation
 
38
    next_uses_args = []
 
39
 
 
40
    def do_command(self, *args):
 
41
        # We always expect the same result here and care only about the
 
42
        # arguments used and their consequences on the remembered locations
 
43
        out, err = self.run_bzr(self.command + list(args),
 
44
                                working_dir=self.working_dir)
 
45
 
 
46
    def test_first_use_no_option(self):
 
47
        self.do_command(*self.first_use_args)
 
48
        self.assertLocations(self.first_use_args)
 
49
 
 
50
    def test_first_use_remember(self):
 
51
        self.do_command('--remember', *self.first_use_args)
 
52
        self.assertLocations(self.first_use_args)
 
53
 
 
54
    def test_first_use_no_remember(self):
 
55
        self.do_command('--no-remember', *self.first_use_args)
 
56
        self.assertLocations([])
 
57
 
 
58
    def test_next_uses_no_option(self):
 
59
        self.setup_next_uses()
 
60
        self.do_command(*self.next_uses_args)
 
61
        self.assertLocations(self.first_use_args)
 
62
 
 
63
    def test_next_uses_remember(self):
 
64
        self.setup_next_uses()
 
65
        self.do_command('--remember', *self.next_uses_args)
 
66
        self.assertLocations(self.next_uses_args)
 
67
 
 
68
    def test_next_uses_no_remember(self):
 
69
        self.setup_next_uses()
 
70
        self.do_command('--no-remember', *self.next_uses_args)
 
71
        self.assertLocations(self.first_use_args)
 
72
 
 
73
 
 
74
class TestSendRemember(script.TestCaseWithTransportAndScript,
 
75
                       TestRememberMixin):
 
76
 
 
77
    working_dir = 'work'
 
78
    command = ['send', '-o-',]
 
79
    first_use_args = ['../parent', '../grand_parent',]
 
80
    next_uses_args = ['../new_parent', '../new_grand_parent']
 
81
 
 
82
    def setUp(self):
 
83
        super(TestSendRemember, self).setUp()
 
84
        self.run_script('''
 
85
            $ bzr init grand_parent
 
86
            $ cd grand_parent
 
87
            $ echo grand_parent > file
 
88
            $ bzr add
 
89
            $ bzr commit -m 'initial commit'
 
90
            $ cd ..
 
91
            $ bzr branch grand_parent parent
 
92
            $ cd parent
 
93
            $ echo parent > file
 
94
            $ bzr commit -m 'parent'
 
95
            $ cd ..
 
96
            $ bzr branch parent %(working_dir)s
 
97
            $ cd %(working_dir)s
 
98
            $ echo %(working_dir)s > file
 
99
            $ bzr commit -m '%(working_dir)s'
 
100
            $ cd ..
 
101
            ''' % {'working_dir': self.working_dir},
 
102
                        null_output_matches_anything=True)
 
103
 
 
104
    def setup_next_uses(self):
 
105
        # Do a first send that remembers the locations
 
106
        self.do_command(*self.first_use_args)
 
107
        # Now create some new targets
 
108
        self.run_script('''
 
109
            $ bzr branch grand_parent new_grand_parent
 
110
            $ bzr branch parent new_parent
 
111
            ''',
 
112
                        null_output_matches_anything=True)
 
113
 
 
114
    def assertLocations(self, expected_locations):
 
115
        if not expected_locations:
 
116
            expected_submit_branch, expected_public_branch = None, None
 
117
        else:
 
118
            expected_submit_branch, expected_public_branch = expected_locations
 
119
        br, _ = branch.Branch.open_containing(self.working_dir)
 
120
        self.assertEqual(expected_submit_branch, br.get_submit_branch())
 
121
        self.assertEqual(expected_public_branch, br.get_public_branch())
 
122
 
 
123
 
 
124
class TestPushRemember(script.TestCaseWithTransportAndScript,
 
125
                       TestRememberMixin):
 
126
 
 
127
    working_dir = 'work'
 
128
    command = ['push',]
 
129
    first_use_args = ['../target',]
 
130
    next_uses_args = ['../new_target']
 
131
 
 
132
    def setUp(self):
 
133
        super(TestPushRemember, self).setUp()
 
134
        self.run_script('''
 
135
            $ bzr init %(working_dir)s
 
136
            $ cd %(working_dir)s
 
137
            $ echo some content > file
 
138
            $ bzr add
 
139
            $ bzr commit -m 'initial commit'
 
140
            $ cd ..
 
141
            ''' % {'working_dir': self.working_dir},
 
142
                        null_output_matches_anything=True)
 
143
 
 
144
    def setup_next_uses(self):
 
145
        # Do a first push that remembers the location
 
146
        self.do_command(*self.first_use_args)
 
147
        # Now create some new content
 
148
        self.run_script('''
 
149
            $ cd %(working_dir)s
 
150
            $ echo new content > file
 
151
            $ bzr commit -m 'new content'
 
152
            $ cd ..
 
153
            ''' % {'working_dir': self.working_dir},
 
154
                        null_output_matches_anything=True)
 
155
 
 
156
    def assertLocations(self, expected_locations):
 
157
        br, _ = branch.Branch.open_containing(self.working_dir)
 
158
        if not expected_locations:
 
159
            self.assertEqual(None, br.get_push_location())
 
160
        else:
 
161
            expected_push_location = expected_locations[0]
 
162
            push_location = urlutils.relative_url(br.base,
 
163
                                                  br.get_push_location())
 
164
            self.assertIsSameRealPath(expected_push_location, push_location)
 
165
 
 
166
 
 
167
class TestPullRemember(script.TestCaseWithTransportAndScript,
 
168
                       TestRememberMixin):
 
169
 
 
170
    working_dir = 'work'
 
171
    command = ['pull',]
 
172
    first_use_args = ['../parent',]
 
173
    next_uses_args = ['../new_parent']
 
174
 
 
175
    def setUp(self):
 
176
        super(TestPullRemember, self).setUp()
 
177
        self.run_script('''
 
178
            $ bzr init parent
 
179
            $ cd parent
 
180
            $ echo parent > file
 
181
            $ bzr add
 
182
            $ bzr commit -m 'initial commit'
 
183
            $ cd ..
 
184
            $ bzr init %(working_dir)s
 
185
            ''' % {'working_dir': self.working_dir},
 
186
                        null_output_matches_anything=True)
 
187
 
 
188
    def setup_next_uses(self):
 
189
        # Do a first push that remembers the location
 
190
        self.do_command(*self.first_use_args)
 
191
        # Now create some new content
 
192
        self.run_script('''
 
193
            $ bzr branch parent new_parent
 
194
            $ cd new_parent
 
195
            $ echo new parent > file
 
196
            $ bzr commit -m 'new parent'
 
197
            $ cd ..
 
198
            ''' % {'working_dir': self.working_dir},
 
199
                        null_output_matches_anything=True)
 
200
 
 
201
    def assertLocations(self, expected_locations):
 
202
        br, _ = branch.Branch.open_containing(self.working_dir)
 
203
        if not expected_locations:
 
204
            self.assertEqual(None, br.get_parent())
 
205
        else:
 
206
            expected_pull_location = expected_locations[0]
 
207
            pull_location = urlutils.relative_url(br.base, br.get_parent())
 
208
            self.assertIsSameRealPath(expected_pull_location, pull_location)