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

* bpo-31163: Added return values to pathlib.Path instance's rename and replace methods.
This commit is contained in:
hui shang 2019-09-11 21:26:49 +08:00 committed by Jason R. Coombs
parent f9b5840fb4
commit 088a09af4b
4 changed files with 30 additions and 11 deletions

View file

@ -1767,12 +1767,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)
@ -1782,12 +1784,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)