~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: 2008-07-08 14:55:19 UTC
  • mfrom: (3530 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3532.
  • Revision ID: john@arbash-meinel.com-20080708145519-paqg4kjwbpgs2xmq
Merge bzr.dev 3530

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from cStringIO import StringIO
20
20
import errno
21
21
import subprocess
 
22
import sys
22
23
from tempfile import TemporaryFile
23
24
 
24
25
from bzrlib import tests
34
35
    )
35
36
from bzrlib.errors import BinaryFile, NoDiff, ExecutableMissing
36
37
import bzrlib.osutils as osutils
 
38
import bzrlib.transform as transform
37
39
import bzrlib.patiencediff
38
40
import bzrlib._patiencediff_py
39
41
from bzrlib.tests import (Feature, TestCase, TestCaseWithTransport,
40
42
                          TestCaseInTempDir, TestSkipped)
41
43
 
42
44
 
 
45
class _AttribFeature(Feature):
 
46
 
 
47
    def _probe(self):
 
48
        if (sys.platform not in ('cygwin', 'win32')):
 
49
            return False
 
50
        try:
 
51
            proc = subprocess.Popen(['attrib', '.'], stdout=subprocess.PIPE)
 
52
        except OSError, e:
 
53
            return False
 
54
        return (0 == proc.wait())
 
55
 
 
56
    def feature_name(self):
 
57
        return 'attrib Windows command-line tool'
 
58
 
 
59
AttribFeature = _AttribFeature()
 
60
 
 
61
 
43
62
class _CompiledPatienceDiffFeature(Feature):
44
63
 
45
64
    def _probe(self):
480
499
        self.assertContainsRe(diff, '-contents\n'
481
500
                                    '\\+new contents\n')
482
501
 
 
502
 
 
503
    def test_internal_diff_exec_property(self):
 
504
        tree = self.make_branch_and_tree('tree')
 
505
 
 
506
        tt = transform.TreeTransform(tree)
 
507
        tt.new_file('a', tt.root, 'contents\n', 'a-id', True)
 
508
        tt.new_file('b', tt.root, 'contents\n', 'b-id', False)
 
509
        tt.new_file('c', tt.root, 'contents\n', 'c-id', True)
 
510
        tt.new_file('d', tt.root, 'contents\n', 'd-id', False)
 
511
        tt.new_file('e', tt.root, 'contents\n', 'control-e-id', True)
 
512
        tt.new_file('f', tt.root, 'contents\n', 'control-f-id', False)
 
513
        tt.apply()
 
514
        tree.commit('one', rev_id='rev-1')
 
515
 
 
516
        tt = transform.TreeTransform(tree)
 
517
        tt.set_executability(False, tt.trans_id_file_id('a-id'))
 
518
        tt.set_executability(True, tt.trans_id_file_id('b-id'))
 
519
        tt.set_executability(False, tt.trans_id_file_id('c-id'))
 
520
        tt.set_executability(True, tt.trans_id_file_id('d-id'))
 
521
        tt.apply()
 
522
        tree.rename_one('c', 'new-c')
 
523
        tree.rename_one('d', 'new-d')
 
524
 
 
525
        diff = self.get_diff(tree.basis_tree(), tree)
 
526
 
 
527
        self.assertContainsRe(diff, r"file 'a'.*\(properties changed:.*\+x to -x.*\)")
 
528
        self.assertContainsRe(diff, r"file 'b'.*\(properties changed:.*-x to \+x.*\)")
 
529
        self.assertContainsRe(diff, r"file 'c'.*\(properties changed:.*\+x to -x.*\)")
 
530
        self.assertContainsRe(diff, r"file 'd'.*\(properties changed:.*-x to \+x.*\)")
 
531
        self.assertNotContainsRe(diff, r"file 'e'")
 
532
        self.assertNotContainsRe(diff, r"file 'f'")
 
533
 
 
534
 
483
535
    def test_binary_unicode_filenames(self):
484
536
        """Test that contents of files are *not* encoded in UTF-8 when there
485
537
        is a binary file in the diff.
486
538
        """
487
539
        # See https://bugs.launchpad.net/bugs/110092.
488
 
        self.requireFeature(UnicodeFilename)
 
540
        self.requireFeature(tests.UnicodeFilenameFeature)
489
541
 
490
542
        # This bug isn't triggered with cStringIO.
491
543
        from StringIO import StringIO
510
562
 
511
563
    def test_unicode_filename(self):
512
564
        """Test when the filename are unicode."""
513
 
        self.requireFeature(UnicodeFilename)
 
565
        self.requireFeature(tests.UnicodeFilenameFeature)
514
566
 
515
567
        alpha, omega = u'\u03b1', u'\u03c9'
516
568
        autf8, outf8 = alpha.encode('utf8'), omega.encode('utf8')
1244
1296
        self.assertEqual('a-tool-which-is-unlikely-to-exist could not be found'
1245
1297
                         ' on this machine', str(e))
1246
1298
 
 
1299
    def test_prepare_files_creates_paths_readable_by_windows_tool(self):
 
1300
        self.requireFeature(AttribFeature)
 
1301
        output = StringIO()
 
1302
        tree = self.make_branch_and_tree('tree')
 
1303
        self.build_tree_contents([('tree/file', 'content')])
 
1304
        tree.add('file', 'file-id')
 
1305
        tree.commit('old tree')
 
1306
        tree.lock_read()
 
1307
        self.addCleanup(tree.unlock)
 
1308
        diff_obj = DiffFromTool(['python', '-c',
 
1309
                                 'print "%(old_path)s %(new_path)s"'],
 
1310
                                tree, tree, output)
 
1311
        diff_obj._prepare_files('file-id', 'file', 'file')
 
1312
        self.assertReadableByAttrib(diff_obj._root, 'old\\file', r'old\\file')
 
1313
        self.assertReadableByAttrib(diff_obj._root, 'new\\file', r'new\\file')
 
1314
 
 
1315
    def assertReadableByAttrib(self, cwd, relpath, regex):
 
1316
        proc = subprocess.Popen(['attrib', relpath],
 
1317
                                stdout=subprocess.PIPE,
 
1318
                                cwd=cwd)
 
1319
        proc.wait()
 
1320
        result = proc.stdout.read()
 
1321
        self.assertContainsRe(result, regex)
 
1322
 
1247
1323
    def test_prepare_files(self):
1248
1324
        output = StringIO()
1249
1325
        tree = self.make_branch_and_tree('tree')
1250
1326
        self.build_tree_contents([('tree/oldname', 'oldcontent')])
 
1327
        self.build_tree_contents([('tree/oldname2', 'oldcontent2')])
1251
1328
        tree.add('oldname', 'file-id')
 
1329
        tree.add('oldname2', 'file2-id')
1252
1330
        tree.commit('old tree', timestamp=0)
1253
1331
        tree.rename_one('oldname', 'newname')
 
1332
        tree.rename_one('oldname2', 'newname2')
1254
1333
        self.build_tree_contents([('tree/newname', 'newcontent')])
 
1334
        self.build_tree_contents([('tree/newname2', 'newcontent2')])
1255
1335
        old_tree = tree.basis_tree()
1256
1336
        old_tree.lock_read()
1257
1337
        self.addCleanup(old_tree.unlock)
1269
1349
        self.assertContainsRe(new_path, 'new/newname$')
1270
1350
        self.assertFileEqual('oldcontent', old_path)
1271
1351
        self.assertFileEqual('newcontent', new_path)
1272
 
        if osutils.has_symlinks():
 
1352
        if osutils.host_os_dereferences_symlinks():
1273
1353
            self.assertTrue(os.path.samefile('tree/newname', new_path))
1274
1354
        # make sure we can create files with the same parent directories
1275
 
        diff_obj._prepare_files('file-id', 'oldname2', 'newname2')
 
1355
        diff_obj._prepare_files('file2-id', 'oldname2', 'newname2')