bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
2100.3.8
by Aaron Bentley
Add add_reference |
1 |
# Copyright (C) 2006 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
import os |
|
18 |
||
19 |
from bzrlib import errors, tests, workingtree |
|
20 |
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree |
|
21 |
||
22 |
class TestBasisInventory(TestCaseWithWorkingTree): |
|
23 |
||
24 |
def make_trees(self): |
|
25 |
tree = self.make_branch_and_tree('tree') |
|
26 |
tree.set_root_id('root-id') |
|
27 |
self.build_tree(['tree/file1']) |
|
28 |
tree.add('file1', 'file1-id') |
|
29 |
sub_tree = self.make_branch_and_tree('tree/sub-tree') |
|
30 |
sub_tree.set_root_id('sub-tree-root-id') |
|
|
2100.3.19
by Aaron Bentley
Ensure commit preserves reference revision |
31 |
sub_tree.commit('commit', rev_id='sub_1') |
|
2100.3.8
by Aaron Bentley
Add add_reference |
32 |
return tree, sub_tree |
33 |
||
|
2100.3.27
by Aaron Bentley
Enable nested commits |
34 |
def make_nested_trees(self): |
35 |
tree, sub_tree = self.make_trees() |
|
36 |
try: |
|
37 |
tree.add_reference(sub_tree) |
|
38 |
except errors.UnsupportedOperation: |
|
39 |
assert tree.__class__ in (workingtree.WorkingTree2, |
|
40 |
workingtree.WorkingTree3) |
|
41 |
raise tests.TestSkipped('Tree format does not support references') |
|
42 |
return tree, sub_tree |
|
43 |
||
|
2100.3.8
by Aaron Bentley
Add add_reference |
44 |
def test_add_reference(self): |
|
2100.3.27
by Aaron Bentley
Enable nested commits |
45 |
self.make_nested_trees() |
|
2100.3.10
by Aaron Bentley
Ensure added references are serialized properly, beef up Workingtreee3 |
46 |
tree = workingtree.WorkingTree.open('tree') |
|
2100.3.8
by Aaron Bentley
Add add_reference |
47 |
self.assertEqual(tree.path2id('sub-tree'), 'sub-tree-root-id') |
48 |
self.assertEqual(tree.inventory['sub-tree-root-id'].kind, |
|
49 |
'tree-reference') |
|
|
2100.3.19
by Aaron Bentley
Ensure commit preserves reference revision |
50 |
tree.commit('commit reference') |
51 |
entry = tree.basis_tree().inventory['sub-tree-root-id'] |
|
|
2100.3.31
by Aaron Bentley
Merged bzr.dev (17 tests failing) |
52 |
sub_tree = tree.get_nested_tree(entry) |
|
2100.3.19
by Aaron Bentley
Ensure commit preserves reference revision |
53 |
self.assertEqual(sub_tree.last_revision(), entry.reference_revision) |
54 |
||
|
2100.3.8
by Aaron Bentley
Add add_reference |
55 |
|
56 |
def test_add_reference_same_root(self): |
|
57 |
tree = self.make_branch_and_tree('tree') |
|
58 |
self.build_tree(['tree/file1']) |
|
59 |
tree.add('file1', 'file1-id') |
|
60 |
tree.set_root_id('root-id') |
|
61 |
sub_tree = self.make_branch_and_tree('tree/sub-tree') |
|
62 |
sub_tree.set_root_id('root-id') |
|
63 |
try: |
|
64 |
self.assertRaises(errors.BadReferenceTarget, tree.add_reference, |
|
65 |
sub_tree) |
|
66 |
except errors.UnsupportedOperation: |
|
67 |
assert tree.__class__ in (workingtree.WorkingTree2, |
|
68 |
workingtree.WorkingTree3) |
|
69 |
raise tests.TestSkipped('Tree format does not support references') |
|
70 |
||
71 |
def test_root_present(self): |
|
72 |
"""Subtree root is present, though not the working tree root""" |
|
73 |
tree, sub_tree = self.make_trees() |
|
74 |
sub_tree.set_root_id('file1-id') |
|
75 |
try: |
|
76 |
self.assertRaises(errors.BadReferenceTarget, tree.add_reference, |
|
77 |
sub_tree) |
|
78 |
except errors.UnsupportedOperation: |
|
79 |
assert tree.__class__ in (workingtree.WorkingTree2, |
|
80 |
workingtree.WorkingTree3) |
|
81 |
raise tests.TestSkipped('Tree format does not support references') |
|
82 |
||
83 |
def test_add_non_subtree(self): |
|
84 |
tree, sub_tree = self.make_trees() |
|
85 |
os.rename('tree/sub-tree', 'sibling') |
|
86 |
sibling = workingtree.WorkingTree.open('sibling') |
|
87 |
try: |
|
88 |
self.assertRaises(errors.BadReferenceTarget, tree.add_reference, |
|
89 |
sibling) |
|
90 |
except errors.UnsupportedOperation: |
|
91 |
assert tree.__class__ in (workingtree.WorkingTree2, |
|
92 |
workingtree.WorkingTree3) |
|
93 |
raise tests.TestSkipped('Tree format does not support references') |
|
94 |
||
|
2100.3.27
by Aaron Bentley
Enable nested commits |
95 |
def test_get_nested_tree(self): |
96 |
tree, sub_tree = self.make_nested_trees() |
|
97 |
sub_tree2 = tree.get_nested_tree(tree.inventory['sub-tree-root-id']) |
|
98 |
self.assertEqual(sub_tree.basedir, sub_tree2.basedir) |
|
99 |
sub_tree2 = tree.get_nested_tree(tree.inventory['sub-tree-root-id'], |
|
100 |
'sub-tree') |
|
101 |
||
102 |
def test_iter_nested_trees(self): |
|
103 |
tree, sub_tree = self.make_nested_trees() |
|
104 |
iterator = tree.iter_nested_trees() |
|
105 |
sub_tree2 = iterator.next() |
|
106 |
self.assertEqual(sub_tree.basedir, sub_tree2.basedir) |
|
107 |
self.assertRaises(StopIteration, iterator.next) |