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
124
125
126
|
# Copyright (C) 2020 Jelmer Vernooij
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""Tests for breezy.branch.InterBranch.copy_content_into."""
from breezy import branch
from breezy.errors import NoSuchFile
from breezy.tests import TestNotApplicable
from breezy.tests.per_intertree import (
TestCaseWithTwoTrees,
)
class TestFindPaths(TestCaseWithTwoTrees):
def test_path_missing(self):
tree1 = self.make_branch_and_tree('1')
tree2 = self.make_to_branch_and_tree('2')
self.build_tree_contents([
('1/file', b'apples'),
('2/file', b'apples'),
])
tree1.add('file')
tree2.add('file')
tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
inter = self.intertree_class(tree1, tree2)
self.assertRaises(NoSuchFile, inter.find_source_path, 'missing')
self.assertRaises(NoSuchFile, inter.find_target_path, 'missing')
self.assertRaises(NoSuchFile, inter.find_source_paths, ['missing'])
self.assertRaises(NoSuchFile, inter.find_target_paths, ['missing'])
def test_old_path(self):
tree1 = self.make_branch_and_tree('1')
tree2 = self.make_to_branch_and_tree('2')
self.build_tree_contents([
('2/file', b'apples'),
])
tree2.add('file')
tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
inter = self.intertree_class(tree1, tree2)
self.assertIs(None, inter.find_source_path('file'))
self.assertEqual({'file': None}, inter.find_source_paths(['file']))
def test_new_path(self):
tree1 = self.make_branch_and_tree('1')
tree2 = self.make_to_branch_and_tree('2')
self.build_tree_contents([
('1/file', b'apples'),
])
tree1.add('file')
tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
inter = self.intertree_class(tree1, tree2)
self.assertIs(None, inter.find_target_path('file'))
self.assertEqual({'file': None}, inter.find_target_paths(['file']))
def test_unchanged(self):
tree1 = self.make_branch_and_tree('1')
self.build_tree_contents([
('1/file', b'apples'),
])
tree1.add('file')
tree1.commit('foo')
tree2 = self.make_to_branch_and_tree('2')
tree2.pull(tree1.branch)
tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
inter = self.intertree_class(tree1, tree2)
self.assertEqual('file', inter.find_target_path('file'))
self.assertEqual({'file': 'file'}, inter.find_target_paths(['file']))
self.assertEqual('file', inter.find_source_path('file'))
self.assertEqual({'file': 'file'}, inter.find_source_paths(['file']))
def test_rename(self):
tree1 = self.make_branch_and_tree('1')
self.build_tree_contents([
('1/file', b'apples'),
])
tree1.add('file')
tree1.commit('foo')
tree2 = self.make_to_branch_and_tree('2')
tree2.pull(tree1.branch)
tree2.rename_one('file', 'newfile')
tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
inter = self.intertree_class(tree1, tree2)
self.assertEqual('newfile', inter.find_target_path('file'))
self.assertEqual({'file': 'newfile'}, inter.find_target_paths(['file']))
self.assertEqual('file', inter.find_source_path('newfile'))
self.assertEqual({'newfile': 'file'}, inter.find_source_paths(['newfile']))
def test_copy(self):
tree1 = self.make_branch_and_tree('1')
self.build_tree_contents([
('1/file', b'apples'),
])
tree1.add('file')
tree1.commit('foo')
tree2 = self.make_to_branch_and_tree('2')
tree2.pull(tree1.branch)
tree2.copy_one('file', 'newfile')
tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
inter = self.intertree_class(tree1, tree2)
self.assertIn(inter.find_target_path('file'), ['file', 'newfile'])
self.assertIn(inter.find_source_path('newfile'), ['file', None])
self.assertEqual('file', inter.find_source_path('file'))
self.assertIn(inter.find_source_paths(['newfile']), [{'newfile': 'file'}, {'newfile': None}])
self.assertIn(
inter.find_source_paths(['newfile', 'file']), [
{'newfile': 'file', 'file': 'file'},
{'newfile': None, 'file': 'file'},
])
|