~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_diff.py

  • Committer: John Arbash Meinel
  • Date: 2009-12-10 17:16:19 UTC
  • mfrom: (4884 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4889.
  • Revision ID: john@arbash-meinel.com-20091210171619-ehdcxjbl8afhq9g1
Bring in bzr.dev 4884

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
    external_diff,
33
33
    internal_diff,
34
34
    show_diff_trees,
 
35
    get_trees_and_branches_to_diff,
35
36
    )
36
37
from bzrlib.errors import BinaryFile, NoDiff, ExecutableMissing
37
38
import bzrlib.osutils as osutils
41
42
import bzrlib._patiencediff_py
42
43
from bzrlib.tests import (Feature, TestCase, TestCaseWithTransport,
43
44
                          TestCaseInTempDir, TestSkipped)
 
45
from bzrlib.revisiontree import RevisionTree
 
46
from bzrlib.revisionspec import RevisionSpec
44
47
 
45
48
 
46
49
class _AttribFeature(Feature):
1296
1299
    def test_from_string(self):
1297
1300
        diff_obj = DiffFromTool.from_string('diff', None, None, None)
1298
1301
        self.addCleanup(diff_obj.finish)
1299
 
        self.assertEqual(['diff', '%(old_path)s', '%(new_path)s'],
 
1302
        self.assertEqual(['diff', '@old_path', '@new_path'],
1300
1303
            diff_obj.command_template)
1301
1304
 
1302
1305
    def test_from_string_u5(self):
1303
1306
        diff_obj = DiffFromTool.from_string('diff -u\\ 5', None, None, None)
1304
1307
        self.addCleanup(diff_obj.finish)
1305
 
        self.assertEqual(['diff', '-u 5', '%(old_path)s', '%(new_path)s'],
 
1308
        self.assertEqual(['diff', '-u 5', '@old_path', '@new_path'],
1306
1309
                         diff_obj.command_template)
1307
1310
        self.assertEqual(['diff', '-u 5', 'old-path', 'new-path'],
1308
1311
                         diff_obj._get_command('old-path', 'new-path'))
1310
1313
    def test_execute(self):
1311
1314
        output = StringIO()
1312
1315
        diff_obj = DiffFromTool(['python', '-c',
1313
 
                                 'print "%(old_path)s %(new_path)s"'],
 
1316
                                 'print "@old_path @new_path"'],
1314
1317
                                None, None, output)
1315
1318
        self.addCleanup(diff_obj.finish)
1316
1319
        diff_obj._execute('old', 'new')
1335
1338
        tree.lock_read()
1336
1339
        self.addCleanup(tree.unlock)
1337
1340
        diff_obj = DiffFromTool(['python', '-c',
1338
 
                                 'print "%(old_path)s %(new_path)s"'],
 
1341
                                 'print "@old_path @new_path"'],
1339
1342
                                tree, tree, output)
1340
1343
        diff_obj._prepare_files('file-id', 'file', 'file')
1341
1344
        self.assertReadableByAttrib(diff_obj._root, 'old\\file', r'old\\file')
1367
1370
        tree.lock_read()
1368
1371
        self.addCleanup(tree.unlock)
1369
1372
        diff_obj = DiffFromTool(['python', '-c',
1370
 
                                 'print "%(old_path)s %(new_path)s"'],
 
1373
                                 'print "@old_path @new_path"'],
1371
1374
                                old_tree, tree, output)
1372
1375
        self.addCleanup(diff_obj.finish)
1373
1376
        self.assertContainsRe(diff_obj._root, 'bzr-diff-[^/]*')
1375
1378
                                                     'newname')
1376
1379
        self.assertContainsRe(old_path, 'old/oldname$')
1377
1380
        self.assertEqual(0, os.stat(old_path).st_mtime)
1378
 
        self.assertContainsRe(new_path, 'new/newname$')
 
1381
        self.assertContainsRe(new_path, 'tree/newname$')
1379
1382
        self.assertFileEqual('oldcontent', old_path)
1380
1383
        self.assertFileEqual('newcontent', new_path)
1381
1384
        if osutils.host_os_dereferences_symlinks():
1382
1385
            self.assertTrue(os.path.samefile('tree/newname', new_path))
1383
1386
        # make sure we can create files with the same parent directories
1384
1387
        diff_obj._prepare_files('file2-id', 'oldname2', 'newname2')
 
1388
 
 
1389
 
 
1390
class TestGetTreesAndBranchesToDiff(TestCaseWithTransport):
 
1391
 
 
1392
    def test_basic(self):
 
1393
        tree = self.make_branch_and_tree('tree')
 
1394
        (old_tree, new_tree,
 
1395
         old_branch, new_branch,
 
1396
         specific_files, extra_trees) = \
 
1397
            get_trees_and_branches_to_diff(['tree'], None, None, None)
 
1398
 
 
1399
        self.assertIsInstance(old_tree, RevisionTree)
 
1400
        #print dir (old_tree)
 
1401
        self.assertEqual(_mod_revision.NULL_REVISION, old_tree.get_revision_id())
 
1402
        self.assertEqual(tree.basedir, new_tree.basedir)
 
1403
        self.assertEqual(tree.branch.base, old_branch.base)
 
1404
        self.assertEqual(tree.branch.base, new_branch.base)
 
1405
        self.assertIs(None, specific_files)
 
1406
        self.assertIs(None, extra_trees)
 
1407
 
 
1408
    def test_with_rev_specs(self):
 
1409
        tree = self.make_branch_and_tree('tree')
 
1410
        self.build_tree_contents([('tree/file', 'oldcontent')])
 
1411
        tree.add('file', 'file-id')
 
1412
        tree.commit('old tree', timestamp=0, rev_id="old-id")
 
1413
        self.build_tree_contents([('tree/file', 'newcontent')])
 
1414
        tree.commit('new tree', timestamp=0, rev_id="new-id")
 
1415
 
 
1416
        revisions = [RevisionSpec.from_string('1'),
 
1417
                     RevisionSpec.from_string('2')]
 
1418
        (old_tree, new_tree,
 
1419
         old_branch, new_branch,
 
1420
         specific_files, extra_trees) = \
 
1421
            get_trees_and_branches_to_diff(['tree'], revisions, None, None)
 
1422
 
 
1423
        self.assertIsInstance(old_tree, RevisionTree)
 
1424
        self.assertEqual("old-id", old_tree.get_revision_id())
 
1425
        self.assertIsInstance(new_tree, RevisionTree)
 
1426
        self.assertEqual("new-id", new_tree.get_revision_id())
 
1427
        self.assertEqual(tree.branch.base, old_branch.base)
 
1428
        self.assertEqual(tree.branch.base, new_branch.base)
 
1429
        self.assertIs(None, specific_files)
 
1430
        self.assertEqual(tree.basedir, extra_trees[0].basedir)