bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.115.12
by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface. |
1 |
# Copyright (C) 2008, 2009 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
16 |
||
17 |
"""Direct tests of the revision_store classes."""
|
|
18 |
||
19 |
from bzrlib import ( |
|
20 |
branch, |
|
21 |
errors, |
|
22 |
inventory, |
|
23 |
osutils, |
|
24 |
tests, |
|
25 |
)
|
|
26 |
||
27 |
from bzrlib.plugins.fastimport import ( |
|
28 |
revision_store, |
|
29 |
)
|
|
|
0.123.13
by Jelmer Vernooij
Check for availability of fastimport before running tests. |
30 |
from bzrlib.plugins.fastimport.tests import ( |
31 |
FastimportFeature, |
|
32 |
)
|
|
|
0.115.12
by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface. |
33 |
|
34 |
||
35 |
class Test_TreeShim(tests.TestCase): |
|
36 |
||
|
0.123.13
by Jelmer Vernooij
Check for availability of fastimport before running tests. |
37 |
_test_needs_features = [FastimportFeature] |
38 |
||
|
0.115.12
by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface. |
39 |
def invAddEntry(self, inv, path, file_id=None): |
40 |
if path.endswith('/'): |
|
41 |
path = path[:-1] |
|
42 |
kind = 'directory' |
|
43 |
else: |
|
44 |
kind = 'file' |
|
45 |
parent_path, basename = osutils.split(path) |
|
46 |
parent_id = inv.path2id(parent_path) |
|
47 |
inv.add(inventory.make_entry(kind, basename, parent_id, file_id)) |
|
48 |
||
49 |
def make_trivial_basis_inv(self): |
|
50 |
basis_inv = inventory.Inventory('TREE_ROOT') |
|
51 |
self.invAddEntry(basis_inv, 'foo', 'foo-id') |
|
52 |
self.invAddEntry(basis_inv, 'bar/', 'bar-id') |
|
53 |
self.invAddEntry(basis_inv, 'bar/baz', 'baz-id') |
|
54 |
return basis_inv |
|
|
0.123.13
by Jelmer Vernooij
Check for availability of fastimport before running tests. |
55 |
|
|
0.115.12
by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface. |
56 |
def test_id2path_no_delta(self): |
57 |
basis_inv = self.make_trivial_basis_inv() |
|
58 |
shim = revision_store._TreeShim(repo=None, basis_inv=basis_inv, |
|
59 |
inv_delta=[], content_provider=None) |
|
60 |
self.assertEqual('', shim.id2path('TREE_ROOT')) |
|
61 |
self.assertEqual('foo', shim.id2path('foo-id')) |
|
62 |
self.assertEqual('bar', shim.id2path('bar-id')) |
|
63 |
self.assertEqual('bar/baz', shim.id2path('baz-id')) |
|
64 |
self.assertRaises(errors.NoSuchId, shim.id2path, 'qux-id') |
|
65 |
||
66 |
def test_id2path_with_delta(self): |
|
67 |
basis_inv = self.make_trivial_basis_inv() |
|
68 |
foo_entry = inventory.make_entry('file', 'foo2', 'TREE_ROOT', 'foo-id') |
|
69 |
inv_delta = [('foo', 'foo2', 'foo-id', foo_entry), |
|
70 |
('bar/baz', None, 'baz-id', None), |
|
71 |
]
|
|
72 |
||
73 |
shim = revision_store._TreeShim(repo=None, basis_inv=basis_inv, |
|
74 |
inv_delta=inv_delta, |
|
75 |
content_provider=None) |
|
76 |
self.assertEqual('', shim.id2path('TREE_ROOT')) |
|
77 |
self.assertEqual('foo2', shim.id2path('foo-id')) |
|
78 |
self.assertEqual('bar', shim.id2path('bar-id')) |
|
79 |
self.assertRaises(errors.NoSuchId, shim.id2path, 'baz-id') |
|
80 |
||
81 |
def test_path2id(self): |
|
82 |
basis_inv = self.make_trivial_basis_inv() |
|
83 |
shim = revision_store._TreeShim(repo=None, basis_inv=basis_inv, |
|
84 |
inv_delta=[], content_provider=None) |
|
85 |
self.assertEqual('TREE_ROOT', shim.path2id('')) |
|
86 |
# We don't want to ever give a wrong value, so for now we just raise
|
|
87 |
# NotImplementedError
|
|
88 |
self.assertRaises(NotImplementedError, shim.path2id, 'bar') |
|
89 |
||
90 |
def test_get_file_with_stat_content_in_stream(self): |
|
91 |
basis_inv = self.make_trivial_basis_inv() |
|
92 |
||
93 |
def content_provider(file_id): |
|
94 |
return 'content of\n' + file_id + '\n' |
|
|
0.123.13
by Jelmer Vernooij
Check for availability of fastimport before running tests. |
95 |
|
|
0.115.12
by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface. |
96 |
shim = revision_store._TreeShim(repo=None, basis_inv=basis_inv, |
97 |
inv_delta=[], |
|
98 |
content_provider=content_provider) |
|
99 |
f_obj, stat_val = shim.get_file_with_stat('baz-id') |
|
100 |
self.assertIs(None, stat_val) |
|
101 |
self.assertEqualDiff('content of\nbaz-id\n', f_obj.read()) |
|
102 |
||
103 |
# TODO: Test when the content isn't in the stream, and we fall back to the
|
|
104 |
# repository that was passed in
|
|
105 |
||
106 |
def test_get_symlink_target(self): |
|
107 |
basis_inv = self.make_trivial_basis_inv() |
|
108 |
ie = inventory.make_entry('symlink', 'link', 'TREE_ROOT', 'link-id') |
|
109 |
ie.symlink_target = u'link-target' |
|
110 |
basis_inv.add(ie) |
|
111 |
shim = revision_store._TreeShim(repo=None, basis_inv=basis_inv, |
|
112 |
inv_delta=[], content_provider=None) |
|
113 |
self.assertEqual(u'link-target', shim.get_symlink_target('link-id')) |
|
114 |
||
115 |
def test_get_symlink_target_from_delta(self): |
|
116 |
basis_inv = self.make_trivial_basis_inv() |
|
117 |
ie = inventory.make_entry('symlink', 'link', 'TREE_ROOT', 'link-id') |
|
118 |
ie.symlink_target = u'link-target' |
|
119 |
inv_delta = [(None, 'link', 'link-id', ie)] |
|
120 |
shim = revision_store._TreeShim(repo=None, basis_inv=basis_inv, |
|
121 |
inv_delta=inv_delta, |
|
122 |
content_provider=None) |
|
123 |
self.assertEqual(u'link-target', shim.get_symlink_target('link-id')) |
|
124 |
||
125 |
def test__delta_to_iter_changes(self): |
|
126 |
basis_inv = self.make_trivial_basis_inv() |
|
127 |
foo_entry = inventory.make_entry('file', 'foo2', 'bar-id', 'foo-id') |
|
128 |
link_entry = inventory.make_entry('symlink', 'link', 'TREE_ROOT', |
|
129 |
'link-id') |
|
130 |
link_entry.symlink_target = u'link-target' |
|
131 |
inv_delta = [('foo', 'bar/foo2', 'foo-id', foo_entry), |
|
132 |
('bar/baz', None, 'baz-id', None), |
|
133 |
(None, 'link', 'link-id', link_entry), |
|
134 |
]
|
|
135 |
shim = revision_store._TreeShim(repo=None, basis_inv=basis_inv, |
|
136 |
inv_delta=inv_delta, |
|
137 |
content_provider=None) |
|
138 |
changes = list(shim._delta_to_iter_changes()) |
|
139 |
expected = [('foo-id', ('foo', 'bar/foo2'), False, (True, True), |
|
140 |
('TREE_ROOT', 'bar-id'), ('foo', 'foo2'), |
|
141 |
('file', 'file'), (False, False)), |
|
142 |
('baz-id', ('bar/baz', None), True, (True, False), |
|
143 |
('bar-id', None), ('baz', None), |
|
144 |
('file', None), (False, None)), |
|
145 |
('link-id', (None, 'link'), True, (False, True), |
|
146 |
(None, 'TREE_ROOT'), (None, 'link'), |
|
147 |
(None, 'symlink'), (None, False)), |
|
148 |
]
|
|
149 |
# from pprint import pformat
|
|
150 |
# self.assertEqualDiff(pformat(expected), pformat(changes))
|
|
151 |
self.assertEqual(expected, changes) |
|
|
0.123.13
by Jelmer Vernooij
Check for availability of fastimport before running tests. |
152 |