63
63
AttribFeature = _AttribFeature()
66
compiled_patiencediff_feature = tests.ModuleAvailableFeature(
67
'bzrlib._patiencediff_c')
66
class _CompiledPatienceDiffFeature(Feature):
70
import bzrlib._patiencediff_c
75
def feature_name(self):
76
return 'bzrlib._patiencediff_c'
78
CompiledPatienceDiffFeature = _CompiledPatienceDiffFeature()
70
81
def udiff_lines(old, new, allow_binary=False):
1146
1157
class TestPatienceDiffLib_c(TestPatienceDiffLib):
1148
_test_needs_features = [compiled_patiencediff_feature]
1159
_test_needs_features = [CompiledPatienceDiffFeature]
1150
1161
def setUp(self):
1151
1162
super(TestPatienceDiffLib_c, self).setUp()
1242
1253
class TestPatienceDiffLibFiles_c(TestPatienceDiffLibFiles):
1244
_test_needs_features = [compiled_patiencediff_feature]
1255
_test_needs_features = [CompiledPatienceDiffFeature]
1246
1257
def setUp(self):
1247
1258
super(TestPatienceDiffLibFiles_c, self).setUp()
1253
1264
class TestUsingCompiledIfAvailable(TestCase):
1255
1266
def test_PatienceSequenceMatcher(self):
1256
if compiled_patiencediff_feature.available():
1267
if CompiledPatienceDiffFeature.available():
1257
1268
from bzrlib._patiencediff_c import PatienceSequenceMatcher_c
1258
1269
self.assertIs(PatienceSequenceMatcher_c,
1259
1270
bzrlib.patiencediff.PatienceSequenceMatcher)
1263
1274
bzrlib.patiencediff.PatienceSequenceMatcher)
1265
1276
def test_unique_lcs(self):
1266
if compiled_patiencediff_feature.available():
1277
if CompiledPatienceDiffFeature.available():
1267
1278
from bzrlib._patiencediff_c import unique_lcs_c
1268
1279
self.assertIs(unique_lcs_c,
1269
1280
bzrlib.patiencediff.unique_lcs)
1273
1284
bzrlib.patiencediff.unique_lcs)
1275
1286
def test_recurse_matches(self):
1276
if compiled_patiencediff_feature.available():
1287
if CompiledPatienceDiffFeature.available():
1277
1288
from bzrlib._patiencediff_c import recurse_matches_c
1278
1289
self.assertIs(recurse_matches_c,
1279
1290
bzrlib.patiencediff.recurse_matches)
1326
1337
tree.commit('old tree')
1327
1338
tree.lock_read()
1328
1339
self.addCleanup(tree.unlock)
1329
basis_tree = tree.basis_tree()
1330
basis_tree.lock_read()
1331
self.addCleanup(basis_tree.unlock)
1332
1340
diff_obj = DiffFromTool(['python', '-c',
1333
1341
'print "@old_path @new_path"'],
1334
basis_tree, tree, output)
1335
1343
diff_obj._prepare_files('file-id', 'file', '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$')
1344
self.assertReadableByAttrib(diff_obj._root, 'old\\file', r'old\\file')
1345
self.assertReadableByAttrib(diff_obj._root, 'new\\file', r'new\\file')
1343
1347
def assertReadableByAttrib(self, cwd, relpath, regex):
1344
1348
proc = subprocess.Popen(['attrib', relpath],
1345
1349
stdout=subprocess.PIPE,
1347
(result, err) = proc.communicate()
1348
self.assertContainsRe(result.replace('\r\n', '\n'), regex)
1352
result = proc.stdout.read()
1353
self.assertContainsRe(result, regex)
1350
1355
def test_prepare_files(self):
1351
1356
output = StringIO()
1374
1379
self.assertContainsRe(old_path, 'old/oldname$')
1375
1380
self.assertEqual(0, os.stat(old_path).st_mtime)
1376
self.assertContainsRe(new_path, 'tree/newname$')
1381
self.assertContainsRe(new_path, 'new/newname$')
1377
1382
self.assertFileEqual('oldcontent', old_path)
1378
1383
self.assertFileEqual('newcontent', new_path)
1379
1384
if osutils.host_os_dereferences_symlinks():