63
63
AttribFeature = _AttribFeature()
66
class _CompiledPatienceDiffFeature(Feature):
70
import bzrlib._patiencediff_c
75
def feature_name(self):
76
return 'bzrlib._patiencediff_c'
78
CompiledPatienceDiffFeature = _CompiledPatienceDiffFeature()
66
compiled_patiencediff_feature = tests.ModuleAvailableFeature(
67
'bzrlib._patiencediff_c')
81
70
def udiff_lines(old, new, allow_binary=False):
1157
1146
class TestPatienceDiffLib_c(TestPatienceDiffLib):
1159
_test_needs_features = [CompiledPatienceDiffFeature]
1148
_test_needs_features = [compiled_patiencediff_feature]
1161
1150
def setUp(self):
1162
1151
super(TestPatienceDiffLib_c, self).setUp()
1253
1242
class TestPatienceDiffLibFiles_c(TestPatienceDiffLibFiles):
1255
_test_needs_features = [CompiledPatienceDiffFeature]
1244
_test_needs_features = [compiled_patiencediff_feature]
1257
1246
def setUp(self):
1258
1247
super(TestPatienceDiffLibFiles_c, self).setUp()
1264
1253
class TestUsingCompiledIfAvailable(TestCase):
1266
1255
def test_PatienceSequenceMatcher(self):
1267
if CompiledPatienceDiffFeature.available():
1256
if compiled_patiencediff_feature.available():
1268
1257
from bzrlib._patiencediff_c import PatienceSequenceMatcher_c
1269
1258
self.assertIs(PatienceSequenceMatcher_c,
1270
1259
bzrlib.patiencediff.PatienceSequenceMatcher)
1274
1263
bzrlib.patiencediff.PatienceSequenceMatcher)
1276
1265
def test_unique_lcs(self):
1277
if CompiledPatienceDiffFeature.available():
1266
if compiled_patiencediff_feature.available():
1278
1267
from bzrlib._patiencediff_c import unique_lcs_c
1279
1268
self.assertIs(unique_lcs_c,
1280
1269
bzrlib.patiencediff.unique_lcs)
1284
1273
bzrlib.patiencediff.unique_lcs)
1286
1275
def test_recurse_matches(self):
1287
if CompiledPatienceDiffFeature.available():
1276
if compiled_patiencediff_feature.available():
1288
1277
from bzrlib._patiencediff_c import recurse_matches_c
1289
1278
self.assertIs(recurse_matches_c,
1290
1279
bzrlib.patiencediff.recurse_matches)
1337
1326
tree.commit('old tree')
1338
1327
tree.lock_read()
1339
1328
self.addCleanup(tree.unlock)
1329
basis_tree = tree.basis_tree()
1330
basis_tree.lock_read()
1331
self.addCleanup(basis_tree.unlock)
1340
1332
diff_obj = DiffFromTool(['python', '-c',
1341
1333
'print "@old_path @new_path"'],
1334
basis_tree, tree, output)
1343
1335
diff_obj._prepare_files('file-id', 'file', 'file')
1344
self.assertReadableByAttrib(diff_obj._root, 'old\\file', r'old\\file')
1345
self.assertReadableByAttrib(diff_obj._root, 'new\\file', r'new\\file')
1336
# The old content should be readonly
1337
self.assertReadableByAttrib(diff_obj._root, 'old\\file',
1339
# The new content should use the tree object, not a 'new' file anymore
1340
self.assertEndsWith(tree.basedir, 'work/tree')
1341
self.assertReadableByAttrib(tree.basedir, 'file', r'work\\tree\\file$')
1347
1343
def assertReadableByAttrib(self, cwd, relpath, regex):
1348
1344
proc = subprocess.Popen(['attrib', relpath],
1349
1345
stdout=subprocess.PIPE,
1352
result = proc.stdout.read()
1353
self.assertContainsRe(result, regex)
1347
(result, err) = proc.communicate()
1348
self.assertContainsRe(result.replace('\r\n', '\n'), regex)
1355
1350
def test_prepare_files(self):
1356
1351
output = StringIO()