summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_io.py
diff options
context:
space:
mode:
authorCharles-François Natali <neologix@free.fr>2012-01-09 21:40:02 (GMT)
committerCharles-François Natali <neologix@free.fr>2012-01-09 21:40:02 (GMT)
commitdc3044c7043b687f3be97a731d873dc991f5d83b (patch)
treeeb7ae132b0c152c6ad9dcfe3ae63b80cd2acdb4a /Lib/test/test_io.py
parent8a9b9c7d165c55ef368a5d0be539e17ad3f201d4 (diff)
downloadcpython-dc3044c7043b687f3be97a731d873dc991f5d83b.zip
cpython-dc3044c7043b687f3be97a731d873dc991f5d83b.tar.gz
cpython-dc3044c7043b687f3be97a731d873dc991f5d83b.tar.bz2
Issue #12760: Add a create mode to open(). Patch by David Townshend.
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r--Lib/test/test_io.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 5954999..bea9395 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -2825,6 +2825,19 @@ class MiscIOTest(unittest.TestCase):
self.assertTrue(wf.closed)
self.assertTrue(rf.closed)
+ def test_create_fail(self):
+ # 'x' mode fails if file is existing
+ with self.open(support.TESTFN, 'w'):
+ pass
+ self.assertRaises(FileExistsError, self.open, support.TESTFN, 'x')
+
+ def test_create_writes(self):
+ # 'x' mode opens for writing
+ with self.open(support.TESTFN, 'xb') as f:
+ f.write(b"spam")
+ with self.open(support.TESTFN, 'rb') as f:
+ self.assertEqual(b"spam", f.read())
+
class CMiscIOTest(MiscIOTest):
io = io