1233
1234
from bzrlib._patiencediff_py import recurse_matches_py
1234
1235
self.assertIs(recurse_matches_py,
1235
1236
bzrlib.patiencediff.recurse_matches)
1239
class TestDiffFromTool(TestCaseWithTransport):
1241
def test_from_string(self):
1242
diff_obj = DiffFromTool.from_string('diff', None, None, None)
1243
self.addCleanup(diff_obj.finish)
1244
self.assertEqual(['diff', '%(old_path)s', '%(new_path)s'],
1245
diff_obj.command_template)
1246
diff_obj = DiffFromTool.from_string('diff -u\\ 5', None, None, None)
1247
self.assertEqual(['diff', '-u 5', '%(old_path)s', '%(new_path)s'],
1248
diff_obj.command_template)
1249
self.assertEqual(['diff', '-u 5', 'old-path', 'new-path'],
1250
diff_obj._get_command('old-path', 'new-path'))
1252
def test_execute(self):
1254
diff_obj = DiffFromTool(['python', '-c',
1255
'print "%(old_path)s %(new_path)s"'],
1257
self.addCleanup(diff_obj.finish)
1258
diff_obj._execute('old', 'new')
1259
self.assertEqual(output.getvalue(), 'old new\n')
1261
def test_prepare_files(self):
1263
tree = self.make_branch_and_tree('tree')
1264
self.build_tree_contents([('tree/file', 'oldcontent')])
1265
tree.add('file', 'file-id')
1266
tree.commit('old tree')
1267
self.build_tree_contents([('tree/file', 'newcontent')])
1268
old_tree = tree.basis_tree()
1269
old_tree.lock_read()
1270
self.addCleanup(old_tree.unlock)
1271
diff_obj = DiffFromTool(['python', '-c',
1272
'print "%(old_path)s %(new_path)s"'],
1273
old_tree, tree, output)
1274
self.addCleanup(diff_obj.finish)
1275
self.assertContainsRe(diff_obj._root, 'bzr-diff-[^/]*')
1276
old_path, new_path = diff_obj._prepare_files('file-id', 'oldname',
1278
self.assertContainsRe(old_path, 'old/oldname$')
1279
self.assertContainsRe(new_path, 'new/newname$')
1280
self.assertFileEqual('oldcontent', old_path)
1281
self.assertFileEqual('newcontent', new_path)
1282
# make sure we can create files with the same parent directories
1283
diff_obj._prepare_files('file-id', 'oldname2', 'newname2')