1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# Copyright (C) 2007 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Tests for interface conformance of 'WorkingTree.add'"""
import os
from bzrlib import (
errors,
osutils,
)
from bzrlib.workingtree_4 import WorkingTreeFormat4
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
class TestAdd(TestCaseWithWorkingTree):
def get_tree_layout(self, tree):
"""Get the (path, file_id) pairs for the current tree."""
tree.lock_read()
try:
return [(path, ie.file_id) for path, ie
in tree.iter_entries_by_dir()]
finally:
tree.unlock()
def assertTreeLayout(self, expected, tree):
"""Check that the tree has the correct layout."""
actual = self.get_tree_layout(tree)
self.assertEqual(expected, actual)
def test_add_one(self):
tree = self.make_branch_and_tree('.')
self.build_tree(['one'])
tree.add('one', 'one-id')
root_id = tree.get_root_id()
self.assertTreeLayout([('', root_id), ('one', 'one-id')], tree)
def test_add_one_list(self):
tree = self.make_branch_and_tree('.')
self.build_tree(['one'])
tree.add(['one'], ['one-id'])
root_id = tree.get_root_id()
self.assertTreeLayout([('', root_id), ('one', 'one-id')], tree)
def test_add_one_new_id(self):
tree = self.make_branch_and_tree('.')
self.build_tree(['one'])
tree.add(['one'])
root_id = tree.get_root_id()
one_id = tree.path2id('one')
self.assertTreeLayout([('', root_id), ('one', one_id)], tree)
def test_add_unicode(self):
tree = self.make_branch_and_tree('.')
try:
self.build_tree([u'f\xf6'])
except UnicodeError:
raise tests.TestSkipped('Filesystem does not support filename.')
tree.add([u'f\xf6'])
root_id = tree.get_root_id()
foo_id = tree.path2id(u'f\xf6')
self.assertTreeLayout([('', root_id), (u'f\xf6', foo_id)], tree)
def test_add_subdir(self):
tree = self.make_branch_and_tree('.')
self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
tree.add(['dir'], ['dir-id'])
tree.add(['dir/subdir'], ['subdir-id'])
tree.add(['dir/subdir/foo'], ['foo-id'])
root_id = tree.get_root_id()
self.assertTreeLayout([('', root_id), ('dir', 'dir-id'),
('dir/subdir', 'subdir-id'),
('dir/subdir/foo', 'foo-id')], tree)
def test_add_multiple(self):
tree = self.make_branch_and_tree('.')
self.build_tree(['a', 'b', 'dir/', 'dir/subdir/', 'dir/subdir/foo'])
tree.add(['a', 'b', 'dir', 'dir/subdir', 'dir/subdir/foo'],
['a-id', 'b-id', 'dir-id', 'subdir-id', 'foo-id'])
root_id = tree.get_root_id()
self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
('dir', 'dir-id'), ('dir/subdir', 'subdir-id'),
('dir/subdir/foo', 'foo-id')], tree)
def test_add_invalid(self):
tree = self.make_branch_and_tree('.')
self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
root_id = tree.get_root_id()
self.assertRaises(errors.NotVersionedError,
tree.add, ['dir/subdir'])
self.assertTreeLayout([('', root_id)], tree)
def test_add_after_remove(self):
tree = self.make_branch_and_tree('.')
self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
root_id = tree.get_root_id()
tree.add(['dir'], ['dir-id'])
tree.commit('dir', rev_id='rev-1')
tree.unversion(['dir-id'])
self.assertRaises(errors.NotVersionedError,
tree.add, ['dir/subdir'])
|