35
35
from bzrlib.symbol_versioning import deprecated_in
36
36
from bzrlib.tests import features, EncodingAdapter
37
37
from bzrlib.tests.blackbox.test_diff import subst_dates
40
class _AttribFeature(tests.Feature):
43
if (sys.platform not in ('cygwin', 'win32')):
46
proc = subprocess.Popen(['attrib', '.'], stdout=subprocess.PIPE)
49
return (0 == proc.wait())
51
def feature_name(self):
52
return 'attrib Windows command-line tool'
54
AttribFeature = _AttribFeature()
57
compiled_patiencediff_feature = tests.ModuleAvailableFeature(
58
'bzrlib._patiencediff_c')
38
from bzrlib.tests import (
61
43
def udiff_lines(old, new, allow_binary=False):
229
211
self.assertIsInstance(output.getvalue(), str,
230
212
'internal_diff should return bytestrings')
214
def test_internal_diff_default_context(self):
216
diff.internal_diff('old', ['same_text\n','same_text\n','same_text\n',
217
'same_text\n','same_text\n','old_text\n'],
218
'new', ['same_text\n','same_text\n','same_text\n',
219
'same_text\n','same_text\n','new_text\n'], output)
220
lines = output.getvalue().splitlines(True)
221
self.check_patch(lines)
222
self.assertEquals(['--- old\n',
234
def test_internal_diff_no_context(self):
236
diff.internal_diff('old', ['same_text\n','same_text\n','same_text\n',
237
'same_text\n','same_text\n','old_text\n'],
238
'new', ['same_text\n','same_text\n','same_text\n',
239
'same_text\n','same_text\n','new_text\n'], output,
241
lines = output.getvalue().splitlines(True)
242
self.check_patch(lines)
243
self.assertEquals(['--- old\n',
252
def test_internal_diff_more_context(self):
254
diff.internal_diff('old', ['same_text\n','same_text\n','same_text\n',
255
'same_text\n','same_text\n','old_text\n'],
256
'new', ['same_text\n','same_text\n','same_text\n',
257
'same_text\n','same_text\n','new_text\n'], output,
259
lines = output.getvalue().splitlines(True)
260
self.check_patch(lines)
261
self.assertEquals(['--- old\n',
233
278
class TestDiffFiles(tests.TestCaseInTempDir):
238
283
lines = external_udiff_lines(['\x00foobar\n'], ['foo\x00bar\n'])
240
285
cmd = ['diff', '-u', '--binary', 'old', 'new']
241
open('old', 'wb').write('\x00foobar\n')
242
open('new', 'wb').write('foo\x00bar\n')
286
with open('old', 'wb') as f: f.write('\x00foobar\n')
287
with open('new', 'wb') as f: f.write('foo\x00bar\n')
243
288
pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE,
244
289
stdin=subprocess.PIPE)
245
290
out, err = pipe.communicate()
514
559
is a binary file in the diff.
516
561
# See https://bugs.launchpad.net/bugs/110092.
517
self.requireFeature(tests.UnicodeFilenameFeature)
562
self.requireFeature(features.UnicodeFilenameFeature)
519
564
# This bug isn't triggered with cStringIO.
520
565
from StringIO import StringIO
540
585
def test_unicode_filename(self):
541
586
"""Test when the filename are unicode."""
542
self.requireFeature(tests.UnicodeFilenameFeature)
587
self.requireFeature(features.UnicodeFilenameFeature)
544
589
alpha, omega = u'\u03b1', u'\u03c9'
545
590
autf8, outf8 = alpha.encode('utf8'), omega.encode('utf8')
571
616
"""Test for bug #382699: unicode filenames on Windows should be shown
572
617
in user encoding.
574
self.requireFeature(tests.UnicodeFilenameFeature)
619
self.requireFeature(features.UnicodeFilenameFeature)
575
620
# The word 'test' in Russian
576
621
_russian_test = u'\u0422\u0435\u0441\u0442'
577
622
directory = _russian_test + u'/'
708
753
' \@\@\n-old\n\+new\n\n')
710
755
def test_diff_kind_change(self):
711
self.requireFeature(tests.SymlinkFeature)
756
self.requireFeature(features.SymlinkFeature)
712
757
self.build_tree_contents([('old-tree/olddir/',),
713
758
('old-tree/olddir/oldfile', 'old\n')])
714
759
self.old_tree.add('olddir')
1209
1254
'how are you today?\n']
1210
1255
txt_b = ['hello there\n',
1211
1256
'how are you today?\n']
1212
open('a1', 'wb').writelines(txt_a)
1213
open('b1', 'wb').writelines(txt_b)
1257
with open('a1', 'wb') as f: f.writelines(txt_a)
1258
with open('b1', 'wb') as f: f.writelines(txt_b)
1215
1260
unified_diff_files = patiencediff.unified_diff_files
1216
1261
psm = self._PatienceSequenceMatcher
1227
1272
txt_a = map(lambda x: x+'\n', 'abcdefghijklmnop')
1228
1273
txt_b = map(lambda x: x+'\n', 'abcdefxydefghijklmnop')
1229
open('a2', 'wb').writelines(txt_a)
1230
open('b2', 'wb').writelines(txt_b)
1274
with open('a2', 'wb') as f: f.writelines(txt_a)
1275
with open('b2', 'wb') as f: f.writelines(txt_b)
1232
1277
# This is the result with LongestCommonSubstring matching
1233
1278
self.assertEquals(['--- a2\n',
1280
1325
class TestUsingCompiledIfAvailable(tests.TestCase):
1282
1327
def test_PatienceSequenceMatcher(self):
1283
if compiled_patiencediff_feature.available():
1328
if features.compiled_patiencediff_feature.available():
1284
1329
from bzrlib._patiencediff_c import PatienceSequenceMatcher_c
1285
1330
self.assertIs(PatienceSequenceMatcher_c,
1286
1331
patiencediff.PatienceSequenceMatcher)
1290
1335
patiencediff.PatienceSequenceMatcher)
1292
1337
def test_unique_lcs(self):
1293
if compiled_patiencediff_feature.available():
1338
if features.compiled_patiencediff_feature.available():
1294
1339
from bzrlib._patiencediff_c import unique_lcs_c
1295
1340
self.assertIs(unique_lcs_c,
1296
1341
patiencediff.unique_lcs)
1300
1345
patiencediff.unique_lcs)
1302
1347
def test_recurse_matches(self):
1303
if compiled_patiencediff_feature.available():
1348
if features.compiled_patiencediff_feature.available():
1304
1349
from bzrlib._patiencediff_c import recurse_matches_c
1305
1350
self.assertIs(recurse_matches_c,
1306
1351
patiencediff.recurse_matches)
1356
1401
' on this machine', str(e))
1358
1403
def test_prepare_files_creates_paths_readable_by_windows_tool(self):
1359
self.requireFeature(AttribFeature)
1404
self.requireFeature(features.AttribFeature)
1360
1405
output = StringIO()
1361
1406
tree = self.make_branch_and_tree('tree')
1362
1407
self.build_tree_contents([('tree/file', 'content')])
1470
1515
class TestGetTreesAndBranchesToDiffLocked(tests.TestCaseWithTransport):
1472
1517
def call_gtabtd(self, path_list, revision_specs, old_url, new_url):
1473
"""Call get_trees_and_branches_to_diff_locked. Overridden by
1474
TestGetTreesAndBranchesToDiff.
1518
"""Call get_trees_and_branches_to_diff_locked."""
1476
1519
return diff.get_trees_and_branches_to_diff_locked(
1477
1520
path_list, revision_specs, old_url, new_url, self.addCleanup)
1515
1558
self.assertEqual(tree.branch.base, new_branch.base)
1516
1559
self.assertIs(None, specific_files)
1517
1560
self.assertEqual(tree.basedir, extra_trees[0].basedir)
1520
class TestGetTreesAndBranchesToDiff(TestGetTreesAndBranchesToDiffLocked):
1521
"""Apply the tests for get_trees_and_branches_to_diff_locked to the
1522
deprecated get_trees_and_branches_to_diff function.
1525
def call_gtabtd(self, path_list, revision_specs, old_url, new_url):
1526
return self.applyDeprecated(
1527
deprecated_in((2, 2, 0)), diff.get_trees_and_branches_to_diff,
1528
path_list, revision_specs, old_url, new_url)