/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 bzr.dev into cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
1299
1299
    def test_from_string(self):
1300
1300
        diff_obj = DiffFromTool.from_string('diff', None, None, None)
1301
1301
        self.addCleanup(diff_obj.finish)
1302
 
        self.assertEqual(['diff', '%(old_path)s', '%(new_path)s'],
 
1302
        self.assertEqual(['diff', '@old_path', '@new_path'],
1303
1303
            diff_obj.command_template)
1304
1304
 
1305
1305
    def test_from_string_u5(self):
1306
1306
        diff_obj = DiffFromTool.from_string('diff -u\\ 5', None, None, None)
1307
1307
        self.addCleanup(diff_obj.finish)
1308
 
        self.assertEqual(['diff', '-u 5', '%(old_path)s', '%(new_path)s'],
 
1308
        self.assertEqual(['diff', '-u 5', '@old_path', '@new_path'],
1309
1309
                         diff_obj.command_template)
1310
1310
        self.assertEqual(['diff', '-u 5', 'old-path', 'new-path'],
1311
1311
                         diff_obj._get_command('old-path', 'new-path'))
1313
1313
    def test_execute(self):
1314
1314
        output = StringIO()
1315
1315
        diff_obj = DiffFromTool(['python', '-c',
1316
 
                                 'print "%(old_path)s %(new_path)s"'],
 
1316
                                 'print "@old_path @new_path"'],
1317
1317
                                None, None, output)
1318
1318
        self.addCleanup(diff_obj.finish)
1319
1319
        diff_obj._execute('old', 'new')
1337
1337
        tree.commit('old tree')
1338
1338
        tree.lock_read()
1339
1339
        self.addCleanup(tree.unlock)
 
1340
        basis_tree = tree.basis_tree()
 
1341
        basis_tree.lock_read()
 
1342
        self.addCleanup(basis_tree.unlock)
1340
1343
        diff_obj = DiffFromTool(['python', '-c',
1341
 
                                 'print "%(old_path)s %(new_path)s"'],
1342
 
                                tree, tree, output)
 
1344
                                 'print "@old_path @new_path"'],
 
1345
                                basis_tree, tree, output)
1343
1346
        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')
 
1347
        # The old content should be readonly
 
1348
        self.assertReadableByAttrib(diff_obj._root, 'old\\file',
 
1349
                                    r'R.*old\\file$')
 
1350
        # The new content should use the tree object, not a 'new' file anymore
 
1351
        self.assertEndsWith(tree.basedir, 'work/tree')
 
1352
        self.assertReadableByAttrib(tree.basedir, 'file', r'work\\tree\\file$')
1346
1353
 
1347
1354
    def assertReadableByAttrib(self, cwd, relpath, regex):
1348
1355
        proc = subprocess.Popen(['attrib', relpath],
1349
1356
                                stdout=subprocess.PIPE,
1350
1357
                                cwd=cwd)
1351
 
        proc.wait()
1352
 
        result = proc.stdout.read()
1353
 
        self.assertContainsRe(result, regex)
 
1358
        (result, err) = proc.communicate()
 
1359
        self.assertContainsRe(result.replace('\r\n', '\n'), regex)
1354
1360
 
1355
1361
    def test_prepare_files(self):
1356
1362
        output = StringIO()
1370
1376
        tree.lock_read()
1371
1377
        self.addCleanup(tree.unlock)
1372
1378
        diff_obj = DiffFromTool(['python', '-c',
1373
 
                                 'print "%(old_path)s %(new_path)s"'],
 
1379
                                 'print "@old_path @new_path"'],
1374
1380
                                old_tree, tree, output)
1375
1381
        self.addCleanup(diff_obj.finish)
1376
1382
        self.assertContainsRe(diff_obj._root, 'bzr-diff-[^/]*')
1378
1384
                                                     'newname')
1379
1385
        self.assertContainsRe(old_path, 'old/oldname$')
1380
1386
        self.assertEqual(0, os.stat(old_path).st_mtime)
1381
 
        self.assertContainsRe(new_path, 'new/newname$')
 
1387
        self.assertContainsRe(new_path, 'tree/newname$')
1382
1388
        self.assertFileEqual('oldcontent', old_path)
1383
1389
        self.assertFileEqual('newcontent', new_path)
1384
1390
        if osutils.host_os_dereferences_symlinks():