~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_diff.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-12-27 15:01:46 UTC
  • mfrom: (3123.6.3 no-inventory2)
  • Revision ID: pqm@pqm.ubuntu.com-20071227150146-08nqv2gvo5e3i1n3
Implement native support for --using (abentley)

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from tempfile import TemporaryFile
22
22
 
23
23
from bzrlib.diff import (
24
 
    internal_diff,
25
 
    external_diff,
 
24
    DiffFromTool,
26
25
    DiffPath,
27
 
    show_diff_trees,
28
26
    DiffSymlink,
29
27
    DiffTree,
30
28
    DiffText,
 
29
    external_diff,
 
30
    internal_diff,
 
31
    show_diff_trees,
31
32
    )
32
33
from bzrlib.errors import BinaryFile, NoDiff
33
34
import bzrlib.osutils as osutils
1233
1234
            from bzrlib._patiencediff_py import recurse_matches_py
1234
1235
            self.assertIs(recurse_matches_py,
1235
1236
                          bzrlib.patiencediff.recurse_matches)
 
1237
 
 
1238
 
 
1239
class TestDiffFromTool(TestCaseWithTransport):
 
1240
 
 
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'))
 
1251
 
 
1252
    def test_execute(self):
 
1253
        output = StringIO()
 
1254
        diff_obj = DiffFromTool(['python', '-c',
 
1255
                                 'print "%(old_path)s %(new_path)s"'],
 
1256
                                None, None, output)
 
1257
        self.addCleanup(diff_obj.finish)
 
1258
        diff_obj._execute('old', 'new')
 
1259
        self.assertEqual(output.getvalue(), 'old new\n')
 
1260
 
 
1261
    def test_prepare_files(self):
 
1262
        output = StringIO()
 
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',
 
1277
                                                     'newname')
 
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')