~bzr-pqm/bzr/bzr.dev

1728.2.1 by Martin Pool
Remove duplicated RevisionSpec_revs (guillaume)
1
# Copyright (C) 2004, 2005, 2006 by Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
897 by Martin Pool
- merge john's revision-naming code
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
897 by Martin Pool
- merge john's revision-naming code
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
897 by Martin Pool
- merge john's revision-naming code
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
1948.4.12 by John Arbash Meinel
Some tests for the date: spec
17
import datetime
974.1.52 by aaron.bentley at utoronto
Merged mpool's latest changes (~0.0.7)
18
import os
1185.1.39 by Robert Collins
Robey Pointers before: namespace to clear up usage of dates in revision parameters
19
import time
1432 by Robert Collins
branch: namespace
20
1948.4.1 by John Arbash Meinel
Update number parsers to raise InvalidRevisionSpec. Update revno: itself so it supports negative numbers
21
from bzrlib import (
22
    errors,
23
    )
1534.1.16 by Robert Collins
Merge from jam-integration.
24
from bzrlib.builtins import merge
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
25
from bzrlib.tests import TestCaseWithTransport
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
26
from bzrlib.revisionspec import RevisionSpec
27
28
29
def spec_in_history(spec, branch):
30
    """A simple helper to change a revision spec into a branch search"""
31
    return RevisionSpec.from_string(spec).in_history(branch)
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
32
33
1948.4.3 by John Arbash Meinel
Create direct tests for RevisionSpec_int
34
# Basic class, which just creates a really basic set of revisions
35
class TestRevisionSpec(TestCaseWithTransport):
36
37
    def setUp(self):
38
        super(TestRevisionSpec, self).setUp()
39
40
        self.tree = self.make_branch_and_tree('tree')
41
        self.build_tree(['tree/a'])
42
        self.tree.add(['a'])
43
        self.tree.commit('a', rev_id='r1')
1948.4.4 by John Arbash Meinel
Update the test tree to include a non-mainline revision
44
45
        self.tree2 = self.tree.bzrdir.sprout('tree2').open_workingtree()
46
        self.tree2.commit('alt', rev_id='alt_r2')
47
48
        self.tree.branch.repository.fetch(self.tree2.branch.repository,
49
                                          revision_id='alt_r2')
50
        self.tree.set_pending_merges(['alt_r2'])
1948.4.3 by John Arbash Meinel
Create direct tests for RevisionSpec_int
51
        self.tree.commit('second', rev_id='r2')
52
53
    def get_in_history(self, revision_spec):
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
54
        return spec_in_history(revision_spec, self.tree.branch)
1948.4.3 by John Arbash Meinel
Create direct tests for RevisionSpec_int
55
56
    def assertInHistoryIs(self, exp_revno, exp_revision_id, revision_spec):
57
        rev_info = self.get_in_history(revision_spec)
58
        self.assertEqual(exp_revno, rev_info.revno,
59
                         'Revision spec: %s returned wrong revno: %s != %s'
60
                         % (revision_spec, exp_revno, rev_info.revno))
61
        self.assertEqual(exp_revision_id, rev_info.rev_id,
62
                         'Revision spec: %s returned wrong revision id:'
63
                         ' %s != %s'
64
                         % (revision_spec, exp_revision_id, rev_info.rev_id))
65
1948.4.23 by John Arbash Meinel
Change the handling of negative numbers, to be trapped at revno 1
66
    def assertInvalid(self, revision_spec, extra=''):
1948.4.3 by John Arbash Meinel
Create direct tests for RevisionSpec_int
67
        try:
68
            self.get_in_history(revision_spec)
69
        except errors.InvalidRevisionSpec, e:
1948.4.23 by John Arbash Meinel
Change the handling of negative numbers, to be trapped at revno 1
70
            self.assertEqual(revision_spec, e.spec)
1948.4.3 by John Arbash Meinel
Create direct tests for RevisionSpec_int
71
            self.assertEqual(extra, e.extra)
1948.4.5 by John Arbash Meinel
Fix tests for negative entries, and add tests for revno:
72
        else:
73
            self.fail('Expected InvalidRevisionSpec to be raised for %s'
74
                      % (revision_spec,))
1948.4.3 by John Arbash Meinel
Create direct tests for RevisionSpec_int
75
76
1948.4.19 by John Arbash Meinel
All old tests are covered elsewhere
77
class TestOddRevisionSpec(TestRevisionSpec):
78
    """Test things that aren't normally thought of as revision specs"""
79
80
    def test_none(self):
81
        self.assertInHistoryIs(0, None, None)
82
83
    def test_object(self):
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
84
        self.assertRaises(TypeError, RevisionSpec.from_string, object())
1948.4.19 by John Arbash Meinel
All old tests are covered elsewhere
85
1948.4.25 by John Arbash Meinel
Check that invalid specs are properly handled
86
    def test_unregistered_spec(self):
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
87
        self.assertRaises(errors.NoSuchRevisionSpec,
88
                          RevisionSpec.from_string, 'foo')
89
        self.assertRaises(errors.NoSuchRevisionSpec,
90
                          RevisionSpec.from_string, '123a')
1948.4.32 by John Arbash Meinel
Clean up __repr__, as well as add tests that we can handle -r12:branch/
91
92
93
class TestRevisionSpec_revno(TestRevisionSpec):
94
95
    def test_positive_int(self):
1948.4.3 by John Arbash Meinel
Create direct tests for RevisionSpec_int
96
        self.assertInHistoryIs(0, None, '0')
97
        self.assertInHistoryIs(1, 'r1', '1')
98
        self.assertInHistoryIs(2, 'r2', '2')
99
1948.4.23 by John Arbash Meinel
Change the handling of negative numbers, to be trapped at revno 1
100
        self.assertInvalid('3')
1948.4.3 by John Arbash Meinel
Create direct tests for RevisionSpec_int
101
1948.4.32 by John Arbash Meinel
Clean up __repr__, as well as add tests that we can handle -r12:branch/
102
    def test_negative_int(self):
1948.4.3 by John Arbash Meinel
Create direct tests for RevisionSpec_int
103
        self.assertInHistoryIs(2, 'r2', '-1')
104
        self.assertInHistoryIs(1, 'r1', '-2')
105
1948.4.23 by John Arbash Meinel
Change the handling of negative numbers, to be trapped at revno 1
106
        self.assertInHistoryIs(1, 'r1', '-3')
107
        self.assertInHistoryIs(1, 'r1', '-4')
108
        self.assertInHistoryIs(1, 'r1', '-100')
1948.4.5 by John Arbash Meinel
Fix tests for negative entries, and add tests for revno:
109
110
    def test_positive(self):
111
        self.assertInHistoryIs(0, None, 'revno:0')
112
        self.assertInHistoryIs(1, 'r1', 'revno:1')
113
        self.assertInHistoryIs(2, 'r2', 'revno:2')
114
115
        self.assertInvalid('revno:3')
116
117
    def test_negative(self):
118
        self.assertInHistoryIs(2, 'r2', 'revno:-1')
119
        self.assertInHistoryIs(1, 'r1', 'revno:-2')
120
1948.4.23 by John Arbash Meinel
Change the handling of negative numbers, to be trapped at revno 1
121
        self.assertInHistoryIs(1, 'r1', 'revno:-3')
122
        self.assertInHistoryIs(1, 'r1', 'revno:-4')
1948.4.6 by John Arbash Meinel
A small bugfix, and more tests for revno:
123
124
    def test_invalid_number(self):
125
        # Get the right exception text
126
        try:
127
            int('X')
128
        except ValueError, e:
129
            pass
1948.4.15 by John Arbash Meinel
Change the InvalidRevisionSpec formatting to be more readable
130
        self.assertInvalid('revno:X', extra='\n' + str(e))
1948.4.6 by John Arbash Meinel
A small bugfix, and more tests for revno:
131
132
    def test_missing_number_and_branch(self):
133
        self.assertInvalid('revno::',
1948.4.15 by John Arbash Meinel
Change the InvalidRevisionSpec formatting to be more readable
134
                           extra='\ncannot have an empty revno and no branch')
1948.4.7 by John Arbash Meinel
More revno: tests, now testing the branch/url parameter
135
136
    def test_invalid_number_with_branch(self):
137
        try:
138
            int('X')
139
        except ValueError, e:
140
            pass
1948.4.15 by John Arbash Meinel
Change the InvalidRevisionSpec formatting to be more readable
141
        self.assertInvalid('revno:X:tree2', extra='\n' + str(e))
1948.4.7 by John Arbash Meinel
More revno: tests, now testing the branch/url parameter
142
1948.4.16 by John Arbash Meinel
Move the tests into the associated tester, remove redundant tests, some small PEP8 changes
143
    def test_non_exact_branch(self):
144
        # It seems better to require an exact path to the branch
145
        # Branch.open() rather than using Branch.open_containing()
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
146
        spec = RevisionSpec.from_string('revno:2:tree2/a')
1948.4.16 by John Arbash Meinel
Move the tests into the associated tester, remove redundant tests, some small PEP8 changes
147
        self.assertRaises(errors.NotBranchError,
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
148
                          spec.in_history, self.tree.branch)
1948.4.16 by John Arbash Meinel
Move the tests into the associated tester, remove redundant tests, some small PEP8 changes
149
1948.4.7 by John Arbash Meinel
More revno: tests, now testing the branch/url parameter
150
    def test_with_branch(self):
151
        # Passing a URL overrides the supplied branch path
152
        revinfo = self.get_in_history('revno:2:tree2')
153
        self.assertNotEqual(self.tree.branch.base, revinfo.branch.base)
154
        self.assertEqual(self.tree2.branch.base, revinfo.branch.base)
155
        self.assertEqual(2, revinfo.revno)
156
        self.assertEqual('alt_r2', revinfo.rev_id)
157
1948.4.32 by John Arbash Meinel
Clean up __repr__, as well as add tests that we can handle -r12:branch/
158
    def test_int_with_branch(self):
159
        revinfo = self.get_in_history('2:tree2')
160
        self.assertNotEqual(self.tree.branch.base, revinfo.branch.base)
161
        self.assertEqual(self.tree2.branch.base, revinfo.branch.base)
162
        self.assertEqual(2, revinfo.revno)
163
        self.assertEqual('alt_r2', revinfo.rev_id)
164
1948.4.7 by John Arbash Meinel
More revno: tests, now testing the branch/url parameter
165
    def test_with_url(self):
166
        url = self.get_url() + '/tree2'
167
        revinfo = self.get_in_history('revno:2:%s' % (url,))
168
        self.assertNotEqual(self.tree.branch.base, revinfo.branch.base)
169
        self.assertEqual(self.tree2.branch.base, revinfo.branch.base)
170
        self.assertEqual(2, revinfo.revno)
171
        self.assertEqual('alt_r2', revinfo.rev_id)
172
173
    def test_negative_with_url(self):
174
        url = self.get_url() + '/tree2'
175
        revinfo = self.get_in_history('revno:-1:%s' % (url,))
176
        self.assertNotEqual(self.tree.branch.base, revinfo.branch.base)
177
        self.assertEqual(self.tree2.branch.base, revinfo.branch.base)
178
        self.assertEqual(2, revinfo.revno)
179
        self.assertEqual('alt_r2', revinfo.rev_id)
180
1948.4.22 by John Arbash Meinel
Refactor common code from integer revno handlers
181
    def test_different_history_lengths(self):
182
        # Make sure we use the revisions and offsets in the supplied branch
183
        # not the ones in the original branch.
184
        self.tree2.commit('three', rev_id='r3')
185
        self.assertInHistoryIs(3, 'r3', 'revno:3:tree2')
186
        self.assertInHistoryIs(3, 'r3', 'revno:-1:tree2')
187
1948.4.7 by John Arbash Meinel
More revno: tests, now testing the branch/url parameter
188
    def test_invalid_branch(self):
189
        self.assertRaises(errors.NotBranchError,
190
                          self.get_in_history, 'revno:-1:tree3')
191
192
    def test_invalid_revno_in_branch(self):
193
        self.tree.commit('three', rev_id='r3')
194
        self.assertInvalid('revno:3:tree2')
1948.4.8 by John Arbash Meinel
Testing the revid: spec
195
1948.4.16 by John Arbash Meinel
Move the tests into the associated tester, remove redundant tests, some small PEP8 changes
196
    def test_revno_n_path(self):
197
        """Old revno:N:path tests"""
198
        wta = self.make_branch_and_tree('a')
199
        ba = wta.branch
200
        
201
        wta.commit('Commit one', rev_id='a@r-0-1')
202
        wta.commit('Commit two', rev_id='a@r-0-2')
203
        wta.commit('Commit three', rev_id='a@r-0-3')
204
205
        wtb = self.make_branch_and_tree('b')
206
        bb = wtb.branch
207
208
        wtb.commit('Commit one', rev_id='b@r-0-1')
209
        wtb.commit('Commit two', rev_id='b@r-0-2')
210
        wtb.commit('Commit three', rev_id='b@r-0-3')
211
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
212
213
        self.assertEqual((1, 'a@r-0-1'),
214
                         spec_in_history('revno:1:a/', ba))
1948.4.16 by John Arbash Meinel
Move the tests into the associated tester, remove redundant tests, some small PEP8 changes
215
        # The argument of in_history should be ignored since it is
216
        # redundant with the path in the spec.
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
217
        self.assertEqual((1, 'a@r-0-1'),
218
                         spec_in_history('revno:1:a/', None))
219
        self.assertEqual((1, 'a@r-0-1'),
220
                         spec_in_history('revno:1:a/', bb))
221
        self.assertEqual((2, 'b@r-0-2'),
222
                         spec_in_history('revno:2:b/', None))
1948.4.16 by John Arbash Meinel
Move the tests into the associated tester, remove redundant tests, some small PEP8 changes
223
224
1948.4.8 by John Arbash Meinel
Testing the revid: spec
225
226
class TestRevisionSpec_revid(TestRevisionSpec):
227
    
228
    def test_in_history(self):
229
        # We should be able to access revisions that are directly
230
        # in the history.
231
        self.assertInHistoryIs(1, 'r1', 'revid:r1')
232
        self.assertInHistoryIs(2, 'r2', 'revid:r2')
233
        
234
    def test_missing(self):
235
        self.assertInvalid('revid:r3')
236
237
    def test_merged(self):
238
        """We can reach revisions in the ancestry"""
239
        self.assertInHistoryIs(None, 'alt_r2', 'revid:alt_r2')
240
241
    def test_not_here(self):
242
        self.tree2.commit('alt third', rev_id='alt_r3')
243
        # It exists in tree2, but not in tree
244
        self.assertInvalid('revid:alt_r3')
245
246
    def test_in_repository(self):
247
        """We can get any revision id in the repository"""
248
        # XXX: This may change in the future, but for now, it is true
249
        self.tree2.commit('alt third', rev_id='alt_r3')
250
        self.tree.branch.repository.fetch(self.tree2.branch.repository,
251
                                          revision_id='alt_r3')
252
        self.assertInHistoryIs(None, 'alt_r3', 'revid:alt_r3')
1948.4.9 by John Arbash Meinel
Cleanup and test last:
253
254
255
class TestRevisionSpec_last(TestRevisionSpec):
256
257
    def test_positive(self):
258
        self.assertInHistoryIs(2, 'r2', 'last:1')
259
        self.assertInHistoryIs(1, 'r1', 'last:2')
260
        self.assertInHistoryIs(0, None, 'last:3')
261
262
    def test_empty(self):
263
        self.assertInHistoryIs(2, 'r2', 'last:')
264
265
    def test_negative(self):
266
        self.assertInvalid('last:-1',
1948.4.15 by John Arbash Meinel
Change the InvalidRevisionSpec formatting to be more readable
267
                           extra='\nyou must supply a positive value')
1948.4.9 by John Arbash Meinel
Cleanup and test last:
268
269
    def test_missing(self):
270
        self.assertInvalid('last:4')
271
272
    def test_no_history(self):
273
        tree = self.make_branch_and_tree('tree3')
274
275
        self.assertRaises(errors.NoCommits,
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
276
                          spec_in_history, 'last:', tree.branch)
1948.4.9 by John Arbash Meinel
Cleanup and test last:
277
278
    def test_not_a_number(self):
279
        try:
280
            int('Y')
281
        except ValueError, e:
282
            pass
1948.4.15 by John Arbash Meinel
Change the InvalidRevisionSpec formatting to be more readable
283
        self.assertInvalid('last:Y', extra='\n' + str(e))
1948.4.10 by John Arbash Meinel
test the before: spec, currently asserting what seems to be buggy behavior
284
285
286
class TestRevisionSpec_before(TestRevisionSpec):
287
288
    def test_int(self):
289
        self.assertInHistoryIs(1, 'r1', 'before:2')
290
        self.assertInHistoryIs(1, 'r1', 'before:-1')
291
292
    def test_before_one(self):
293
        self.assertInHistoryIs(0, None, 'before:1')
294
295
    def test_before_none(self):
1948.4.13 by John Arbash Meinel
Going before:0 is an error, and if you are on another history, use the leftmost parent
296
        self.assertInvalid('before:0',
1948.4.15 by John Arbash Meinel
Change the InvalidRevisionSpec formatting to be more readable
297
                           extra='\ncannot go before the null: revision')
1948.4.10 by John Arbash Meinel
test the before: spec, currently asserting what seems to be buggy behavior
298
299
    def test_revid(self):
300
        self.assertInHistoryIs(1, 'r1', 'before:revid:r2')
301
302
    def test_last(self):
303
        self.assertInHistoryIs(1, 'r1', 'before:last:1')
304
305
    def test_alt_revid(self):
1948.4.13 by John Arbash Meinel
Going before:0 is an error, and if you are on another history, use the leftmost parent
306
        # This will grab the left-most ancestor for alternate histories
307
        self.assertInHistoryIs(1, 'r1', 'before:revid:alt_r2')
1948.4.11 by John Arbash Meinel
Update and test the tag: spec
308
1948.4.14 by John Arbash Meinel
Test the code path for a no-parent alternate history
309
    def test_alt_no_parents(self):
310
        new_tree = self.make_branch_and_tree('new_tree')
311
        new_tree.commit('first', rev_id='new_r1')
312
        self.tree.branch.repository.fetch(new_tree.branch.repository,
313
                                          revision_id='new_r1')
314
        self.assertInHistoryIs(0, None, 'before:revid:new_r1')
315
1948.4.11 by John Arbash Meinel
Update and test the tag: spec
316
317
class TestRevisionSpec_tag(TestRevisionSpec):
318
    
319
    def test_invalid(self):
1948.4.15 by John Arbash Meinel
Change the InvalidRevisionSpec formatting to be more readable
320
        self.assertInvalid('tag:foo', extra='\ntag: namespace registered,'
1948.4.11 by John Arbash Meinel
Update and test the tag: spec
321
                                            ' but not implemented')
1948.4.12 by John Arbash Meinel
Some tests for the date: spec
322
323
324
class TestRevisionSpec_date(TestRevisionSpec):
325
326
    def setUp(self):
327
        super(TestRevisionSpec, self).setUp()
328
329
        new_tree = self.make_branch_and_tree('new_tree')
330
        new_tree.commit('Commit one', rev_id='new_r1',
331
                        timestamp=time.time() - 60*60*24)
332
        new_tree.commit('Commit two', rev_id='new_r2')
333
        new_tree.commit('Commit three', rev_id='new_r3')
334
335
        self.tree = new_tree
336
337
    def test_tomorrow(self):
338
        self.assertInvalid('date:tomorrow')
339
340
    def test_today(self):
341
        self.assertInHistoryIs(2, 'new_r2', 'date:today')
342
        self.assertInHistoryIs(1, 'new_r1', 'before:date:today')
343
344
    def test_yesterday(self):
345
        self.assertInHistoryIs(1, 'new_r1', 'date:yesterday')
346
347
    def test_invalid(self):
1948.4.15 by John Arbash Meinel
Change the InvalidRevisionSpec formatting to be more readable
348
        self.assertInvalid('date:foobar', extra='\ninvalid date')
1948.4.12 by John Arbash Meinel
Some tests for the date: spec
349
        # You must have '-' between year/month/day
1948.4.15 by John Arbash Meinel
Change the InvalidRevisionSpec formatting to be more readable
350
        self.assertInvalid('date:20040404', extra='\ninvalid date')
1948.4.12 by John Arbash Meinel
Some tests for the date: spec
351
        # Need 2 digits for each date piece
1948.4.15 by John Arbash Meinel
Change the InvalidRevisionSpec formatting to be more readable
352
        self.assertInvalid('date:2004-4-4', extra='\ninvalid date')
1948.4.12 by John Arbash Meinel
Some tests for the date: spec
353
354
    def test_day(self):
355
        now = datetime.datetime.now()
356
        self.assertInHistoryIs(2, 'new_r2',
357
            'date:%04d-%02d-%02d' % (now.year, now.month, now.day))
1948.4.17 by John Arbash Meinel
Update tests for ancestor: spec
358
359
360
class TestRevisionSpec_ancestor(TestRevisionSpec):
361
    
362
    def test_non_exact_branch(self):
363
        # It seems better to require an exact path to the branch
364
        # Branch.open() rather than using Branch.open_containing()
365
        self.assertRaises(errors.NotBranchError,
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
366
                          self.get_in_history, 'ancestor:tree2/a')
1948.4.17 by John Arbash Meinel
Update tests for ancestor: spec
367
368
    def test_simple(self):
369
        # Common ancestor of trees is 'alt_r2'
370
        self.assertInHistoryIs(None, 'alt_r2', 'ancestor:tree2')
371
372
        # Going the other way, we get a valid revno
373
        tmp = self.tree
374
        self.tree = self.tree2
375
        self.tree2 = tmp
376
        self.assertInHistoryIs(2, 'alt_r2', 'ancestor:tree')
377
378
    def test_self(self):
379
        self.assertInHistoryIs(2, 'r2', 'ancestor:tree')
380
381
    def test_unrelated(self):
382
        new_tree = self.make_branch_and_tree('new_tree')
383
384
        new_tree.commit('Commit one', rev_id='new_r1')
385
        new_tree.commit('Commit two', rev_id='new_r2')
386
        new_tree.commit('Commit three', rev_id='new_r3')
387
388
        # With no common ancestor, we should raise another user error
389
        self.assertRaises(errors.NoCommonAncestor,
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
390
                          self.get_in_history, 'ancestor:new_tree')
1948.4.17 by John Arbash Meinel
Update tests for ancestor: spec
391
392
    def test_no_commits(self):
393
        new_tree = self.make_branch_and_tree('new_tree')
394
        self.assertRaises(errors.NoCommits,
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
395
                          spec_in_history, 'ancestor:new_tree',
396
                                           self.tree.branch)
1948.4.17 by John Arbash Meinel
Update tests for ancestor: spec
397
                        
398
        self.assertRaises(errors.NoCommits,
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
399
                          spec_in_history, 'ancestor:tree',
400
                                           new_tree.branch)
1948.4.18 by John Arbash Meinel
Update branch: spec and tests
401
402
403
class TestRevisionSpec_branch(TestRevisionSpec):
404
    
405
    def test_non_exact_branch(self):
406
        # It seems better to require an exact path to the branch
407
        # Branch.open() rather than using Branch.open_containing()
408
        self.assertRaises(errors.NotBranchError,
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
409
                          self.get_in_history, 'branch:tree2/a')
1948.4.18 by John Arbash Meinel
Update branch: spec and tests
410
411
    def test_simple(self):
412
        self.assertInHistoryIs(None, 'alt_r2', 'branch:tree2')
413
414
    def test_self(self):
415
        self.assertInHistoryIs(2, 'r2', 'branch:tree')
416
417
    def test_unrelated(self):
418
        new_tree = self.make_branch_and_tree('new_tree')
419
420
        new_tree.commit('Commit one', rev_id='new_r1')
421
        new_tree.commit('Commit two', rev_id='new_r2')
422
        new_tree.commit('Commit three', rev_id='new_r3')
423
424
        self.assertInHistoryIs(None, 'new_r3', 'branch:new_tree')
425
426
        # XXX: Right now, we use fetch() to make sure the remote revisions
427
        # have been pulled into the local branch. We may change that
428
        # behavior in the future.
429
        self.failUnless(self.tree.branch.repository.has_revision('new_r3'))
430
431
    def test_no_commits(self):
432
        new_tree = self.make_branch_and_tree('new_tree')
433
        self.assertRaises(errors.NoCommits,
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
434
                          self.get_in_history, 'branch:new_tree')