1424
1424
class TestDiffFromToolEncodedFilename(tests.TestCaseWithTransport):
1426
def check_filename_passed(self, dirname, filename):
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)
1437
self.addCleanup(tree.unlock)
1438
diff_obj = diff.DiffFromTool(
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')
1449
"oldcontent:newcontent",
1453
1426
def test_encodable_filename(self):
1428
diffobj = diff.DiffFromTool(['python', '@old_path', '@new_path'],
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']
1460
1435
self.overrideAttr(sys, 'getfilesystemencoding', lambda: encoding)
1461
self.check_filename_passed(dirname, filename)
1436
fullpath = diffobj._safe_filename('safe', dirname + u'/' + filename)
1439
fullpath.encode(encoding).decode(encoding)
1441
self.assert_(fullpath.startswith(diffobj._root + '/safe'))
1463
1443
def test_unencodable_filename(self):
1445
diffobj = diff.DiffFromTool(['python', '@old_path', '@new_path'],
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']
1470
1452
if encoding == 'iso-8859-1':
1471
1453
encoding = 'iso-8859-2'
1473
1455
encoding = 'iso-8859-1'
1474
1457
self.overrideAttr(sys, 'getfilesystemencoding', lambda: encoding)
1475
self.check_filename_passed(dirname, filename)
1458
fullpath = diffobj._safe_filename('safe', dirname + u'/' + filename)
1461
fullpath.encode(encoding).decode(encoding)
1463
self.assert_(fullpath.startswith(diffobj._root + '/safe'))
1478
1466
class TestGetTreesAndBranchesToDiffLocked(tests.TestCaseWithTransport):