mirror of
https://github.com/python/cpython.git
synced 2025-08-23 18:24:46 +00:00
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:
parent
4d2babd990
commit
cbd7b2a399
4 changed files with 30 additions and 11 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue