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

  • Committer: Vincent Ladeuil
  • Date: 2011-07-06 09:22:00 UTC
  • mfrom: (6008 +trunk)
  • mto: (6012.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6013.
  • Revision ID: v.ladeuil+lp@free.fr-20110706092200-7iai2mwzc0sqdsvf
MergingĀ inĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
])
63
63
 
64
64
 
 
65
def vary_by_conflicts():
 
66
    for conflict in example_conflicts:
 
67
        yield (conflict.__class__.__name__, {"conflict": conflict})
 
68
 
 
69
 
65
70
class TestConflicts(tests.TestCaseWithTransport):
66
71
 
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'),
77
 
                                  ])
78
 
        tree.lock_read()
79
 
        self.assertLength(6, list(tree.list_files()))
80
 
        tree.unlock()
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')
93
 
 
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())
148
126
 
149
127
 
150
 
class TestConflictStanzas(tests.TestCase):
 
128
class TestPerConflict(tests.TestCase):
 
129
 
 
130
    scenarios = scenarios.multiply_scenarios(vary_by_conflicts())
 
131
 
 
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__)
151
138
 
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)
158
 
 
159
 
            self.assertIsInstance(o.path, unicode)
160
 
 
161
 
            if o.file_id is not None:
162
 
                self.assertIsInstance(o.file_id, str)
163
 
 
164
 
            conflict_path = getattr(o, 'conflict_path', None)
165
 
            if conflict_path is not None:
166
 
                self.assertIsInstance(conflict_path, unicode)
167
 
 
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)
 
140
        p = self.conflict
 
141
        o = conflicts.Conflict.factory(**p.as_stanza().as_dict())
 
142
        self.assertEqual(o, p)
 
143
 
 
144
        self.assertIsInstance(o.path, unicode)
 
145
 
 
146
        if o.file_id is not None:
 
147
            self.assertIsInstance(o.file_id, str)
 
148
 
 
149
        conflict_path = getattr(o, 'conflict_path', None)
 
150
        if conflict_path is not None:
 
151
            self.assertIsInstance(conflict_path, unicode)
 
152
 
 
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)
171
156
 
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')
 
167
 
 
168
 
 
169
class TestConflictList(tests.TestCase):
 
170
 
 
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)
 
175
 
 
176
    def test_stringification(self):
 
177
        for text, o in zip(example_conflicts.to_strings(), example_conflicts):
 
178
            self.assertEqual(text, unicode(o))
182
179
 
183
180
 
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')),
450
447
             ('file_deleted',
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')),
 
455
             ('file_deleted',
 
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'))]
468
473
 
 
474
    def do_modify_and_rename_file(self):
 
475
        return [('modify', ('file-id', 'trunk content\nmore content\n')),
 
476
                ('rename', ('file', 'new-file'))]
 
477
 
469
478
    def check_file_has_more_content(self):
470
479
        self.assertFileEqual('trunk content\nmore content\n', 'branch/file')
471
480
 
 
481
    def check_file_renamed_and_more_content(self):
 
482
        self.assertFileEqual('trunk content\nmore content\n', 'branch/new-file')
 
483
 
472
484
    def do_delete_file(self):
473
485
        return [('unversion', 'file-id')]
474
486