439
439
sorted(original_paths, cmp=osutils.compare_paths_prefix_order))
442
class TestCopyTree(TestCaseInTempDir):
444
def test_copy_basic_tree(self):
445
self.build_tree(['source/', 'source/a', 'source/b/', 'source/b/c'])
446
osutils.copy_tree('source', 'target')
447
self.assertEqual(['a', 'b'], os.listdir('target'))
448
self.assertEqual(['c'], os.listdir('target/b'))
450
def test_copy_tree_target_exists(self):
451
self.build_tree(['source/', 'source/a', 'source/b/', 'source/b/c',
453
osutils.copy_tree('source', 'target')
454
self.assertEqual(['a', 'b'], os.listdir('target'))
455
self.assertEqual(['c'], os.listdir('target/b'))
457
def test_copy_tree_symlinks(self):
458
if not osutils.has_symlinks():
460
self.build_tree(['source/'])
461
os.symlink('a/generic/path', 'source/lnk')
462
osutils.copy_tree('source', 'target')
463
self.assertEqual(['lnk'], os.listdir('target'))
464
self.assertEqual('a/generic/path', os.readlink('target/lnk'))
466
def test_copy_tree_handlers(self):
469
def file_handler(from_path, to_path):
470
processed_files.append(('f', from_path, to_path))
471
def dir_handler(from_path, to_path):
472
processed_files.append(('d', from_path, to_path))
473
def link_handler(from_path, to_path):
474
processed_links.append((from_path, to_path))
475
handlers = {'file':file_handler,
476
'directory':dir_handler,
477
'symlink':link_handler,
480
self.build_tree(['source/', 'source/a', 'source/b/', 'source/b/c'])
481
if osutils.has_symlinks():
482
os.symlink('a/generic/path', 'source/lnk')
483
osutils.copy_tree('source', 'target', handlers=handlers)
485
self.assertEqual([('d', 'source', 'target'),
486
('f', 'source/a', 'target/a'),
487
('d', 'source/b', 'target/b'),
488
('f', 'source/b/c', 'target/b/c'),
490
self.failIfExists('target')
491
if osutils.has_symlinks():
492
self.assertEqual([('source/lnk', 'target/lnk')], processed_links)
442
495
class TestTerminalEncoding(TestCase):
443
496
"""Test the auto-detection of proper terminal encoding."""