33
33
# The order of 'path' here is important - do not let it
34
34
# be a sorted list.
35
# u'\xe5' == a with circle
36
# '\xc3\xae' == u'\xee' == i with hat
37
# So these are u'pathg' and 'idg' only with a circle and a hat. (shappo?)
38
35
example_conflicts = ConflictList([
39
MissingParent('Not deleting', u'p\xe5thg', '\xc3\xaedg'),
40
ContentsConflict(u'p\xe5tha', None, '\xc3\xaeda'),
41
TextConflict(u'p\xe5tha'),
42
PathConflict(u'p\xe5thb', u'p\xe5thc', '\xc3\xaedb'),
43
DuplicateID('Unversioned existing file', u'p\xe5thc', u'p\xe5thc2',
44
'\xc3\xaedc', '\xc3\xaedc'),
45
DuplicateEntry('Moved existing file to', u'p\xe5thdd.moved', u'p\xe5thd',
47
ParentLoop('Cancelled move', u'p\xe5the', u'p\xe5th2e',
49
UnversionedParent('Versioned directory', u'p\xe5thf', '\xc3\xaedf'),
36
MissingParent('Not deleting', 'pathg', 'idg'),
37
ContentsConflict('patha', 'ida'),
38
TextConflict('patha'),
39
PathConflict('pathb', 'pathc', 'idb'),
40
DuplicateID('Unversioned existing file', 'pathc', 'pathc2', 'idc', 'idc'),
41
DuplicateEntry('Moved existing file to', 'pathdd.moved', 'pathd', 'idd',
43
ParentLoop('Cancelled move', 'pathe', 'path2e', None, 'id2e'),
44
UnversionedParent('Versioned directory', 'pathf', 'idf'),
63
58
file('hello.OTHER', 'w').write('hello world3')
64
59
file('hello.sploo.BASE', 'w').write('yellow world')
65
60
file('hello.sploo.OTHER', 'w').write('yellow world2')
67
61
self.assertEqual(len(list(tree.list_files())), 6)
69
62
conflicts = tree.conflicts()
70
63
self.assertEqual(len(conflicts), 2)
71
64
self.assert_('hello' in conflicts[0].path)
89
82
l = ConflictList([TextConflict('hello')])
90
83
l.remove_files(tree)
92
def test_select_conflicts(self):
93
tree = self.make_branch_and_tree('.')
94
tree_conflicts = ConflictList([ContentsConflict('foo'),
95
ContentsConflict('bar')])
96
self.assertEqual((ConflictList([ContentsConflict('bar')]),
97
ConflictList([ContentsConflict('foo')])),
98
tree_conflicts.select_conflicts(tree, ['foo']))
99
self.assertEqual((ConflictList(), tree_conflicts),
100
tree_conflicts.select_conflicts(tree, [''],
101
ignore_misses=True, recurse=True))
102
tree_conflicts = ConflictList([ContentsConflict('foo/baz'),
103
ContentsConflict('bar')])
104
self.assertEqual((ConflictList([ContentsConflict('bar')]),
105
ConflictList([ContentsConflict('foo/baz')])),
106
tree_conflicts.select_conflicts(tree, ['foo'],
109
tree_conflicts = ConflictList([PathConflict('qux', 'foo/baz')])
110
self.assertEqual((ConflictList(), tree_conflicts),
111
tree_conflicts.select_conflicts(tree, ['foo'],
114
self.assertEqual((tree_conflicts, ConflictList()),
115
tree_conflicts.select_conflicts(tree, ['foo'],
119
86
class TestConflictStanzas(TestCase):
122
89
# write and read our example stanza.
123
90
stanza_iter = example_conflicts.to_stanzas()
124
91
processed = ConflictList.from_stanzas(stanza_iter)
125
for o, p in zip(processed, example_conflicts):
92
for o,p in zip(processed, example_conflicts):
126
93
self.assertEqual(o, p)
128
self.assertIsInstance(o.path, unicode)
130
if o.file_id is not None:
131
self.assertIsInstance(o.file_id, str)
133
conflict_path = getattr(o, 'conflict_path', None)
134
if conflict_path is not None:
135
self.assertIsInstance(conflict_path, unicode)
137
conflict_file_id = getattr(o, 'conflict_file_id', None)
138
if conflict_file_id is not None:
139
self.assertIsInstance(conflict_file_id, str)
141
95
def test_stanzification(self):
142
96
for stanza in example_conflicts.to_stanzas():
143
if 'file_id' in stanza:
144
# In Stanza form, the file_id has to be unicode.
145
self.assertStartsWith(stanza['file_id'], u'\xeed')
146
self.assertStartsWith(stanza['path'], u'p\xe5th')
147
if 'conflict_path' in stanza:
148
self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
149
if 'conflict_file_id' in stanza:
150
self.assertStartsWith(stanza['conflict_file_id'], u'\xeed')
98
self.assertStartsWith(stanza['file_id'], 'id')
101
self.assertStartsWith(stanza['path'], 'path')
103
self.assertStartsWith(stanza['conflict_file_id'], 'id')
104
self.assertStartsWith(stanza['conflict_file_path'], 'path')