1
# Copyright (C) 2005, 2006 Canonical Ltd
1
# Copyright (C) 2005-2010 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
63
65
AttribFeature = _AttribFeature()
66
class _CompiledPatienceDiffFeature(Feature):
70
import bzrlib._patiencediff_c
75
def feature_name(self):
76
return 'bzrlib._patiencediff_c'
78
CompiledPatienceDiffFeature = _CompiledPatienceDiffFeature()
68
compiled_patiencediff_feature = tests.ModuleAvailableFeature(
69
'bzrlib._patiencediff_c')
81
72
def udiff_lines(old, new, allow_binary=False):
1157
1148
class TestPatienceDiffLib_c(TestPatienceDiffLib):
1159
_test_needs_features = [CompiledPatienceDiffFeature]
1150
_test_needs_features = [compiled_patiencediff_feature]
1161
1152
def setUp(self):
1162
1153
super(TestPatienceDiffLib_c, self).setUp()
1253
1244
class TestPatienceDiffLibFiles_c(TestPatienceDiffLibFiles):
1255
_test_needs_features = [CompiledPatienceDiffFeature]
1246
_test_needs_features = [compiled_patiencediff_feature]
1257
1248
def setUp(self):
1258
1249
super(TestPatienceDiffLibFiles_c, self).setUp()
1264
1255
class TestUsingCompiledIfAvailable(TestCase):
1266
1257
def test_PatienceSequenceMatcher(self):
1267
if CompiledPatienceDiffFeature.available():
1258
if compiled_patiencediff_feature.available():
1268
1259
from bzrlib._patiencediff_c import PatienceSequenceMatcher_c
1269
1260
self.assertIs(PatienceSequenceMatcher_c,
1270
1261
bzrlib.patiencediff.PatienceSequenceMatcher)
1274
1265
bzrlib.patiencediff.PatienceSequenceMatcher)
1276
1267
def test_unique_lcs(self):
1277
if CompiledPatienceDiffFeature.available():
1268
if compiled_patiencediff_feature.available():
1278
1269
from bzrlib._patiencediff_c import unique_lcs_c
1279
1270
self.assertIs(unique_lcs_c,
1280
1271
bzrlib.patiencediff.unique_lcs)
1284
1275
bzrlib.patiencediff.unique_lcs)
1286
1277
def test_recurse_matches(self):
1287
if CompiledPatienceDiffFeature.available():
1278
if compiled_patiencediff_feature.available():
1288
1279
from bzrlib._patiencediff_c import recurse_matches_c
1289
1280
self.assertIs(recurse_matches_c,
1290
1281
bzrlib.patiencediff.recurse_matches)
1303
1294
diff_obj.command_template)
1305
1296
def test_from_string_u5(self):
1306
diff_obj = DiffFromTool.from_string('diff -u\\ 5', None, None, None)
1297
diff_obj = DiffFromTool.from_string('diff "-u 5"', None, None, None)
1307
1298
self.addCleanup(diff_obj.finish)
1308
1299
self.assertEqual(['diff', '-u 5', '@old_path', '@new_path'],
1309
1300
diff_obj.command_template)
1310
1301
self.assertEqual(['diff', '-u 5', 'old-path', 'new-path'],
1311
1302
diff_obj._get_command('old-path', 'new-path'))
1304
def test_from_string_path_with_backslashes(self):
1305
self.requireFeature(BackslashDirSeparatorFeature)
1306
tool = 'C:\\Tools\\Diff.exe'
1307
diff_obj = DiffFromTool.from_string(tool, None, None, None)
1308
self.addCleanup(diff_obj.finish)
1309
self.assertEqual(['C:\\Tools\\Diff.exe', '@old_path', '@new_path'],
1310
diff_obj.command_template)
1311
self.assertEqual(['C:\\Tools\\Diff.exe', 'old-path', 'new-path'],
1312
diff_obj._get_command('old-path', 'new-path'))
1313
1314
def test_execute(self):
1314
1315
output = StringIO()