/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

  • Committer: INADA Naoki
  • Date: 2011-05-06 01:00:31 UTC
  • mto: This revision was merged to the branch mainline in revision 5892.
  • Revision ID: songofacandy@gmail.com-20110506010031-fgrh2f26i80a070z
Test for filename encoding can't test subprocess execution because
can't override Py_FileSystemDefaultEncoding in CPython.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1423
1423
 
1424
1424
class TestDiffFromToolEncodedFilename(tests.TestCaseWithTransport):
1425
1425
 
1426
 
    def check_filename_passed(self, dirname, filename):
1427
 
        output = StringIO()
1428
 
        tree = self.make_branch_and_tree(dirname)
1429
 
        self.build_tree_contents([(dirname+'/'+filename, 'oldcontent')])
1430
 
        tree.add(filename, 'file-id')
1431
 
        tree.commit('old tree', timestamp=0)
1432
 
        self.build_tree_contents([(dirname+'/'+filename, 'newcontent')])
1433
 
        old_tree = tree.basis_tree()
1434
 
        old_tree.lock_read()
1435
 
        self.addCleanup(old_tree.unlock)
1436
 
        tree.lock_read()
1437
 
        self.addCleanup(tree.unlock)
1438
 
        diff_obj = diff.DiffFromTool(
1439
 
                    ['python', '-c',
1440
 
                     ('import sys;'
1441
 
                      'sys.stdout.write('
1442
 
                      '  open(sys.argv[1], "rb").read()+":"+'
1443
 
                      '  open(sys.argv[2], "rb").read())'),
1444
 
                     '@old_path', '@new_path'],
1445
 
                    old_tree, tree, output)
1446
 
        self.addCleanup(diff_obj.finish)
1447
 
        diff_obj.diff('file-id', filename, filename, 'file', 'file')
1448
 
        self.assertEqual(
1449
 
                "oldcontent:newcontent",
1450
 
                output.getvalue()
1451
 
                )
1452
 
 
1453
1426
    def test_encodable_filename(self):
1454
1427
        import sys
 
1428
        diffobj = diff.DiffFromTool(['python', '@old_path', '@new_path'],
 
1429
                                    None, None, None)
1455
1430
        for _, scenario in EncodingAdapter.encoding_scenarios:
1456
1431
            encoding = scenario['encoding']
 
1432
            dirname  = scenario['info']['directory']
1457
1433
            filename = scenario['info']['filename']
1458
 
            dirname = 'encodable_' + scenario['info']['directory']
1459
1434
 
1460
1435
            self.overrideAttr(sys, 'getfilesystemencoding', lambda: encoding)
1461
 
            self.check_filename_passed(dirname, filename)
 
1436
            fullpath = diffobj._safe_filename('safe', dirname + u'/' + filename)
 
1437
            self.assertEqual(
 
1438
                    fullpath,
 
1439
                    fullpath.encode(encoding).decode(encoding)
 
1440
                    )
 
1441
            self.assert_(fullpath.startswith(diffobj._root + '/safe'))
1462
1442
 
1463
1443
    def test_unencodable_filename(self):
1464
1444
        import sys
 
1445
        diffobj = diff.DiffFromTool(['python', '@old_path', '@new_path'],
 
1446
                                    None, None, None)
1465
1447
        for _, scenario in EncodingAdapter.encoding_scenarios:
1466
1448
            encoding = scenario['encoding']
 
1449
            dirname  = scenario['info']['directory']
1467
1450
            filename = scenario['info']['filename']
1468
 
            dirname = 'unencodable_' + scenario['info']['directory']
1469
1451
 
1470
1452
            if encoding == 'iso-8859-1':
1471
1453
                encoding = 'iso-8859-2'
1472
1454
            else:
1473
1455
                encoding = 'iso-8859-1'
 
1456
 
1474
1457
            self.overrideAttr(sys, 'getfilesystemencoding', lambda: encoding)
1475
 
            self.check_filename_passed(dirname, filename)
 
1458
            fullpath = diffobj._safe_filename('safe', dirname + u'/' + filename)
 
1459
            self.assertEqual(
 
1460
                    fullpath,
 
1461
                    fullpath.encode(encoding).decode(encoding)
 
1462
                    )
 
1463
            self.assert_(fullpath.startswith(diffobj._root + '/safe'))
1476
1464
 
1477
1465
 
1478
1466
class TestGetTreesAndBranchesToDiffLocked(tests.TestCaseWithTransport):