~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_diff.py

  • Committer: Vincent Ladeuil
  • Date: 2011-06-15 11:36:05 UTC
  • mto: This revision was merged to the branch mainline in revision 5975.
  • Revision ID: v.ladeuil+lp@free.fr-20110615113605-p7zyyfry9wy1hquc
Make ContentConflict resolution more robust

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
from bzrlib.symbol_versioning import deprecated_in
36
36
from bzrlib.tests import features, EncodingAdapter
37
37
from bzrlib.tests.blackbox.test_diff import subst_dates
38
 
from bzrlib.tests import (
39
 
    features,
40
 
    )
 
38
 
 
39
 
 
40
class _AttribFeature(tests.Feature):
 
41
 
 
42
    def _probe(self):
 
43
        if (sys.platform not in ('cygwin', 'win32')):
 
44
            return False
 
45
        try:
 
46
            proc = subprocess.Popen(['attrib', '.'], stdout=subprocess.PIPE)
 
47
        except OSError, e:
 
48
            return False
 
49
        return (0 == proc.wait())
 
50
 
 
51
    def feature_name(self):
 
52
        return 'attrib Windows command-line tool'
 
53
 
 
54
AttribFeature = _AttribFeature()
 
55
 
 
56
 
 
57
compiled_patiencediff_feature = tests.ModuleAvailableFeature(
 
58
                                    'bzrlib._patiencediff_c')
41
59
 
42
60
 
43
61
def udiff_lines(old, new, allow_binary=False):
496
514
        is a binary file in the diff.
497
515
        """
498
516
        # See https://bugs.launchpad.net/bugs/110092.
499
 
        self.requireFeature(features.UnicodeFilenameFeature)
 
517
        self.requireFeature(tests.UnicodeFilenameFeature)
500
518
 
501
519
        # This bug isn't triggered with cStringIO.
502
520
        from StringIO import StringIO
521
539
 
522
540
    def test_unicode_filename(self):
523
541
        """Test when the filename are unicode."""
524
 
        self.requireFeature(features.UnicodeFilenameFeature)
 
542
        self.requireFeature(tests.UnicodeFilenameFeature)
525
543
 
526
544
        alpha, omega = u'\u03b1', u'\u03c9'
527
545
        autf8, outf8 = alpha.encode('utf8'), omega.encode('utf8')
553
571
        """Test for bug #382699: unicode filenames on Windows should be shown
554
572
        in user encoding.
555
573
        """
556
 
        self.requireFeature(features.UnicodeFilenameFeature)
 
574
        self.requireFeature(tests.UnicodeFilenameFeature)
557
575
        # The word 'test' in Russian
558
576
        _russian_test = u'\u0422\u0435\u0441\u0442'
559
577
        directory = _russian_test + u'/'
690
708
             ' \@\@\n-old\n\+new\n\n')
691
709
 
692
710
    def test_diff_kind_change(self):
693
 
        self.requireFeature(features.SymlinkFeature)
 
711
        self.requireFeature(tests.SymlinkFeature)
694
712
        self.build_tree_contents([('old-tree/olddir/',),
695
713
                                  ('old-tree/olddir/oldfile', 'old\n')])
696
714
        self.old_tree.add('olddir')
1154
1172
 
1155
1173
class TestPatienceDiffLib_c(TestPatienceDiffLib):
1156
1174
 
1157
 
    _test_needs_features = [features.compiled_patiencediff_feature]
 
1175
    _test_needs_features = [compiled_patiencediff_feature]
1158
1176
 
1159
1177
    def setUp(self):
1160
1178
        super(TestPatienceDiffLib_c, self).setUp()
1250
1268
 
1251
1269
class TestPatienceDiffLibFiles_c(TestPatienceDiffLibFiles):
1252
1270
 
1253
 
    _test_needs_features = [features.compiled_patiencediff_feature]
 
1271
    _test_needs_features = [compiled_patiencediff_feature]
1254
1272
 
1255
1273
    def setUp(self):
1256
1274
        super(TestPatienceDiffLibFiles_c, self).setUp()
1262
1280
class TestUsingCompiledIfAvailable(tests.TestCase):
1263
1281
 
1264
1282
    def test_PatienceSequenceMatcher(self):
1265
 
        if features.compiled_patiencediff_feature.available():
 
1283
        if compiled_patiencediff_feature.available():
1266
1284
            from bzrlib._patiencediff_c import PatienceSequenceMatcher_c
1267
1285
            self.assertIs(PatienceSequenceMatcher_c,
1268
1286
                          patiencediff.PatienceSequenceMatcher)
1272
1290
                          patiencediff.PatienceSequenceMatcher)
1273
1291
 
1274
1292
    def test_unique_lcs(self):
1275
 
        if features.compiled_patiencediff_feature.available():
 
1293
        if compiled_patiencediff_feature.available():
1276
1294
            from bzrlib._patiencediff_c import unique_lcs_c
1277
1295
            self.assertIs(unique_lcs_c,
1278
1296
                          patiencediff.unique_lcs)
1282
1300
                          patiencediff.unique_lcs)
1283
1301
 
1284
1302
    def test_recurse_matches(self):
1285
 
        if features.compiled_patiencediff_feature.available():
 
1303
        if compiled_patiencediff_feature.available():
1286
1304
            from bzrlib._patiencediff_c import recurse_matches_c
1287
1305
            self.assertIs(recurse_matches_c,
1288
1306
                          patiencediff.recurse_matches)
1338
1356
                         ' on this machine', str(e))
1339
1357
 
1340
1358
    def test_prepare_files_creates_paths_readable_by_windows_tool(self):
1341
 
        self.requireFeature(features.AttribFeature)
 
1359
        self.requireFeature(AttribFeature)
1342
1360
        output = StringIO()
1343
1361
        tree = self.make_branch_and_tree('tree')
1344
1362
        self.build_tree_contents([('tree/file', 'content')])
1452
1470
class TestGetTreesAndBranchesToDiffLocked(tests.TestCaseWithTransport):
1453
1471
 
1454
1472
    def call_gtabtd(self, path_list, revision_specs, old_url, new_url):
1455
 
        """Call get_trees_and_branches_to_diff_locked."""
 
1473
        """Call get_trees_and_branches_to_diff_locked.  Overridden by
 
1474
        TestGetTreesAndBranchesToDiff.
 
1475
        """
1456
1476
        return diff.get_trees_and_branches_to_diff_locked(
1457
1477
            path_list, revision_specs, old_url, new_url, self.addCleanup)
1458
1478
 
1495
1515
        self.assertEqual(tree.branch.base, new_branch.base)
1496
1516
        self.assertIs(None, specific_files)
1497
1517
        self.assertEqual(tree.basedir, extra_trees[0].basedir)
 
1518
 
 
1519
 
 
1520
class TestGetTreesAndBranchesToDiff(TestGetTreesAndBranchesToDiffLocked):
 
1521
    """Apply the tests for get_trees_and_branches_to_diff_locked to the
 
1522
    deprecated get_trees_and_branches_to_diff function.
 
1523
    """
 
1524
 
 
1525
    def call_gtabtd(self, path_list, revision_specs, old_url, new_url):
 
1526
        return self.applyDeprecated(
 
1527
            deprecated_in((2, 2, 0)), diff.get_trees_and_branches_to_diff,
 
1528
            path_list, revision_specs, old_url, new_url)