bpo-26978: Implement pathlib.Path.link_to (Using os.link) (GH-12990)

This commit is contained in:
Joannah Nanjekye 2019-05-04 11:27:10 -04:00 committed by Antoine Pitrou
parent f0900199d5
commit 6b5b013bcc
5 changed files with 42 additions and 0 deletions

View file

@ -1643,6 +1643,25 @@ class _BasePathTest(object):
self.assertFileNotFound(p.stat)
self.assertFileNotFound(p.unlink)
def test_link_to(self):
P = self.cls(BASE)
p = P / 'fileA'
size = p.stat().st_size
# linking to another path.
q = P / 'dirA' / 'fileAA'
try:
p.link_to(q)
except PermissionError as e:
self.skipTest('os.link(): %s' % e)
self.assertEqual(q.stat().st_size, size)
self.assertEqual(os.path.samefile(p, q), True)
self.assertTrue(p.stat)
# Linking to a str of a relative path.
r = rel_join('fileAAA')
q.link_to(r)
self.assertEqual(os.stat(r).st_size, size)
self.assertTrue(q.stat)
def test_rename(self):
P = self.cls(BASE)
p = P / 'fileA'