~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
439
439
            sorted(original_paths, cmp=osutils.compare_paths_prefix_order))
440
440
 
441
441
 
 
442
class TestCopyTree(TestCaseInTempDir):
 
443
    
 
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'))
 
449
 
 
450
    def test_copy_tree_target_exists(self):
 
451
        self.build_tree(['source/', 'source/a', 'source/b/', 'source/b/c',
 
452
                         'target/'])
 
453
        osutils.copy_tree('source', 'target')
 
454
        self.assertEqual(['a', 'b'], os.listdir('target'))
 
455
        self.assertEqual(['c'], os.listdir('target/b'))
 
456
 
 
457
    def test_copy_tree_symlinks(self):
 
458
        if not osutils.has_symlinks():
 
459
            return
 
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'))
 
465
 
 
466
    def test_copy_tree_handlers(self):
 
467
        processed_files = []
 
468
        processed_links = []
 
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,
 
478
                   }
 
479
 
 
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)
 
484
 
 
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'),
 
489
                         ], processed_files)
 
490
        self.failIfExists('target')
 
491
        if osutils.has_symlinks():
 
492
            self.assertEqual([('source/lnk', 'target/lnk')], processed_links)
 
493
 
 
494
 
442
495
class TestTerminalEncoding(TestCase):
443
496
    """Test the auto-detection of proper terminal encoding."""
444
497