~bzr-pqm/bzr/bzr.dev

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