442
442
'\\+new contents\n')
444
444
def test_binary_unicode_filenames(self):
445
"""Test that contents of files are encoded in UTF-8 when there is a
446
binary file in the diff.
445
"""Test that contents of files are *not* encoded in UTF-8 when there
446
is a binary file in the diff.
448
448
# See https://bugs.launchpad.net/bugs/110092.
450
450
# This bug isn't triggered with cStringIO.
451
451
from StringIO import StringIO
452
452
tree = self.make_branch_and_tree('tree')
453
alpha, omega = u'\u03b1', u'\u03c9'
454
alpha_utf8, omega_utf8 = alpha.encode('utf8'), omega.encode('utf8')
453
455
self.build_tree_contents(
454
[('tree/binary', chr(0)),
455
('tree/elephant', '\xc7a trompe \xc3\xa9norm\xc3\xa9ment.\n')])
456
tree.add(['binary'], ['file-id'])
457
tree.add(['elephant'], ['file-id-2'])
456
[('tree/' + alpha, chr(0)),
458
('The %s and the %s\n' % (alpha_utf8, omega_utf8)))])
459
tree.add([alpha], ['file-id'])
460
tree.add([omega], ['file-id-2'])
458
461
diff_content = StringIO()
459
462
show_diff_trees(tree.basis_tree(), tree, diff_content)
460
463
diff = diff_content.getvalue()
461
self.assertContainsRe(diff, "=== added file 'binary'")
464
self.assertContainsRe(diff, r"=== added file '%s'" % alpha_utf8)
462
465
self.assertContainsRe(
463
diff, "Binary files a/binary.*and b/binary.* differ\n")
464
self.assertContainsRe(diff, "=== added file 'elephant'")
465
self.assertContainsRe(diff, "--- a/elephant")
466
self.assertContainsRe(diff, "\\+\\+\\+ b/elephant")
466
diff, "Binary files a/%s.*and b/%s.* differ\n" % (alpha_utf8, alpha_utf8))
467
self.assertContainsRe(diff, r"=== added file '%s'" % omega_utf8)
468
self.assertContainsRe(diff, r"--- a/%s" % (omega_utf8,))
469
self.assertContainsRe(diff, r"\+\+\+ b/%s" % (omega_utf8,))
469
472
class TestPatienceDiffLib(TestCase):