/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/per_intertree/test_find_path.py

  • Committer: Jelmer Vernooij
  • Date: 2020-02-13 23:57:28 UTC
  • mfrom: (7490 work)
  • mto: This revision was merged to the branch mainline in revision 7492.
  • Revision ID: jelmer@jelmer.uk-20200213235728-m6ds0mm3mbs4y182
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2020 Jelmer Vernooij
 
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
"""Tests for breezy.branch.InterBranch.copy_content_into."""
 
18
 
 
19
from breezy import branch
 
20
from breezy.errors import NoSuchFile
 
21
from breezy.tests import TestNotApplicable
 
22
from breezy.tests.per_intertree import (
 
23
    TestCaseWithTwoTrees,
 
24
    )
 
25
 
 
26
 
 
27
class TestFindPaths(TestCaseWithTwoTrees):
 
28
 
 
29
    def test_path_missing(self):
 
30
        tree1 = self.make_branch_and_tree('1')
 
31
        tree2 = self.make_to_branch_and_tree('2')
 
32
        self.build_tree_contents([
 
33
            ('1/file', b'apples'),
 
34
            ('2/file', b'apples'),
 
35
            ])
 
36
        tree1.add('file')
 
37
        tree2.add('file')
 
38
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
 
39
        inter = self.intertree_class(tree1, tree2)
 
40
        self.assertRaises(NoSuchFile, inter.find_source_path, 'missing')
 
41
        self.assertRaises(NoSuchFile, inter.find_target_path, 'missing')
 
42
        self.assertRaises(NoSuchFile, inter.find_source_paths, ['missing'])
 
43
        self.assertRaises(NoSuchFile, inter.find_target_paths, ['missing'])
 
44
 
 
45
    def test_old_path(self):
 
46
        tree1 = self.make_branch_and_tree('1')
 
47
        tree2 = self.make_to_branch_and_tree('2')
 
48
        self.build_tree_contents([
 
49
            ('2/file', b'apples'),
 
50
            ])
 
51
        tree2.add('file')
 
52
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
 
53
        inter = self.intertree_class(tree1, tree2)
 
54
        self.assertIs(None, inter.find_source_path('file'))
 
55
        self.assertEqual({'file': None}, inter.find_source_paths(['file']))
 
56
 
 
57
    def test_new_path(self):
 
58
        tree1 = self.make_branch_and_tree('1')
 
59
        tree2 = self.make_to_branch_and_tree('2')
 
60
        self.build_tree_contents([
 
61
            ('1/file', b'apples'),
 
62
            ])
 
63
        tree1.add('file')
 
64
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
 
65
        inter = self.intertree_class(tree1, tree2)
 
66
        self.assertIs(None, inter.find_target_path('file'))
 
67
        self.assertEqual({'file': None}, inter.find_target_paths(['file']))
 
68
 
 
69
    def test_unchanged(self):
 
70
        tree1 = self.make_branch_and_tree('1')
 
71
        self.build_tree_contents([
 
72
            ('1/file', b'apples'),
 
73
            ])
 
74
        tree1.add('file')
 
75
        tree1.commit('foo')
 
76
 
 
77
        tree2 = self.make_to_branch_and_tree('2')
 
78
        tree2.pull(tree1.branch)
 
79
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
 
80
        inter = self.intertree_class(tree1, tree2)
 
81
        self.assertEqual('file', inter.find_target_path('file'))
 
82
        self.assertEqual({'file': 'file'}, inter.find_target_paths(['file']))
 
83
        self.assertEqual('file', inter.find_source_path('file'))
 
84
        self.assertEqual({'file': 'file'}, inter.find_source_paths(['file']))
 
85
 
 
86
    def test_rename(self):
 
87
        tree1 = self.make_branch_and_tree('1')
 
88
        self.build_tree_contents([
 
89
            ('1/file', b'apples'),
 
90
            ])
 
91
        tree1.add('file')
 
92
        tree1.commit('foo')
 
93
 
 
94
        tree2 = self.make_to_branch_and_tree('2')
 
95
        tree2.pull(tree1.branch)
 
96
        tree2.rename_one('file', 'newfile')
 
97
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
 
98
        inter = self.intertree_class(tree1, tree2)
 
99
        self.assertEqual('newfile', inter.find_target_path('file'))
 
100
        self.assertEqual({'file': 'newfile'}, inter.find_target_paths(['file']))
 
101
        self.assertEqual('file', inter.find_source_path('newfile'))
 
102
        self.assertEqual({'newfile': 'file'}, inter.find_source_paths(['newfile']))
 
103
 
 
104
    def test_copy(self):
 
105
        tree1 = self.make_branch_and_tree('1')
 
106
        self.build_tree_contents([
 
107
            ('1/file', b'apples'),
 
108
            ])
 
109
        tree1.add('file')
 
110
        tree1.commit('foo')
 
111
 
 
112
        tree2 = self.make_to_branch_and_tree('2')
 
113
        tree2.pull(tree1.branch)
 
114
        tree2.copy_one('file', 'newfile')
 
115
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
 
116
        inter = self.intertree_class(tree1, tree2)
 
117
        self.assertIn(inter.find_target_path('file'), ['file', 'newfile'])
 
118
        self.assertIn(inter.find_source_path('newfile'), ['file', None])
 
119
        self.assertEqual('file', inter.find_source_path('file'))
 
120
        self.assertIn(inter.find_source_paths(['newfile']), [{'newfile': 'file'}, {'newfile': None}])
 
121
 
 
122
        self.assertIn(
 
123
            inter.find_source_paths(['newfile', 'file']), [
 
124
                {'newfile': 'file', 'file': 'file'},
 
125
                {'newfile': None, 'file': 'file'},
 
126
                ])