~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_diff.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-11-17 03:20:35 UTC
  • mfrom: (4792.4.3 456036)
  • Revision ID: pqm@pqm.ubuntu.com-20091117032035-s3sgtlixj1lrminn
(Gordon Tyler) Fix IndexError during 'bzr ignore /' (#456036)

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
AttribFeature = _AttribFeature()
64
64
 
65
65
 
66
 
compiled_patiencediff_feature = tests.ModuleAvailableFeature(
67
 
                                    'bzrlib._patiencediff_c')
 
66
class _CompiledPatienceDiffFeature(Feature):
 
67
 
 
68
    def _probe(self):
 
69
        try:
 
70
            import bzrlib._patiencediff_c
 
71
        except ImportError:
 
72
            return False
 
73
        return True
 
74
 
 
75
    def feature_name(self):
 
76
        return 'bzrlib._patiencediff_c'
 
77
 
 
78
CompiledPatienceDiffFeature = _CompiledPatienceDiffFeature()
68
79
 
69
80
 
70
81
def udiff_lines(old, new, allow_binary=False):
1145
1156
 
1146
1157
class TestPatienceDiffLib_c(TestPatienceDiffLib):
1147
1158
 
1148
 
    _test_needs_features = [compiled_patiencediff_feature]
 
1159
    _test_needs_features = [CompiledPatienceDiffFeature]
1149
1160
 
1150
1161
    def setUp(self):
1151
1162
        super(TestPatienceDiffLib_c, self).setUp()
1241
1252
 
1242
1253
class TestPatienceDiffLibFiles_c(TestPatienceDiffLibFiles):
1243
1254
 
1244
 
    _test_needs_features = [compiled_patiencediff_feature]
 
1255
    _test_needs_features = [CompiledPatienceDiffFeature]
1245
1256
 
1246
1257
    def setUp(self):
1247
1258
        super(TestPatienceDiffLibFiles_c, self).setUp()
1253
1264
class TestUsingCompiledIfAvailable(TestCase):
1254
1265
 
1255
1266
    def test_PatienceSequenceMatcher(self):
1256
 
        if compiled_patiencediff_feature.available():
 
1267
        if CompiledPatienceDiffFeature.available():
1257
1268
            from bzrlib._patiencediff_c import PatienceSequenceMatcher_c
1258
1269
            self.assertIs(PatienceSequenceMatcher_c,
1259
1270
                          bzrlib.patiencediff.PatienceSequenceMatcher)
1263
1274
                          bzrlib.patiencediff.PatienceSequenceMatcher)
1264
1275
 
1265
1276
    def test_unique_lcs(self):
1266
 
        if compiled_patiencediff_feature.available():
 
1277
        if CompiledPatienceDiffFeature.available():
1267
1278
            from bzrlib._patiencediff_c import unique_lcs_c
1268
1279
            self.assertIs(unique_lcs_c,
1269
1280
                          bzrlib.patiencediff.unique_lcs)
1273
1284
                          bzrlib.patiencediff.unique_lcs)
1274
1285
 
1275
1286
    def test_recurse_matches(self):
1276
 
        if compiled_patiencediff_feature.available():
 
1287
        if CompiledPatienceDiffFeature.available():
1277
1288
            from bzrlib._patiencediff_c import recurse_matches_c
1278
1289
            self.assertIs(recurse_matches_c,
1279
1290
                          bzrlib.patiencediff.recurse_matches)
1326
1337
        tree.commit('old tree')
1327
1338
        tree.lock_read()
1328
1339
        self.addCleanup(tree.unlock)
1329
 
        basis_tree = tree.basis_tree()
1330
 
        basis_tree.lock_read()
1331
 
        self.addCleanup(basis_tree.unlock)
1332
1340
        diff_obj = DiffFromTool(['python', '-c',
1333
1341
                                 'print "@old_path @new_path"'],
1334
 
                                basis_tree, tree, output)
 
1342
                                tree, tree, output)
1335
1343
        diff_obj._prepare_files('file-id', 'file', 'file')
1336
 
        # The old content should be readonly
1337
 
        self.assertReadableByAttrib(diff_obj._root, 'old\\file',
1338
 
                                    r'R.*old\\file$')
1339
 
        # The new content should use the tree object, not a 'new' file anymore
1340
 
        self.assertEndsWith(tree.basedir, 'work/tree')
1341
 
        self.assertReadableByAttrib(tree.basedir, 'file', r'work\\tree\\file$')
 
1344
        self.assertReadableByAttrib(diff_obj._root, 'old\\file', r'old\\file')
 
1345
        self.assertReadableByAttrib(diff_obj._root, 'new\\file', r'new\\file')
1342
1346
 
1343
1347
    def assertReadableByAttrib(self, cwd, relpath, regex):
1344
1348
        proc = subprocess.Popen(['attrib', relpath],
1345
1349
                                stdout=subprocess.PIPE,
1346
1350
                                cwd=cwd)
1347
 
        (result, err) = proc.communicate()
1348
 
        self.assertContainsRe(result.replace('\r\n', '\n'), regex)
 
1351
        proc.wait()
 
1352
        result = proc.stdout.read()
 
1353
        self.assertContainsRe(result, regex)
1349
1354
 
1350
1355
    def test_prepare_files(self):
1351
1356
        output = StringIO()
1373
1378
                                                     'newname')
1374
1379
        self.assertContainsRe(old_path, 'old/oldname$')
1375
1380
        self.assertEqual(0, os.stat(old_path).st_mtime)
1376
 
        self.assertContainsRe(new_path, 'tree/newname$')
 
1381
        self.assertContainsRe(new_path, 'new/newname$')
1377
1382
        self.assertFileEqual('oldcontent', old_path)
1378
1383
        self.assertFileEqual('newcontent', new_path)
1379
1384
        if osutils.host_os_dereferences_symlinks():