~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_conflicts.py

(gz) Fix unicode handling in bzrlib.conflicts ui code (Martin [gz])

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
72
    def test_resolve_conflict_dir(self):
120
125
        self.assertEqual(conflicts.ConflictList([]), tree.conflicts())
121
126
 
122
127
 
123
 
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__)
124
138
 
125
139
    def test_stanza_roundtrip(self):
126
 
        # write and read our example stanza.
127
 
        stanza_iter = example_conflicts.to_stanzas()
128
 
        processed = conflicts.ConflictList.from_stanzas(stanza_iter)
129
 
        for o, p in zip(processed, example_conflicts):
130
 
            self.assertEqual(o, p)
131
 
 
132
 
            self.assertIsInstance(o.path, unicode)
133
 
 
134
 
            if o.file_id is not None:
135
 
                self.assertIsInstance(o.file_id, str)
136
 
 
137
 
            conflict_path = getattr(o, 'conflict_path', None)
138
 
            if conflict_path is not None:
139
 
                self.assertIsInstance(conflict_path, unicode)
140
 
 
141
 
            conflict_file_id = getattr(o, 'conflict_file_id', None)
142
 
            if conflict_file_id is not None:
143
 
                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)
144
156
 
145
157
    def test_stanzification(self):
146
 
        for stanza in example_conflicts.to_stanzas():
147
 
            if 'file_id' in stanza:
148
 
                # In Stanza form, the file_id has to be unicode.
149
 
                self.assertStartsWith(stanza['file_id'], u'\xeed')
150
 
            self.assertStartsWith(stanza['path'], u'p\xe5th')
151
 
            if 'conflict_path' in stanza:
152
 
                self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
153
 
            if 'conflict_file_id' in stanza:
154
 
                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))
155
179
 
156
180
 
157
181
# FIXME: The shell-like tests should be converted to real whitebox tests... or