mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
Issue #8828: Add new function os.replace(), for cross-platform renaming with overwriting.
This commit is contained in:
parent
8a8945085f
commit
f3b2d88b67
4 changed files with 65 additions and 15 deletions
|
@ -129,6 +129,18 @@ class FileTests(unittest.TestCase):
|
|||
self.fdopen_helper('r')
|
||||
self.fdopen_helper('r', 100)
|
||||
|
||||
def test_replace(self):
|
||||
TESTFN2 = support.TESTFN + ".2"
|
||||
with open(support.TESTFN, 'w') as f:
|
||||
f.write("1")
|
||||
with open(TESTFN2, 'w') as f:
|
||||
f.write("2")
|
||||
self.addCleanup(os.unlink, TESTFN2)
|
||||
os.replace(support.TESTFN, TESTFN2)
|
||||
self.assertRaises(FileNotFoundError, os.stat, support.TESTFN)
|
||||
with open(TESTFN2, 'r') as f:
|
||||
self.assertEqual(f.read(), "1")
|
||||
|
||||
|
||||
# Test attributes on return values from os.*stat* family.
|
||||
class StatAttributeTests(unittest.TestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue