~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_osutils.py

  • Committer: Aaron Bentley
  • Date: 2006-08-16 19:13:00 UTC
  • mfrom: (1934 +trunk)
  • mto: (1910.2.43 format-bumps)
  • mto: This revision was merged to the branch mainline in revision 1935.
  • Revision ID: abentley@panoramicfeedback.com-20060816191300-045772b26b975d1c
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
131
131
            finally:
132
132
                os.remove('socket')
133
133
 
 
134
    def test_get_umask(self):
 
135
        if sys.platform == 'win32':
 
136
            # umask always returns '0', no way to set it
 
137
            self.assertEqual(0, osutils.get_umask())
 
138
            return
 
139
 
 
140
        orig_umask = osutils.get_umask()
 
141
        try:
 
142
            os.umask(0222)
 
143
            self.assertEqual(0222, osutils.get_umask())
 
144
            os.umask(0022)
 
145
            self.assertEqual(0022, osutils.get_umask())
 
146
            os.umask(0002)
 
147
            self.assertEqual(0002, osutils.get_umask())
 
148
            os.umask(0027)
 
149
            self.assertEqual(0027, osutils.get_umask())
 
150
        finally:
 
151
            os.umask(orig_umask)
 
152
 
134
153
 
135
154
class TestSafeUnicode(TestCase):
136
155
 
420
439
            sorted(original_paths, cmp=osutils.compare_paths_prefix_order))
421
440
 
422
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
 
423
495
class TestTerminalEncoding(TestCase):
424
496
    """Test the auto-detection of proper terminal encoding."""
425
497