/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.16.89 by Aaron Bentley
Add tests for Shelver
1
# Copyright (C) 2008 Canonical Ltd
2
#
0.16.101 by Aaron Bentley
Update GPL formatting and copyright
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.16.89 by Aaron Bentley
Add tests for Shelver
16
17
18
from cStringIO import StringIO
0.16.91 by Aaron Bentley
Test finish and quit
19
import os
0.16.108 by Aaron Bentley
Shelf supports multiple diff writers.
20
import sys
0.16.89 by Aaron Bentley
Add tests for Shelver
21
0.16.103 by Aaron Bentley
raise UserAbort instead of doing sys.exit
22
from bzrlib import errors, shelf_ui, tests
0.16.89 by Aaron Bentley
Add tests for Shelver
23
24
25
class ExpectShelver(shelf_ui.Shelver):
26
    """A variant of Shelver that intercepts console activity, for testing."""
27
4100.3.4 by Aaron Bentley
Clean up signatures
28
    def __init__(self, work_tree, target_tree, diff_writer=None,
29
                 auto=False, auto_apply=False, file_list=None, message=None,
4526.7.1 by Aaron Bentley
Make vocabulary part of reporter.
30
                 destroy=False, reporter=None):
0.16.108 by Aaron Bentley
Shelf supports multiple diff writers.
31
        shelf_ui.Shelver.__init__(self, work_tree, target_tree, diff_writer,
4100.3.4 by Aaron Bentley
Clean up signatures
32
                                  auto, auto_apply, file_list, message,
4526.7.1 by Aaron Bentley
Make vocabulary part of reporter.
33
                                  destroy, reporter=reporter)
0.16.89 by Aaron Bentley
Add tests for Shelver
34
        self.expected = []
35
        self.diff_writer = StringIO()
36
37
    def expect(self, prompt, response):
38
        self.expected.append((prompt, response))
39
40
    def prompt(self, message):
41
        try:
42
            prompt, response = self.expected.pop(0)
43
        except IndexError:
44
            raise AssertionError('Unexpected prompt: %s' % message)
45
        if prompt != message:
46
            raise AssertionError('Wrong prompt: %s' % message)
47
        return response
48
49
0.16.90 by Aaron Bentley
Handle shelving multiple diff hunks
50
LINES_AJ = 'a\nb\nc\nd\ne\nf\ng\nh\ni\nj\n'
51
52
53
LINES_ZY = 'z\nb\nc\nd\ne\nf\ng\nh\ni\ny\n'
54
55
56
LINES_AY = 'a\nb\nc\nd\ne\nf\ng\nh\ni\ny\n'
57
58
0.16.89 by Aaron Bentley
Add tests for Shelver
59
class TestShelver(tests.TestCaseWithTransport):
60
61
    def create_shelvable_tree(self):
62
        tree = self.make_branch_and_tree('tree')
0.16.90 by Aaron Bentley
Handle shelving multiple diff hunks
63
        self.build_tree_contents([('tree/foo', LINES_AJ)])
0.16.89 by Aaron Bentley
Add tests for Shelver
64
        tree.add('foo', 'foo-id')
65
        tree.commit('added foo')
0.16.90 by Aaron Bentley
Handle shelving multiple diff hunks
66
        self.build_tree_contents([('tree/foo', LINES_ZY)])
0.16.89 by Aaron Bentley
Add tests for Shelver
67
        return tree
68
69
    def test_unexpected_prompt_failure(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
70
        self.thisFailsStrictLockCheck()
0.16.89 by Aaron Bentley
Add tests for Shelver
71
        tree = self.create_shelvable_tree()
72
        shelver = ExpectShelver(tree, tree.basis_tree())
73
        e = self.assertRaises(AssertionError, shelver.run)
3990.4.1 by Daniel Watkins
Changed all shelve tests to expect a '?'.
74
        self.assertEqual('Unexpected prompt: Shelve? [yNfq?]', str(e))
0.16.89 by Aaron Bentley
Add tests for Shelver
75
76
    def test_wrong_prompt_failure(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
77
        self.thisFailsStrictLockCheck()
0.16.89 by Aaron Bentley
Add tests for Shelver
78
        tree = self.create_shelvable_tree()
79
        shelver = ExpectShelver(tree, tree.basis_tree())
80
        shelver.expect('foo', 'y')
81
        e = self.assertRaises(AssertionError, shelver.run)
3990.4.1 by Daniel Watkins
Changed all shelve tests to expect a '?'.
82
        self.assertEqual('Wrong prompt: Shelve? [yNfq?]', str(e))
0.16.89 by Aaron Bentley
Add tests for Shelver
83
84
    def test_shelve_not_diff(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
85
        self.thisFailsStrictLockCheck()
0.16.89 by Aaron Bentley
Add tests for Shelver
86
        tree = self.create_shelvable_tree()
87
        shelver = ExpectShelver(tree, tree.basis_tree())
3990.4.1 by Daniel Watkins
Changed all shelve tests to expect a '?'.
88
        shelver.expect('Shelve? [yNfq?]', 'n')
89
        shelver.expect('Shelve? [yNfq?]', 'n')
0.16.89 by Aaron Bentley
Add tests for Shelver
90
        # No final shelving prompt because no changes were selected
91
        shelver.run()
0.16.90 by Aaron Bentley
Handle shelving multiple diff hunks
92
        self.assertFileEqual(LINES_ZY, 'tree/foo')
0.16.89 by Aaron Bentley
Add tests for Shelver
93
94
    def test_shelve_diff_no(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
95
        self.thisFailsStrictLockCheck()
0.16.89 by Aaron Bentley
Add tests for Shelver
96
        tree = self.create_shelvable_tree()
97
        shelver = ExpectShelver(tree, tree.basis_tree())
3990.4.1 by Daniel Watkins
Changed all shelve tests to expect a '?'.
98
        shelver.expect('Shelve? [yNfq?]', 'y')
99
        shelver.expect('Shelve? [yNfq?]', 'y')
100
        shelver.expect('Shelve 2 change(s)? [yNfq?]', 'n')
0.16.89 by Aaron Bentley
Add tests for Shelver
101
        shelver.run()
0.16.90 by Aaron Bentley
Handle shelving multiple diff hunks
102
        self.assertFileEqual(LINES_ZY, 'tree/foo')
0.16.89 by Aaron Bentley
Add tests for Shelver
103
104
    def test_shelve_diff(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
105
        self.thisFailsStrictLockCheck()
0.16.89 by Aaron Bentley
Add tests for Shelver
106
        tree = self.create_shelvable_tree()
107
        shelver = ExpectShelver(tree, tree.basis_tree())
3990.4.1 by Daniel Watkins
Changed all shelve tests to expect a '?'.
108
        shelver.expect('Shelve? [yNfq?]', 'y')
109
        shelver.expect('Shelve? [yNfq?]', 'y')
110
        shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y')
0.16.90 by Aaron Bentley
Handle shelving multiple diff hunks
111
        shelver.run()
112
        self.assertFileEqual(LINES_AJ, 'tree/foo')
113
114
    def test_shelve_one_diff(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
115
        self.thisFailsStrictLockCheck()
0.16.90 by Aaron Bentley
Handle shelving multiple diff hunks
116
        tree = self.create_shelvable_tree()
117
        shelver = ExpectShelver(tree, tree.basis_tree())
3990.4.1 by Daniel Watkins
Changed all shelve tests to expect a '?'.
118
        shelver.expect('Shelve? [yNfq?]', 'y')
119
        shelver.expect('Shelve? [yNfq?]', 'n')
120
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
0.16.89 by Aaron Bentley
Add tests for Shelver
121
        shelver.run()
0.16.90 by Aaron Bentley
Handle shelving multiple diff hunks
122
        self.assertFileEqual(LINES_AY, 'tree/foo')
0.16.89 by Aaron Bentley
Add tests for Shelver
123
0.16.92 by Aaron Bentley
Test kind, add, binary, --all
124
    def test_shelve_binary_change(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
125
        self.thisFailsStrictLockCheck()
0.16.92 by Aaron Bentley
Test kind, add, binary, --all
126
        tree = self.create_shelvable_tree()
127
        self.build_tree_contents([('tree/foo', '\x00')])
128
        shelver = ExpectShelver(tree, tree.basis_tree())
3990.4.1 by Daniel Watkins
Changed all shelve tests to expect a '?'.
129
        shelver.expect('Shelve binary changes? [yNfq?]', 'y')
130
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
0.16.92 by Aaron Bentley
Test kind, add, binary, --all
131
        shelver.run()
132
        self.assertFileEqual(LINES_AJ, 'tree/foo')
133
0.16.89 by Aaron Bentley
Add tests for Shelver
134
    def test_shelve_rename(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
135
        self.thisFailsStrictLockCheck()
0.16.89 by Aaron Bentley
Add tests for Shelver
136
        tree = self.create_shelvable_tree()
137
        tree.rename_one('foo', 'bar')
138
        shelver = ExpectShelver(tree, tree.basis_tree())
3990.4.1 by Daniel Watkins
Changed all shelve tests to expect a '?'.
139
        shelver.expect('Shelve renaming "foo" => "bar"? [yNfq?]', 'y')
140
        shelver.expect('Shelve? [yNfq?]', 'y')
141
        shelver.expect('Shelve? [yNfq?]', 'y')
142
        shelver.expect('Shelve 3 change(s)? [yNfq?]', 'y')
0.16.89 by Aaron Bentley
Add tests for Shelver
143
        shelver.run()
0.16.90 by Aaron Bentley
Handle shelving multiple diff hunks
144
        self.assertFileEqual(LINES_AJ, 'tree/foo')
0.16.91 by Aaron Bentley
Test finish and quit
145
146
    def test_shelve_deletion(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
147
        self.thisFailsStrictLockCheck()
0.16.91 by Aaron Bentley
Test finish and quit
148
        tree = self.create_shelvable_tree()
149
        os.unlink('tree/foo')
150
        shelver = ExpectShelver(tree, tree.basis_tree())
3990.4.1 by Daniel Watkins
Changed all shelve tests to expect a '?'.
151
        shelver.expect('Shelve removing file "foo"? [yNfq?]', 'y')
152
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
0.16.91 by Aaron Bentley
Test finish and quit
153
        shelver.run()
154
        self.assertFileEqual(LINES_AJ, 'tree/foo')
155
0.16.92 by Aaron Bentley
Test kind, add, binary, --all
156
    def test_shelve_creation(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
157
        self.thisFailsStrictLockCheck()
0.16.92 by Aaron Bentley
Test kind, add, binary, --all
158
        tree = self.make_branch_and_tree('tree')
159
        tree.commit('add tree root')
160
        self.build_tree(['tree/foo'])
161
        tree.add('foo')
162
        shelver = ExpectShelver(tree, tree.basis_tree())
3990.4.1 by Daniel Watkins
Changed all shelve tests to expect a '?'.
163
        shelver.expect('Shelve adding file "foo"? [yNfq?]', 'y')
164
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
0.16.92 by Aaron Bentley
Test kind, add, binary, --all
165
        shelver.run()
166
        self.failIfExists('tree/foo')
167
168
    def test_shelve_kind_change(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
169
        self.thisFailsStrictLockCheck()
0.16.92 by Aaron Bentley
Test kind, add, binary, --all
170
        tree = self.create_shelvable_tree()
171
        os.unlink('tree/foo')
172
        os.mkdir('tree/foo')
173
        shelver = ExpectShelver(tree, tree.basis_tree())
3990.4.1 by Daniel Watkins
Changed all shelve tests to expect a '?'.
174
        shelver.expect('Shelve changing "foo" from file to directory? [yNfq?]',
0.16.92 by Aaron Bentley
Test kind, add, binary, --all
175
                       'y')
3990.4.1 by Daniel Watkins
Changed all shelve tests to expect a '?'.
176
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
0.16.92 by Aaron Bentley
Test kind, add, binary, --all
177
4119.5.1 by James Westby
Shelve can now shelve changes to a symlink's target.
178
    def test_shelve_modify_target(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
179
        self.thisFailsStrictLockCheck()
4526.6.12 by Aaron Bentley
Updates from review.
180
        self.requireFeature(tests.SymlinkFeature)
4119.5.1 by James Westby
Shelve can now shelve changes to a symlink's target.
181
        tree = self.create_shelvable_tree()
182
        os.symlink('bar', 'tree/baz')
183
        tree.add('baz', 'baz-id')
184
        tree.commit("Add symlink")
185
        os.unlink('tree/baz')
186
        os.symlink('vax', 'tree/baz')
187
        shelver = ExpectShelver(tree, tree.basis_tree())
188
        shelver.expect('Shelve changing target of "baz" from "bar" to '
189
                '"vax"? [yNfq?]', 'y')
190
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
191
        shelver.run()
192
        self.assertEqual('bar', os.readlink('tree/baz'))
193
0.16.91 by Aaron Bentley
Test finish and quit
194
    def test_shelve_finish(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
195
        self.thisFailsStrictLockCheck()
0.16.91 by Aaron Bentley
Test finish and quit
196
        tree = self.create_shelvable_tree()
197
        shelver = ExpectShelver(tree, tree.basis_tree())
3990.4.1 by Daniel Watkins
Changed all shelve tests to expect a '?'.
198
        shelver.expect('Shelve? [yNfq?]', 'f')
199
        shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y')
0.16.91 by Aaron Bentley
Test finish and quit
200
        shelver.run()
201
        self.assertFileEqual(LINES_AJ, 'tree/foo')
202
203
    def test_shelve_quit(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
204
        self.thisFailsStrictLockCheck()
0.16.91 by Aaron Bentley
Test finish and quit
205
        tree = self.create_shelvable_tree()
206
        shelver = ExpectShelver(tree, tree.basis_tree())
3990.4.1 by Daniel Watkins
Changed all shelve tests to expect a '?'.
207
        shelver.expect('Shelve? [yNfq?]', 'q')
0.16.103 by Aaron Bentley
raise UserAbort instead of doing sys.exit
208
        self.assertRaises(errors.UserAbort, shelver.run)
0.16.91 by Aaron Bentley
Test finish and quit
209
        self.assertFileEqual(LINES_ZY, 'tree/foo')
0.16.92 by Aaron Bentley
Test kind, add, binary, --all
210
211
    def test_shelve_all(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
212
        self.thisFailsStrictLockCheck()
0.16.92 by Aaron Bentley
Test kind, add, binary, --all
213
        tree = self.create_shelvable_tree()
0.16.108 by Aaron Bentley
Shelf supports multiple diff writers.
214
        ExpectShelver.from_args(sys.stdout, all=True, directory='tree').run()
0.16.92 by Aaron Bentley
Test kind, add, binary, --all
215
        self.assertFileEqual(LINES_AJ, 'tree/foo')
0.16.93 by Aaron Bentley
Test shelving one file
216
217
    def test_shelve_filename(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
218
        self.thisFailsStrictLockCheck()
0.16.93 by Aaron Bentley
Test shelving one file
219
        tree = self.create_shelvable_tree()
220
        self.build_tree(['tree/bar'])
221
        tree.add('bar')
222
        shelver = ExpectShelver(tree, tree.basis_tree(), file_list=['bar'])
3990.4.1 by Daniel Watkins
Changed all shelve tests to expect a '?'.
223
        shelver.expect('Shelve adding file "bar"? [yNfq?]', 'y')
224
        shelver.expect('Shelve 1 change(s)? [yNfq?]', 'y')
0.16.93 by Aaron Bentley
Test shelving one file
225
        shelver.run()
0.16.94 by Aaron Bentley
Add unshelve tests
226
3990.4.2 by Daniel Watkins
Added test for help option.
227
    def test_shelve_help(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
228
        self.thisFailsStrictLockCheck()
3990.4.2 by Daniel Watkins
Added test for help option.
229
        tree = self.create_shelvable_tree()
230
        shelver = ExpectShelver(tree, tree.basis_tree())
231
        shelver.expect('Shelve? [yNfq?]', '?')
232
        shelver.expect('Shelve? [(y)es, (N)o, (f)inish, or (q)uit]', 'f')
233
        shelver.expect('Shelve 2 change(s)? [yNfq?]', 'y')
234
        shelver.run()
235
4100.3.1 by Aaron Bentley
Implement shelve --destroy
236
    def test_shelve_distroy(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
237
        self.thisFailsStrictLockCheck()
4100.3.1 by Aaron Bentley
Implement shelve --destroy
238
        tree = self.create_shelvable_tree()
239
        shelver = shelf_ui.Shelver.from_args(sys.stdout, all=True,
240
                                             directory='tree', destroy=True)
241
        shelver.run()
242
        self.assertIs(None, tree.get_shelf_manager().last_shelf())
243
        self.assertFileEqual(LINES_AJ, 'tree/foo')
244
0.16.94 by Aaron Bentley
Add unshelve tests
245
4526.7.1 by Aaron Bentley
Make vocabulary part of reporter.
246
class TestApplyReporter(TestShelver):
4526.6.1 by Aaron Bentley
Reverse the way changes are described by Shelver.
247
248
    def test_shelve_not_diff(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
249
        self.thisFailsStrictLockCheck()
4526.6.1 by Aaron Bentley
Reverse the way changes are described by Shelver.
250
        tree = self.create_shelvable_tree()
4526.7.1 by Aaron Bentley
Make vocabulary part of reporter.
251
        shelver = ExpectShelver(tree, tree.basis_tree(),
252
                                reporter=shelf_ui.ApplyReporter())
4526.6.1 by Aaron Bentley
Reverse the way changes are described by Shelver.
253
        shelver.expect('Apply change? [yNfq?]', 'n')
254
        shelver.expect('Apply change? [yNfq?]', 'n')
255
        # No final shelving prompt because no changes were selected
256
        shelver.run()
257
        self.assertFileEqual(LINES_ZY, 'tree/foo')
258
259
    def test_shelve_diff_no(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
260
        self.thisFailsStrictLockCheck()
4526.6.1 by Aaron Bentley
Reverse the way changes are described by Shelver.
261
        tree = self.create_shelvable_tree()
4526.7.1 by Aaron Bentley
Make vocabulary part of reporter.
262
        shelver = ExpectShelver(tree, tree.basis_tree(),
263
                                reporter=shelf_ui.ApplyReporter())
4526.6.1 by Aaron Bentley
Reverse the way changes are described by Shelver.
264
        shelver.expect('Apply change? [yNfq?]', 'y')
265
        shelver.expect('Apply change? [yNfq?]', 'y')
266
        shelver.expect('Apply 2 change(s)? [yNfq?]', 'n')
267
        shelver.run()
268
        self.assertFileEqual(LINES_ZY, 'tree/foo')
269
270
    def test_shelve_diff(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
271
        self.thisFailsStrictLockCheck()
4526.6.1 by Aaron Bentley
Reverse the way changes are described by Shelver.
272
        tree = self.create_shelvable_tree()
4526.7.1 by Aaron Bentley
Make vocabulary part of reporter.
273
        shelver = ExpectShelver(tree, tree.basis_tree(),
274
                                reporter=shelf_ui.ApplyReporter())
4526.6.1 by Aaron Bentley
Reverse the way changes are described by Shelver.
275
        shelver.expect('Apply change? [yNfq?]', 'y')
276
        shelver.expect('Apply change? [yNfq?]', 'y')
277
        shelver.expect('Apply 2 change(s)? [yNfq?]', 'y')
278
        shelver.run()
279
        self.assertFileEqual(LINES_AJ, 'tree/foo')
280
281
    def test_shelve_binary_change(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
282
        self.thisFailsStrictLockCheck()
4526.6.1 by Aaron Bentley
Reverse the way changes are described by Shelver.
283
        tree = self.create_shelvable_tree()
284
        self.build_tree_contents([('tree/foo', '\x00')])
4526.7.1 by Aaron Bentley
Make vocabulary part of reporter.
285
        shelver = ExpectShelver(tree, tree.basis_tree(),
286
                                reporter=shelf_ui.ApplyReporter())
4526.6.1 by Aaron Bentley
Reverse the way changes are described by Shelver.
287
        shelver.expect('Apply binary changes? [yNfq?]', 'y')
288
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
289
        shelver.run()
290
        self.assertFileEqual(LINES_AJ, 'tree/foo')
291
292
    def test_shelve_rename(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
293
        self.thisFailsStrictLockCheck()
4526.6.1 by Aaron Bentley
Reverse the way changes are described by Shelver.
294
        tree = self.create_shelvable_tree()
295
        tree.rename_one('foo', 'bar')
4526.7.1 by Aaron Bentley
Make vocabulary part of reporter.
296
        shelver = ExpectShelver(tree, tree.basis_tree(),
297
                                reporter=shelf_ui.ApplyReporter())
4526.6.1 by Aaron Bentley
Reverse the way changes are described by Shelver.
298
        shelver.expect('Rename "bar" => "foo"? [yNfq?]', 'y')
299
        shelver.expect('Apply change? [yNfq?]', 'y')
300
        shelver.expect('Apply change? [yNfq?]', 'y')
301
        shelver.expect('Apply 3 change(s)? [yNfq?]', 'y')
302
        shelver.run()
303
        self.assertFileEqual(LINES_AJ, 'tree/foo')
304
305
    def test_shelve_deletion(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
306
        self.thisFailsStrictLockCheck()
4526.6.1 by Aaron Bentley
Reverse the way changes are described by Shelver.
307
        tree = self.create_shelvable_tree()
308
        os.unlink('tree/foo')
4526.7.1 by Aaron Bentley
Make vocabulary part of reporter.
309
        shelver = ExpectShelver(tree, tree.basis_tree(),
310
                                reporter=shelf_ui.ApplyReporter())
4526.6.1 by Aaron Bentley
Reverse the way changes are described by Shelver.
311
        shelver.expect('Add file "foo"? [yNfq?]', 'y')
312
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
313
        shelver.run()
314
        self.assertFileEqual(LINES_AJ, 'tree/foo')
315
316
    def test_shelve_creation(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
317
        self.thisFailsStrictLockCheck()
4526.6.1 by Aaron Bentley
Reverse the way changes are described by Shelver.
318
        tree = self.make_branch_and_tree('tree')
319
        tree.commit('add tree root')
320
        self.build_tree(['tree/foo'])
321
        tree.add('foo')
4526.7.1 by Aaron Bentley
Make vocabulary part of reporter.
322
        shelver = ExpectShelver(tree, tree.basis_tree(),
323
                                reporter=shelf_ui.ApplyReporter())
4526.6.1 by Aaron Bentley
Reverse the way changes are described by Shelver.
324
        shelver.expect('Delete file "foo"? [yNfq?]', 'y')
325
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
326
        shelver.run()
327
        self.failIfExists('tree/foo')
328
329
    def test_shelve_kind_change(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
330
        self.thisFailsStrictLockCheck()
4526.6.1 by Aaron Bentley
Reverse the way changes are described by Shelver.
331
        tree = self.create_shelvable_tree()
332
        os.unlink('tree/foo')
333
        os.mkdir('tree/foo')
4526.7.1 by Aaron Bentley
Make vocabulary part of reporter.
334
        shelver = ExpectShelver(tree, tree.basis_tree(),
335
                               reporter=shelf_ui.ApplyReporter())
4526.6.1 by Aaron Bentley
Reverse the way changes are described by Shelver.
336
        shelver.expect('Change "foo" from directory to a file? [yNfq?]', 'y')
337
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
338
339
    def test_shelve_modify_target(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
340
        self.thisFailsStrictLockCheck()
4526.6.12 by Aaron Bentley
Updates from review.
341
        self.requireFeature(tests.SymlinkFeature)
4526.6.1 by Aaron Bentley
Reverse the way changes are described by Shelver.
342
        tree = self.create_shelvable_tree()
343
        os.symlink('bar', 'tree/baz')
344
        tree.add('baz', 'baz-id')
345
        tree.commit("Add symlink")
346
        os.unlink('tree/baz')
347
        os.symlink('vax', 'tree/baz')
4526.7.1 by Aaron Bentley
Make vocabulary part of reporter.
348
        shelver = ExpectShelver(tree, tree.basis_tree(),
349
                                reporter=shelf_ui.ApplyReporter())
4526.6.1 by Aaron Bentley
Reverse the way changes are described by Shelver.
350
        shelver.expect('Change target of "baz" from "vax" to "bar"? [yNfq?]',
351
                       'y')
352
        shelver.expect('Apply 1 change(s)? [yNfq?]', 'y')
353
        shelver.run()
354
        self.assertEqual('bar', os.readlink('tree/baz'))
355
356
0.16.94 by Aaron Bentley
Add unshelve tests
357
class TestUnshelver(tests.TestCaseWithTransport):
358
359
    def create_tree_with_shelf(self):
360
        tree = self.make_branch_and_tree('tree')
361
        self.build_tree_contents([('tree/foo', LINES_AJ)])
362
        tree.add('foo', 'foo-id')
363
        tree.commit('added foo')
364
        self.build_tree_contents([('tree/foo', LINES_ZY)])
0.16.97 by Aaron Bentley
Turn diff_file and text_differ into instance variables.
365
        shelf_ui.Shelver(tree, tree.basis_tree(), auto_apply=True,
0.16.94 by Aaron Bentley
Add unshelve tests
366
                         auto=True).run()
367
        return tree
368
369
    def test_unshelve(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
370
        self.thisFailsStrictLockCheck()
0.16.94 by Aaron Bentley
Add unshelve tests
371
        tree = self.create_tree_with_shelf()
372
        tree.lock_write()
373
        self.addCleanup(tree.unlock)
374
        manager = tree.get_shelf_manager()
375
        shelf_ui.Unshelver(tree, manager, 1, True, True, True).run()
376
        self.assertFileEqual(LINES_ZY, 'tree/foo')
377
378
    def test_unshelve_args(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
379
        self.thisFailsStrictLockCheck()
0.16.94 by Aaron Bentley
Add unshelve tests
380
        tree = self.create_tree_with_shelf()
381
        shelf_ui.Unshelver.from_args(directory='tree').run()
382
        self.assertFileEqual(LINES_ZY, 'tree/foo')
383
        self.assertIs(None, tree.get_shelf_manager().last_shelf())
384
385
    def test_unshelve_args_dry_run(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
386
        self.thisFailsStrictLockCheck()
0.16.94 by Aaron Bentley
Add unshelve tests
387
        tree = self.create_tree_with_shelf()
388
        shelf_ui.Unshelver.from_args(directory='tree', action='dry-run').run()
389
        self.assertFileEqual(LINES_AJ, 'tree/foo')
390
        self.assertEqual(1, tree.get_shelf_manager().last_shelf())
391
392
    def test_unshelve_args_delete_only(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
393
        self.thisFailsStrictLockCheck()
0.16.94 by Aaron Bentley
Add unshelve tests
394
        tree = self.make_branch_and_tree('tree')
395
        manager = tree.get_shelf_manager()
396
        shelf_file = manager.new_shelf()[1]
397
        try:
398
            shelf_file.write('garbage')
399
        finally:
400
            shelf_file.close()
401
        unshelver = shelf_ui.Unshelver.from_args(directory='tree',
402
                                                 action='delete-only')
403
        unshelver.run()
404
        self.assertIs(None, manager.last_shelf())
3990.2.1 by Daniel Watkins
Added test for unshelve being passed an invalid shelf_id.
405
406
    def test_unshelve_args_invalid_shelf_id(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
407
        self.thisFailsStrictLockCheck()
3990.2.1 by Daniel Watkins
Added test for unshelve being passed an invalid shelf_id.
408
        tree = self.make_branch_and_tree('tree')
409
        manager = tree.get_shelf_manager()
410
        shelf_file = manager.new_shelf()[1]
411
        try:
412
            shelf_file.write('garbage')
413
        finally:
414
            shelf_file.close()
415
        self.assertRaises(errors.InvalidShelfId,
3999.1.1 by Ian Clatworthy
Improve shelf documentation & fix backtrace (Daniel Watkins)
416
            shelf_ui.Unshelver.from_args, directory='tree',
417
            action='delete-only', shelf_id='foo')