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

Method test_copy2_symlinks

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

Source from the content-addressed store, hash-verified

1403
1404 @os_helper.skip_unless_symlink
1405 def test_copy2_symlinks(self):
1406 tmp_dir = self.mkdtemp()
1407 src = os.path.join(tmp_dir, 'foo')
1408 dst = os.path.join(tmp_dir, 'bar')
1409 src_link = os.path.join(tmp_dir, 'baz')
1410 create_file(src, 'foo')
1411 os.symlink(src, src_link)
1412 if hasattr(os, 'lchmod'):
1413 os.lchmod(src_link, stat.S_IRWXU | stat.S_IRWXO)
1414 if hasattr(os, 'lchflags') and hasattr(stat, 'UF_NODUMP'):
1415 os.lchflags(src_link, stat.UF_NODUMP)
1416 src_stat = os.stat(src)
1417 src_link_stat = os.lstat(src_link)
1418 # follow
1419 shutil.copy2(src_link, dst, follow_symlinks=True)
1420 self.assertFalse(os.path.islink(dst))
1421 self.assertEqual(read_file(src), read_file(dst))
1422 os.remove(dst)
1423 # don't follow
1424 shutil.copy2(src_link, dst, follow_symlinks=False)
1425 self.assertTrue(os.path.islink(dst))
1426 self.assertEqual(os.readlink(dst), os.readlink(src_link))
1427 dst_stat = os.lstat(dst)
1428 if os.utime in os.supports_follow_symlinks:
1429 for attr in 'st_atime', 'st_mtime':
1430 # The modification times may be truncated in the new file.
1431 self.assertLessEqual(getattr(src_link_stat, attr),
1432 getattr(dst_stat, attr) + 1)
1433 if hasattr(os, 'lchmod'):
1434 self.assertEqual(src_link_stat.st_mode, dst_stat.st_mode)
1435 self.assertNotEqual(src_stat.st_mode, dst_stat.st_mode)
1436 if hasattr(os, 'lchflags') and hasattr(src_link_stat, 'st_flags'):
1437 self.assertEqual(src_link_stat.st_flags, dst_stat.st_flags)
1438
1439 @os_helper.skip_unless_xattr
1440 def test_copy2_xattr(self):

Callers

nothing calls this directly

Calls 15

read_fileFunction · 0.85
mkdtempMethod · 0.80
lchmodMethod · 0.80
lstatMethod · 0.80
assertFalseMethod · 0.80
islinkMethod · 0.80
assertTrueMethod · 0.80
assertLessEqualMethod · 0.80
assertNotEqualMethod · 0.80
create_fileFunction · 0.70
joinMethod · 0.45
statMethod · 0.45

Tested by

no test coverage detected