bpo-31163: Added return values to pathlib.Path instance's rename and replace methods. (GH-13582) (GH-15944)

* bpo-31163: Added return values to pathlib.Path instance's rename and replace methods.
(cherry picked from commit 088a09af4b)

Co-authored-by: hui shang <shangdahao@gmail.com>
This commit is contained in:
Miss Islington (bot) 2019-09-11 07:12:54 -07:00 committed by Jason R. Coombs
parent 4d2babd990
commit cbd7b2a399
4 changed files with 30 additions and 11 deletions

View file

@ -1680,12 +1680,14 @@ class _BasePathTest(object):
size = p.stat().st_size
# Renaming to another path.
q = P / 'dirA' / 'fileAA'
p.rename(q)
renamed_p = p.rename(q)
self.assertEqual(renamed_p, q)
self.assertEqual(q.stat().st_size, size)
self.assertFileNotFound(p.stat)
# Renaming to a str of a relative path.
r = rel_join('fileAAA')
q.rename(r)
renamed_q = q.rename(r)
self.assertEqual(renamed_q, self.cls(r))
self.assertEqual(os.stat(r).st_size, size)
self.assertFileNotFound(q.stat)
@ -1695,12 +1697,14 @@ class _BasePathTest(object):
size = p.stat().st_size
# Replacing a non-existing path.
q = P / 'dirA' / 'fileAA'
p.replace(q)
replaced_p = p.replace(q)
self.assertEqual(replaced_p, q)
self.assertEqual(q.stat().st_size, size)
self.assertFileNotFound(p.stat)
# Replacing another (existing) path.
r = rel_join('dirB', 'fileB')
q.replace(r)
replaced_q = q.replace(r)
self.assertEqual(replaced_q, self.cls(r))
self.assertEqual(os.stat(r).st_size, size)
self.assertFileNotFound(q.stat)