5557.1.15
by John Arbash Meinel
Merge bzr.dev 5597 to resolve NEWS, aka bzr-2.3.txt |
1 |
# Copyright (C) 2006-2009, 2011 Canonical Ltd
|
2100.3.8
by Aaron Bentley
Add add_reference |
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
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2100.3.8
by Aaron Bentley
Add add_reference |
16 |
|
17 |
import os |
|
18 |
||
5582.10.4
by Jelmer Vernooij
Fix a bunch of tests. |
19 |
from bzrlib import errors, tests, workingtree |
4523.1.4
by Martin Pool
Rename remaining *_implementations tests |
20 |
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree |
2100.3.8
by Aaron Bentley
Add add_reference |
21 |
|
2255.6.3
by Aaron Bentley
tweak tests |
22 |
|
2100.3.8
by Aaron Bentley
Add add_reference |
23 |
class TestBasisInventory(TestCaseWithWorkingTree): |
24 |
||
25 |
def make_trees(self): |
|
26 |
tree = self.make_branch_and_tree('tree') |
|
27 |
tree.set_root_id('root-id') |
|
28 |
self.build_tree(['tree/file1']) |
|
29 |
tree.add('file1', 'file1-id') |
|
30 |
sub_tree = self.make_branch_and_tree('tree/sub-tree') |
|
31 |
sub_tree.set_root_id('sub-tree-root-id') |
|
2100.3.19
by Aaron Bentley
Ensure commit preserves reference revision |
32 |
sub_tree.commit('commit', rev_id='sub_1') |
2100.3.8
by Aaron Bentley
Add add_reference |
33 |
return tree, sub_tree |
34 |
||
3376.2.4
by Martin Pool
Remove every assert statement from bzrlib! |
35 |
def _references_unsupported(self, tree): |
5582.10.4
by Jelmer Vernooij
Fix a bunch of tests. |
36 |
if not tree.supports_tree_reference(): |
5786.1.2
by John Arbash Meinel
Change a test a bit. |
37 |
raise tests.TestNotApplicable( |
38 |
'Tree format does not support references') |
|
3376.2.4
by Martin Pool
Remove every assert statement from bzrlib! |
39 |
else: |
40 |
self.fail('%r does not support references but should' |
|
41 |
% (tree, )) |
|
42 |
||
2100.3.27
by Aaron Bentley
Enable nested commits |
43 |
def make_nested_trees(self): |
44 |
tree, sub_tree = self.make_trees() |
|
45 |
try: |
|
46 |
tree.add_reference(sub_tree) |
|
47 |
except errors.UnsupportedOperation: |
|
3376.2.4
by Martin Pool
Remove every assert statement from bzrlib! |
48 |
self._references_unsupported(tree) |
2100.3.27
by Aaron Bentley
Enable nested commits |
49 |
return tree, sub_tree |
50 |
||
2100.3.8
by Aaron Bentley
Add add_reference |
51 |
def test_add_reference(self): |
2100.3.27
by Aaron Bentley
Enable nested commits |
52 |
self.make_nested_trees() |
2100.3.10
by Aaron Bentley
Ensure added references are serialized properly, beef up Workingtreee3 |
53 |
tree = workingtree.WorkingTree.open('tree') |
2255.6.9
by Aaron Bentley
Fix test locking for dirstate |
54 |
tree.lock_write() |
55 |
try: |
|
56 |
self.assertEqual(tree.path2id('sub-tree'), 'sub-tree-root-id') |
|
5807.2.1
by Jelmer Vernooij
Remove unused imports. |
57 |
self.assertEqual(tree.kind('sub-tree-root-id'), 'tree-reference') |
2255.6.9
by Aaron Bentley
Fix test locking for dirstate |
58 |
tree.commit('commit reference') |
59 |
basis = tree.basis_tree() |
|
60 |
basis.lock_read() |
|
61 |
try: |
|
2255.2.228
by Robert Collins
Make all test_add_reference tests pass again. |
62 |
sub_tree = tree.get_nested_tree('sub-tree-root-id') |
2255.6.9
by Aaron Bentley
Fix test locking for dirstate |
63 |
self.assertEqual(sub_tree.last_revision(), |
2255.2.228
by Robert Collins
Make all test_add_reference tests pass again. |
64 |
tree.get_reference_revision('sub-tree-root-id')) |
2255.6.9
by Aaron Bentley
Fix test locking for dirstate |
65 |
finally: |
66 |
basis.unlock() |
|
67 |
finally: |
|
68 |
tree.unlock() |
|
2100.3.8
by Aaron Bentley
Add add_reference |
69 |
|
70 |
def test_add_reference_same_root(self): |
|
71 |
tree = self.make_branch_and_tree('tree') |
|
72 |
self.build_tree(['tree/file1']) |
|
73 |
tree.add('file1', 'file1-id') |
|
74 |
tree.set_root_id('root-id') |
|
75 |
sub_tree = self.make_branch_and_tree('tree/sub-tree') |
|
76 |
sub_tree.set_root_id('root-id') |
|
77 |
try: |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
78 |
self.assertRaises(errors.BadReferenceTarget, tree.add_reference, |
2100.3.8
by Aaron Bentley
Add add_reference |
79 |
sub_tree) |
80 |
except errors.UnsupportedOperation: |
|
3376.2.4
by Martin Pool
Remove every assert statement from bzrlib! |
81 |
self._references_unsupported(tree) |
2100.3.8
by Aaron Bentley
Add add_reference |
82 |
|
83 |
def test_root_present(self): |
|
84 |
"""Subtree root is present, though not the working tree root"""
|
|
85 |
tree, sub_tree = self.make_trees() |
|
86 |
sub_tree.set_root_id('file1-id') |
|
87 |
try: |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
88 |
self.assertRaises(errors.BadReferenceTarget, tree.add_reference, |
2100.3.8
by Aaron Bentley
Add add_reference |
89 |
sub_tree) |
90 |
except errors.UnsupportedOperation: |
|
3376.2.4
by Martin Pool
Remove every assert statement from bzrlib! |
91 |
self._references_unsupported(tree) |
2100.3.8
by Aaron Bentley
Add add_reference |
92 |
|
93 |
def test_add_non_subtree(self): |
|
94 |
tree, sub_tree = self.make_trees() |
|
95 |
os.rename('tree/sub-tree', 'sibling') |
|
96 |
sibling = workingtree.WorkingTree.open('sibling') |
|
97 |
try: |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
98 |
self.assertRaises(errors.BadReferenceTarget, tree.add_reference, |
2100.3.8
by Aaron Bentley
Add add_reference |
99 |
sibling) |
100 |
except errors.UnsupportedOperation: |
|
3376.2.4
by Martin Pool
Remove every assert statement from bzrlib! |
101 |
self._references_unsupported(tree) |
2100.3.8
by Aaron Bentley
Add add_reference |
102 |
|
2100.3.27
by Aaron Bentley
Enable nested commits |
103 |
def test_get_nested_tree(self): |
104 |
tree, sub_tree = self.make_nested_trees() |
|
2255.6.9
by Aaron Bentley
Fix test locking for dirstate |
105 |
tree.lock_read() |
106 |
try: |
|
2255.2.228
by Robert Collins
Make all test_add_reference tests pass again. |
107 |
sub_tree2 = tree.get_nested_tree('sub-tree-root-id') |
2255.6.9
by Aaron Bentley
Fix test locking for dirstate |
108 |
self.assertEqual(sub_tree.basedir, sub_tree2.basedir) |
2255.2.228
by Robert Collins
Make all test_add_reference tests pass again. |
109 |
sub_tree2 = tree.get_nested_tree('sub-tree-root-id', 'sub-tree') |
2255.6.9
by Aaron Bentley
Fix test locking for dirstate |
110 |
finally: |
111 |
tree.unlock() |