36
35
from bzrlib.errors import BinaryFile, NoDiff, ExecutableMissing
37
36
import bzrlib.osutils as osutils
38
import bzrlib.revision as _mod_revision
39
37
import bzrlib.transform as transform
40
38
import bzrlib.patiencediff
41
39
import bzrlib._patiencediff_py
43
41
TestCaseInTempDir, TestSkipped)
46
class _AttribFeature(Feature):
49
if (sys.platform not in ('cygwin', 'win32')):
52
proc = subprocess.Popen(['attrib', '.'], stdout=subprocess.PIPE)
55
return (0 == proc.wait())
57
def feature_name(self):
58
return 'attrib Windows command-line tool'
60
AttribFeature = _AttribFeature()
63
44
class _CompiledPatienceDiffFeature(Feature):
75
56
CompiledPatienceDiffFeature = _CompiledPatienceDiffFeature()
59
class _UnicodeFilename(Feature):
60
"""Does the filesystem support Unicode filenames?"""
65
except UnicodeEncodeError:
67
except (IOError, OSError):
68
# The filesystem allows the Unicode filename but the file doesn't
72
# The filesystem allows the Unicode filename and the file exists,
76
UnicodeFilename = _UnicodeFilename()
79
class TestUnicodeFilename(TestCase):
81
def test_probe_passes(self):
82
"""UnicodeFilename._probe passes."""
83
# We can't test much more than that because the behaviour depends
85
UnicodeFilename._probe()
78
88
def udiff_lines(old, new, allow_binary=False):
79
89
output = StringIO()
80
90
internal_diff('old', old, 'new', new, output, allow_binary)
359
369
def test_diff_add_files(self):
360
tree1 = self.b.repository.revision_tree(_mod_revision.NULL_REVISION)
370
tree1 = self.b.repository.revision_tree(None)
361
371
tree2 = self.b.repository.revision_tree('rev-1')
362
372
output = self.get_diff(tree1, tree2)
363
373
# the files have the epoch time stamp for the tree in which
538
548
is a binary file in the diff.
540
550
# See https://bugs.launchpad.net/bugs/110092.
541
self.requireFeature(tests.UnicodeFilenameFeature)
551
self.requireFeature(UnicodeFilename)
543
553
# This bug isn't triggered with cStringIO.
544
554
from StringIO import StringIO
564
574
def test_unicode_filename(self):
565
575
"""Test when the filename are unicode."""
566
self.requireFeature(tests.UnicodeFilenameFeature)
576
self.requireFeature(UnicodeFilename)
568
578
alpha, omega = u'\u03b1', u'\u03c9'
569
579
autf8, outf8 = alpha.encode('utf8'), omega.encode('utf8')
770
780
self._PatienceSequenceMatcher = \
771
781
bzrlib._patiencediff_py.PatienceSequenceMatcher_py
773
def test_diff_unicode_string(self):
774
a = ''.join([unichr(i) for i in range(4000, 4500, 3)])
775
b = ''.join([unichr(i) for i in range(4300, 4800, 2)])
776
sm = self._PatienceSequenceMatcher(None, a, b)
777
mb = sm.get_matching_blocks()
778
self.assertEquals(35, len(mb))
780
783
def test_unique_lcs(self):
781
784
unique_lcs = self._unique_lcs
782
785
self.assertEquals(unique_lcs('', ''), [])
1304
1307
self.assertEqual('a-tool-which-is-unlikely-to-exist could not be found'
1305
1308
' on this machine', str(e))
1307
def test_prepare_files_creates_paths_readable_by_windows_tool(self):
1308
self.requireFeature(AttribFeature)
1310
tree = self.make_branch_and_tree('tree')
1311
self.build_tree_contents([('tree/file', 'content')])
1312
tree.add('file', 'file-id')
1313
tree.commit('old tree')
1315
self.addCleanup(tree.unlock)
1316
diff_obj = DiffFromTool(['python', '-c',
1317
'print "%(old_path)s %(new_path)s"'],
1319
diff_obj._prepare_files('file-id', 'file', 'file')
1320
self.assertReadableByAttrib(diff_obj._root, 'old\\file', r'old\\file')
1321
self.assertReadableByAttrib(diff_obj._root, 'new\\file', r'new\\file')
1323
def assertReadableByAttrib(self, cwd, relpath, regex):
1324
proc = subprocess.Popen(['attrib', relpath],
1325
stdout=subprocess.PIPE,
1328
result = proc.stdout.read()
1329
self.assertContainsRe(result, regex)
1331
1310
def test_prepare_files(self):
1332
1311
output = StringIO()
1333
1312
tree = self.make_branch_and_tree('tree')
1334
1313
self.build_tree_contents([('tree/oldname', 'oldcontent')])
1335
self.build_tree_contents([('tree/oldname2', 'oldcontent2')])
1336
1314
tree.add('oldname', 'file-id')
1337
tree.add('oldname2', 'file2-id')
1338
1315
tree.commit('old tree', timestamp=0)
1339
1316
tree.rename_one('oldname', 'newname')
1340
tree.rename_one('oldname2', 'newname2')
1341
1317
self.build_tree_contents([('tree/newname', 'newcontent')])
1342
self.build_tree_contents([('tree/newname2', 'newcontent2')])
1343
1318
old_tree = tree.basis_tree()
1344
1319
old_tree.lock_read()
1345
1320
self.addCleanup(old_tree.unlock)
1357
1332
self.assertContainsRe(new_path, 'new/newname$')
1358
1333
self.assertFileEqual('oldcontent', old_path)
1359
1334
self.assertFileEqual('newcontent', new_path)
1360
if osutils.host_os_dereferences_symlinks():
1335
if osutils.has_symlinks():
1361
1336
self.assertTrue(os.path.samefile('tree/newname', new_path))
1362
1337
# make sure we can create files with the same parent directories
1363
diff_obj._prepare_files('file2-id', 'oldname2', 'newname2')
1338
diff_obj._prepare_files('file-id', 'oldname2', 'newname2')