MCPcopy Index your code
hub / github.com/python/cpython / test_copytree_dirs_exist_ok

Method test_copytree_dirs_exist_ok

Lib/test/test_shutil.py:771–794  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

769 self.assertEqual(actual, '456')
770
771 def test_copytree_dirs_exist_ok(self):
772 src_dir = self.mkdtemp()
773 dst_dir = self.mkdtemp()
774 self.addCleanup(shutil.rmtree, src_dir)
775 self.addCleanup(shutil.rmtree, dst_dir)
776
777 create_file((src_dir, 'nonexisting.txt'), '123')
778 os.mkdir(os.path.join(src_dir, 'existing_dir'))
779 os.mkdir(os.path.join(dst_dir, 'existing_dir'))
780 create_file((dst_dir, 'existing_dir', 'existing.txt'), 'will be replaced')
781 create_file((src_dir, 'existing_dir', 'existing.txt'), 'has been replaced')
782
783 shutil.copytree(src_dir, dst_dir, dirs_exist_ok=True)
784 self.assertTrue(os.path.isfile(os.path.join(dst_dir, 'nonexisting.txt')))
785 self.assertTrue(os.path.isdir(os.path.join(dst_dir, 'existing_dir')))
786 self.assertTrue(os.path.isfile(os.path.join(dst_dir, 'existing_dir',
787 'existing.txt')))
788 actual = read_file((dst_dir, 'nonexisting.txt'))
789 self.assertEqual(actual, '123')
790 actual = read_file((dst_dir, 'existing_dir', 'existing.txt'))
791 self.assertEqual(actual, 'has been replaced')
792
793 with self.assertRaises(FileExistsError):
794 shutil.copytree(src_dir, dst_dir, dirs_exist_ok=False)
795
796 @os_helper.skip_unless_symlink
797 def test_copytree_symlinks(self):

Callers

nothing calls this directly

Calls 11

read_fileFunction · 0.85
mkdtempMethod · 0.80
addCleanupMethod · 0.80
assertTrueMethod · 0.80
create_fileFunction · 0.70
mkdirMethod · 0.45
joinMethod · 0.45
isfileMethod · 0.45
isdirMethod · 0.45
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected