~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_diff.py

  • Committer: Andrew Bennetts
  • Date: 2010-01-15 03:58:20 UTC
  • mfrom: (4963 +trunk)
  • mto: (4973.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4975.
  • Revision ID: andrew.bennetts@canonical.com-20100115035820-ilb3t36swgzq6v1l
MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
AttribFeature = _AttribFeature()
64
64
 
65
65
 
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()
 
66
compiled_patiencediff_feature = tests.ModuleAvailableFeature(
 
67
                                    'bzrlib._patiencediff_c')
79
68
 
80
69
 
81
70
def udiff_lines(old, new, allow_binary=False):
1156
1145
 
1157
1146
class TestPatienceDiffLib_c(TestPatienceDiffLib):
1158
1147
 
1159
 
    _test_needs_features = [CompiledPatienceDiffFeature]
 
1148
    _test_needs_features = [compiled_patiencediff_feature]
1160
1149
 
1161
1150
    def setUp(self):
1162
1151
        super(TestPatienceDiffLib_c, self).setUp()
1252
1241
 
1253
1242
class TestPatienceDiffLibFiles_c(TestPatienceDiffLibFiles):
1254
1243
 
1255
 
    _test_needs_features = [CompiledPatienceDiffFeature]
 
1244
    _test_needs_features = [compiled_patiencediff_feature]
1256
1245
 
1257
1246
    def setUp(self):
1258
1247
        super(TestPatienceDiffLibFiles_c, self).setUp()
1264
1253
class TestUsingCompiledIfAvailable(TestCase):
1265
1254
 
1266
1255
    def test_PatienceSequenceMatcher(self):
1267
 
        if CompiledPatienceDiffFeature.available():
 
1256
        if compiled_patiencediff_feature.available():
1268
1257
            from bzrlib._patiencediff_c import PatienceSequenceMatcher_c
1269
1258
            self.assertIs(PatienceSequenceMatcher_c,
1270
1259
                          bzrlib.patiencediff.PatienceSequenceMatcher)
1274
1263
                          bzrlib.patiencediff.PatienceSequenceMatcher)
1275
1264
 
1276
1265
    def test_unique_lcs(self):
1277
 
        if CompiledPatienceDiffFeature.available():
 
1266
        if compiled_patiencediff_feature.available():
1278
1267
            from bzrlib._patiencediff_c import unique_lcs_c
1279
1268
            self.assertIs(unique_lcs_c,
1280
1269
                          bzrlib.patiencediff.unique_lcs)
1284
1273
                          bzrlib.patiencediff.unique_lcs)
1285
1274
 
1286
1275
    def test_recurse_matches(self):
1287
 
        if CompiledPatienceDiffFeature.available():
 
1276
        if compiled_patiencediff_feature.available():
1288
1277
            from bzrlib._patiencediff_c import recurse_matches_c
1289
1278
            self.assertIs(recurse_matches_c,
1290
1279
                          bzrlib.patiencediff.recurse_matches)
1337
1326
        tree.commit('old tree')
1338
1327
        tree.lock_read()
1339
1328
        self.addCleanup(tree.unlock)
 
1329
        basis_tree = tree.basis_tree()
 
1330
        basis_tree.lock_read()
 
1331
        self.addCleanup(basis_tree.unlock)
1340
1332
        diff_obj = DiffFromTool(['python', '-c',
1341
1333
                                 'print "@old_path @new_path"'],
1342
 
                                tree, tree, output)
 
1334
                                basis_tree, tree, output)
1343
1335
        diff_obj._prepare_files('file-id', 'file', 'file')
1344
 
        self.assertReadableByAttrib(diff_obj._root, 'old\\file', r'old\\file')
1345
 
        self.assertReadableByAttrib(diff_obj._root, 'new\\file', r'new\\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$')
1346
1342
 
1347
1343
    def assertReadableByAttrib(self, cwd, relpath, regex):
1348
1344
        proc = subprocess.Popen(['attrib', relpath],
1349
1345
                                stdout=subprocess.PIPE,
1350
1346
                                cwd=cwd)
1351
 
        proc.wait()
1352
 
        result = proc.stdout.read()
1353
 
        self.assertContainsRe(result, regex)
 
1347
        (result, err) = proc.communicate()
 
1348
        self.assertContainsRe(result.replace('\r\n', '\n'), regex)
1354
1349
 
1355
1350
    def test_prepare_files(self):
1356
1351
        output = StringIO()