24
24
from bzrlib.errors import BinaryFile, NoDiff
25
25
import bzrlib.osutils as osutils
26
26
import bzrlib.patiencediff
27
from bzrlib.tests import (TestCase, TestCaseWithTransport,
27
from bzrlib.tests import (Feature, TestCase, TestCaseWithTransport,
28
28
TestCaseInTempDir, TestSkipped)
31
class _UnicodeFilename(Feature):
32
"""Does the filesystem support Unicode filenames?"""
37
except UnicodeEncodeError:
39
except (IOError, OSError):
40
# The filesystem allows the Unicode filename but the file doesn't
44
# The filesystem allows the Unicode filename and the file exists,
48
UnicodeFilename = _UnicodeFilename()
51
class TestUnicodeFilename(TestCase):
53
def test_probe_passes(self):
54
"""UnicodeFilename._probe passes."""
55
# We can't test much more than that because the behaviour depends
57
UnicodeFilename._probe()
31
60
def udiff_lines(old, new, allow_binary=False):
32
61
output = StringIO()
33
62
internal_diff('old', old, 'new', new, output, allow_binary)
441
470
self.assertContainsRe(diff, '-contents\n'
442
471
'\\+new contents\n')
473
def test_binary_unicode_filenames(self):
474
"""Test that contents of files are *not* encoded in UTF-8 when there
475
is a binary file in the diff.
477
# See https://bugs.launchpad.net/bugs/110092.
478
self.requireFeature(UnicodeFilename)
480
# This bug isn't triggered with cStringIO.
481
from StringIO import StringIO
482
tree = self.make_branch_and_tree('tree')
483
alpha, omega = u'\u03b1', u'\u03c9'
484
alpha_utf8, omega_utf8 = alpha.encode('utf8'), omega.encode('utf8')
485
self.build_tree_contents(
486
[('tree/' + alpha, chr(0)),
488
('The %s and the %s\n' % (alpha_utf8, omega_utf8)))])
489
tree.add([alpha], ['file-id'])
490
tree.add([omega], ['file-id-2'])
491
diff_content = StringIO()
492
show_diff_trees(tree.basis_tree(), tree, diff_content)
493
diff = diff_content.getvalue()
494
self.assertContainsRe(diff, r"=== added file '%s'" % alpha_utf8)
495
self.assertContainsRe(
496
diff, "Binary files a/%s.*and b/%s.* differ\n" % (alpha_utf8, alpha_utf8))
497
self.assertContainsRe(diff, r"=== added file '%s'" % omega_utf8)
498
self.assertContainsRe(diff, r"--- a/%s" % (omega_utf8,))
499
self.assertContainsRe(diff, r"\+\+\+ b/%s" % (omega_utf8,))
445
502
class TestPatienceDiffLib(TestCase):