65
def vary_by_conflicts():
66
for conflict in example_conflicts:
67
yield (conflict.__class__.__name__, {"conflict": conflict})
65
70
class TestConflicts(tests.TestCaseWithTransport):
67
def test_conflicts(self):
68
"""Conflicts are detected properly"""
69
# Use BzrDirFormat6 so we can fake conflicts
70
tree = self.make_branch_and_tree('.', format=bzrdir.BzrDirFormat6())
71
self.build_tree_contents([('hello', 'hello world4'),
72
('hello.THIS', 'hello world2'),
73
('hello.BASE', 'hello world1'),
74
('hello.OTHER', 'hello world3'),
75
('hello.sploo.BASE', 'yellowworld'),
76
('hello.sploo.OTHER', 'yellowworld2'),
79
self.assertLength(6, list(tree.list_files()))
81
tree_conflicts = tree.conflicts()
82
self.assertLength(2, tree_conflicts)
83
self.assertTrue('hello' in tree_conflicts[0].path)
84
self.assertTrue('hello.sploo' in tree_conflicts[1].path)
85
conflicts.restore('hello')
86
conflicts.restore('hello.sploo')
87
self.assertLength(0, tree.conflicts())
88
self.assertFileEqual('hello world2', 'hello')
89
self.assertFalse(os.path.lexists('hello.sploo'))
90
self.assertRaises(errors.NotConflicted, conflicts.restore, 'hello')
91
self.assertRaises(errors.NotConflicted,
92
conflicts.restore, 'hello.sploo')
94
72
def test_resolve_conflict_dir(self):
95
73
tree = self.make_branch_and_tree('.')
96
74
self.build_tree_contents([('hello', 'hello world4'),
147
125
self.assertEqual(conflicts.ConflictList([]), tree.conflicts())
150
class TestConflictStanzas(tests.TestCase):
128
class TestPerConflict(tests.TestCase):
130
scenarios = scenarios.multiply_scenarios(vary_by_conflicts())
132
def test_stringification(self):
133
text = unicode(self.conflict)
134
self.assertContainsString(text, self.conflict.path)
135
self.assertContainsString(text.lower(), "conflict")
136
self.assertContainsString(repr(self.conflict),
137
self.conflict.__class__.__name__)
152
139
def test_stanza_roundtrip(self):
153
# write and read our example stanza.
154
stanza_iter = example_conflicts.to_stanzas()
155
processed = conflicts.ConflictList.from_stanzas(stanza_iter)
156
for o, p in zip(processed, example_conflicts):
157
self.assertEqual(o, p)
159
self.assertIsInstance(o.path, unicode)
161
if o.file_id is not None:
162
self.assertIsInstance(o.file_id, str)
164
conflict_path = getattr(o, 'conflict_path', None)
165
if conflict_path is not None:
166
self.assertIsInstance(conflict_path, unicode)
168
conflict_file_id = getattr(o, 'conflict_file_id', None)
169
if conflict_file_id is not None:
170
self.assertIsInstance(conflict_file_id, str)
141
o = conflicts.Conflict.factory(**p.as_stanza().as_dict())
142
self.assertEqual(o, p)
144
self.assertIsInstance(o.path, unicode)
146
if o.file_id is not None:
147
self.assertIsInstance(o.file_id, str)
149
conflict_path = getattr(o, 'conflict_path', None)
150
if conflict_path is not None:
151
self.assertIsInstance(conflict_path, unicode)
153
conflict_file_id = getattr(o, 'conflict_file_id', None)
154
if conflict_file_id is not None:
155
self.assertIsInstance(conflict_file_id, str)
172
157
def test_stanzification(self):
173
for stanza in example_conflicts.to_stanzas():
174
if 'file_id' in stanza:
175
# In Stanza form, the file_id has to be unicode.
176
self.assertStartsWith(stanza['file_id'], u'\xeed')
177
self.assertStartsWith(stanza['path'], u'p\xe5th')
178
if 'conflict_path' in stanza:
179
self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
180
if 'conflict_file_id' in stanza:
181
self.assertStartsWith(stanza['conflict_file_id'], u'\xeed')
158
stanza = self.conflict.as_stanza()
159
if 'file_id' in stanza:
160
# In Stanza form, the file_id has to be unicode.
161
self.assertStartsWith(stanza['file_id'], u'\xeed')
162
self.assertStartsWith(stanza['path'], u'p\xe5th')
163
if 'conflict_path' in stanza:
164
self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
165
if 'conflict_file_id' in stanza:
166
self.assertStartsWith(stanza['conflict_file_id'], u'\xeed')
169
class TestConflictList(tests.TestCase):
171
def test_stanzas_roundtrip(self):
172
stanzas_iter = example_conflicts.to_stanzas()
173
processed = conflicts.ConflictList.from_stanzas(stanzas_iter)
174
self.assertEqual(example_conflicts, processed)
176
def test_stringification(self):
177
for text, o in zip(example_conflicts.to_strings(), example_conflicts):
178
self.assertEqual(text, unicode(o))
184
181
# FIXME: The shell-like tests should be converted to real whitebox tests... or
449
446
dict(actions='modify_file', check='file_has_more_content')),
451
448
dict(actions='delete_file', check='file_doesnt_exist')),),
449
# File renamed-modified/deleted
450
(dict(_base_actions='create_file',
451
_path='new-file', _file_id='file-id'),
452
('file_renamed_and_modified',
453
dict(actions='modify_and_rename_file',
454
check='file_renamed_and_more_content')),
456
dict(actions='delete_file', check='file_doesnt_exist')),),
452
457
# File modified/deleted in dir
453
458
(dict(_base_actions='create_file_in_dir',
454
459
_path='dir/file', _file_id='file-id'),
466
471
def do_modify_file(self):
467
472
return [('modify', ('file-id', 'trunk content\nmore content\n'))]
474
def do_modify_and_rename_file(self):
475
return [('modify', ('file-id', 'trunk content\nmore content\n')),
476
('rename', ('file', 'new-file'))]
469
478
def check_file_has_more_content(self):
470
479
self.assertFileEqual('trunk content\nmore content\n', 'branch/file')
481
def check_file_renamed_and_more_content(self):
482
self.assertFileEqual('trunk content\nmore content\n', 'branch/new-file')
472
484
def do_delete_file(self):
473
485
return [('unversion', 'file-id')]