/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_diff.py

MergeĀ fromĀ smart-push-gpm.

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
41
42
                          TestCaseInTempDir, TestSkipped)
42
43
 
43
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
 
44
62
class _CompiledPatienceDiffFeature(Feature):
45
63
 
46
64
    def _probe(self):
56
74
CompiledPatienceDiffFeature = _CompiledPatienceDiffFeature()
57
75
 
58
76
 
59
 
class _UnicodeFilename(Feature):
60
 
    """Does the filesystem support Unicode filenames?"""
61
 
 
62
 
    def _probe(self):
63
 
        try:
64
 
            os.stat(u'\u03b1')
65
 
        except UnicodeEncodeError:
66
 
            return False
67
 
        except (IOError, OSError):
68
 
            # The filesystem allows the Unicode filename but the file doesn't
69
 
            # exist.
70
 
            return True
71
 
        else:
72
 
            # The filesystem allows the Unicode filename and the file exists,
73
 
            # for some reason.
74
 
            return True
75
 
 
76
 
UnicodeFilename = _UnicodeFilename()
77
 
 
78
 
 
79
 
class TestUnicodeFilename(TestCase):
80
 
 
81
 
    def test_probe_passes(self):
82
 
        """UnicodeFilename._probe passes."""
83
 
        # We can't test much more than that because the behaviour depends
84
 
        # on the platform.
85
 
        UnicodeFilename._probe()
86
 
        
87
 
 
88
77
def udiff_lines(old, new, allow_binary=False):
89
78
    output = StringIO()
90
79
    internal_diff('old', old, 'new', new, output, allow_binary)
548
537
        is a binary file in the diff.
549
538
        """
550
539
        # See https://bugs.launchpad.net/bugs/110092.
551
 
        self.requireFeature(UnicodeFilename)
 
540
        self.requireFeature(tests.UnicodeFilenameFeature)
552
541
 
553
542
        # This bug isn't triggered with cStringIO.
554
543
        from StringIO import StringIO
573
562
 
574
563
    def test_unicode_filename(self):
575
564
        """Test when the filename are unicode."""
576
 
        self.requireFeature(UnicodeFilename)
 
565
        self.requireFeature(tests.UnicodeFilenameFeature)
577
566
 
578
567
        alpha, omega = u'\u03b1', u'\u03c9'
579
568
        autf8, outf8 = alpha.encode('utf8'), omega.encode('utf8')
1307
1296
        self.assertEqual('a-tool-which-is-unlikely-to-exist could not be found'
1308
1297
                         ' on this machine', str(e))
1309
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
 
1310
1323
    def test_prepare_files(self):
1311
1324
        output = StringIO()
1312
1325
        tree = self.make_branch_and_tree('tree')
1313
1326
        self.build_tree_contents([('tree/oldname', 'oldcontent')])
 
1327
        self.build_tree_contents([('tree/oldname2', 'oldcontent2')])
1314
1328
        tree.add('oldname', 'file-id')
 
1329
        tree.add('oldname2', 'file2-id')
1315
1330
        tree.commit('old tree', timestamp=0)
1316
1331
        tree.rename_one('oldname', 'newname')
 
1332
        tree.rename_one('oldname2', 'newname2')
1317
1333
        self.build_tree_contents([('tree/newname', 'newcontent')])
 
1334
        self.build_tree_contents([('tree/newname2', 'newcontent2')])
1318
1335
        old_tree = tree.basis_tree()
1319
1336
        old_tree.lock_read()
1320
1337
        self.addCleanup(old_tree.unlock)
1332
1349
        self.assertContainsRe(new_path, 'new/newname$')
1333
1350
        self.assertFileEqual('oldcontent', old_path)
1334
1351
        self.assertFileEqual('newcontent', new_path)
1335
 
        if osutils.has_symlinks():
 
1352
        if osutils.host_os_dereferences_symlinks():
1336
1353
            self.assertTrue(os.path.samefile('tree/newname', new_path))
1337
1354
        # make sure we can create files with the same parent directories
1338
 
        diff_obj._prepare_files('file-id', 'oldname2', 'newname2')
 
1355
        diff_obj._prepare_files('file2-id', 'oldname2', 'newname2')