~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_diff.py

  • Committer: Robert Collins
  • Date: 2008-01-03 21:02:06 UTC
  • mfrom: (3162 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3163.
  • Revision ID: robertc@robertcollins.net-20080103210206-eqvta89m37jgjjfi
Resolve conflicts with bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import os
 
18
import os.path
18
19
from cStringIO import StringIO
19
20
import errno
20
21
import subprocess
21
22
from tempfile import TemporaryFile
22
23
 
 
24
from bzrlib import tests
23
25
from bzrlib.diff import (
24
26
    DiffFromTool,
25
27
    DiffPath,
30
32
    internal_diff,
31
33
    show_diff_trees,
32
34
    )
33
 
from bzrlib.errors import BinaryFile, NoDiff
 
35
from bzrlib.errors import BinaryFile, NoDiff, ExecutableMissing
34
36
import bzrlib.osutils as osutils
35
37
import bzrlib.patiencediff
36
38
import bzrlib._patiencediff_py
663
665
             ' \@\@\n-old\n\+new\n\n')
664
666
 
665
667
    def test_diff_kind_change(self):
 
668
        self.requireFeature(tests.SymlinkFeature)
666
669
        self.build_tree_contents([('old-tree/olddir/',),
667
670
                                  ('old-tree/olddir/oldfile', 'old\n')])
668
671
        self.old_tree.add('olddir')
1256
1259
                                None, None, output)
1257
1260
        self.addCleanup(diff_obj.finish)
1258
1261
        diff_obj._execute('old', 'new')
1259
 
        self.assertEqual(output.getvalue(), 'old new\n')
 
1262
        self.assertEqual(output.getvalue().rstrip(), 'old new')
 
1263
 
 
1264
    def test_excute_missing(self):
 
1265
        diff_obj = DiffFromTool(['a-tool-which-is-unlikely-to-exist'],
 
1266
                                None, None, None)
 
1267
        self.addCleanup(diff_obj.finish)
 
1268
        e = self.assertRaises(ExecutableMissing, diff_obj._execute, 'old',
 
1269
                              'new')
 
1270
        self.assertEqual('a-tool-which-is-unlikely-to-exist could not be found'
 
1271
                         ' on this machine', str(e))
1260
1272
 
1261
1273
    def test_prepare_files(self):
1262
1274
        output = StringIO()
1263
1275
        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')])
 
1276
        self.build_tree_contents([('tree/oldname', 'oldcontent')])
 
1277
        tree.add('oldname', 'file-id')
 
1278
        tree.commit('old tree', timestamp=0)
 
1279
        tree.rename_one('oldname', 'newname')
 
1280
        self.build_tree_contents([('tree/newname', 'newcontent')])
1268
1281
        old_tree = tree.basis_tree()
1269
1282
        old_tree.lock_read()
1270
1283
        self.addCleanup(old_tree.unlock)
 
1284
        tree.lock_read()
 
1285
        self.addCleanup(tree.unlock)
1271
1286
        diff_obj = DiffFromTool(['python', '-c',
1272
1287
                                 'print "%(old_path)s %(new_path)s"'],
1273
1288
                                old_tree, tree, output)
1276
1291
        old_path, new_path = diff_obj._prepare_files('file-id', 'oldname',
1277
1292
                                                     'newname')
1278
1293
        self.assertContainsRe(old_path, 'old/oldname$')
 
1294
        self.assertEqual(0, os.stat(old_path).st_mtime)
1279
1295
        self.assertContainsRe(new_path, 'new/newname$')
1280
1296
        self.assertFileEqual('oldcontent', old_path)
1281
1297
        self.assertFileEqual('newcontent', new_path)
 
1298
        if osutils.has_symlinks():
 
1299
            self.assertTrue(os.path.samefile('tree/newname', new_path))
1282
1300
        # make sure we can create files with the same parent directories
1283
1301
        diff_obj._prepare_files('file-id', 'oldname2', 'newname2')