/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/bzr/tests/test_conflicts.py

  • Committer: Gustav Hartvigsson
  • Date: 2021-01-11 20:19:38 UTC
  • mfrom: (7526.3.2 work)
  • Revision ID: gustav.hartvigsson@gmail.com-20210111201938-omr9wjz3qdgyxe8k
MergedĀ lp:brz

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005-2011 Canonical Ltd
 
2
# Copyright (C) 2018-2020 Breezy Developers
 
3
#
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
#
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program; if not, write to the Free Software
 
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
17
 
 
18
import os
 
19
 
 
20
from ...conflicts import resolve
 
21
from ... import (
 
22
    tests,
 
23
    )
 
24
 
 
25
from ...tests import (
 
26
    scenarios,
 
27
    )
 
28
from ...tests.test_conflicts import vary_by_conflicts
 
29
 
 
30
 
 
31
from .. import conflicts as bzr_conflicts
 
32
 
 
33
 
 
34
load_tests = scenarios.load_tests_apply_scenarios
 
35
 
 
36
 
 
37
class TestPerConflict(tests.TestCase):
 
38
 
 
39
    scenarios = scenarios.multiply_scenarios(vary_by_conflicts())
 
40
 
 
41
    def test_stringification(self):
 
42
        text = str(self.conflict)
 
43
        self.assertContainsString(text, self.conflict.path)
 
44
        self.assertContainsString(text.lower(), "conflict")
 
45
        self.assertContainsString(repr(self.conflict),
 
46
                                  self.conflict.__class__.__name__)
 
47
 
 
48
    def test_stanza_roundtrip(self):
 
49
        p = self.conflict
 
50
        o = bzr_conflicts.Conflict.factory(**p.as_stanza().as_dict())
 
51
        self.assertEqual(o, p)
 
52
 
 
53
        self.assertIsInstance(o.path, str)
 
54
 
 
55
        if o.file_id is not None:
 
56
            self.assertIsInstance(o.file_id, bytes)
 
57
 
 
58
        conflict_path = getattr(o, 'conflict_path', None)
 
59
        if conflict_path is not None:
 
60
            self.assertIsInstance(conflict_path, str)
 
61
 
 
62
        conflict_file_id = getattr(o, 'conflict_file_id', None)
 
63
        if conflict_file_id is not None:
 
64
            self.assertIsInstance(conflict_file_id, bytes)
 
65
 
 
66
    def test_stanzification(self):
 
67
        stanza = self.conflict.as_stanza()
 
68
        if 'file_id' in stanza:
 
69
            # In Stanza form, the file_id has to be unicode.
 
70
            self.assertStartsWith(stanza['file_id'], u'\xeed')
 
71
        self.assertStartsWith(stanza['path'], u'p\xe5th')
 
72
        if 'conflict_path' in stanza:
 
73
            self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
 
74
        if 'conflict_file_id' in stanza:
 
75
            self.assertStartsWith(stanza['conflict_file_id'], u'\xeed')
 
76
 
 
77
 
 
78
class TestConflicts(tests.TestCaseWithTransport):
 
79
 
 
80
    def test_resolve_conflict_dir(self):
 
81
        tree = self.make_branch_and_tree('.')
 
82
        self.build_tree_contents([('hello', b'hello world4'),
 
83
                                  ('hello.THIS', b'hello world2'),
 
84
                                  ('hello.BASE', b'hello world1'),
 
85
                                  ])
 
86
        os.mkdir('hello.OTHER')
 
87
        tree.add('hello', b'q')
 
88
        l = bzr_conflicts.ConflictList([bzr_conflicts.TextConflict('hello')])
 
89
        l.remove_files(tree)
 
90
 
 
91
    def test_select_conflicts(self):
 
92
        tree = self.make_branch_and_tree('.')
 
93
        clist = bzr_conflicts.ConflictList
 
94
 
 
95
        def check_select(not_selected, selected, paths, **kwargs):
 
96
            self.assertEqual(
 
97
                (not_selected, selected),
 
98
                tree_conflicts.select_conflicts(tree, paths, **kwargs))
 
99
 
 
100
        foo = bzr_conflicts.ContentsConflict('foo')
 
101
        bar = bzr_conflicts.ContentsConflict('bar')
 
102
        tree_conflicts = clist([foo, bar])
 
103
 
 
104
        check_select(clist([bar]), clist([foo]), ['foo'])
 
105
        check_select(clist(), tree_conflicts,
 
106
                     [''], ignore_misses=True, recurse=True)
 
107
 
 
108
        foobaz = bzr_conflicts.ContentsConflict('foo/baz')
 
109
        tree_conflicts = clist([foobaz, bar])
 
110
 
 
111
        check_select(clist([bar]), clist([foobaz]),
 
112
                     ['foo'], ignore_misses=True, recurse=True)
 
113
 
 
114
        qux = bzr_conflicts.PathConflict('qux', 'foo/baz')
 
115
        tree_conflicts = clist([qux])
 
116
 
 
117
        check_select(clist(), tree_conflicts,
 
118
                     ['foo'], ignore_misses=True, recurse=True)
 
119
        check_select(tree_conflicts, clist(), ['foo'], ignore_misses=True)
 
120
 
 
121
    def test_resolve_conflicts_recursive(self):
 
122
        tree = self.make_branch_and_tree('.')
 
123
        self.build_tree(['dir/', 'dir/hello'])
 
124
        tree.add(['dir', 'dir/hello'])
 
125
 
 
126
        dirhello = [bzr_conflicts.TextConflict('dir/hello')]
 
127
        tree.set_conflicts(dirhello)
 
128
 
 
129
        resolve(tree, ['dir'], recursive=False, ignore_misses=True)
 
130
        self.assertEqual(dirhello, tree.conflicts())
 
131
 
 
132
        resolve(tree, ['dir'], recursive=True, ignore_misses=True)
 
133
        self.assertEqual(bzr_conflicts.ConflictList([]), tree.conflicts())