summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_winconsoleio.py
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2017-02-04 23:07:46 (GMT)
committerSteve Dower <steve.dower@microsoft.com>2017-02-04 23:07:46 (GMT)
commit722e3e2705e1f7dbbbc2ad58e2957f9fb759ad76 (patch)
tree934a9999e405917ffcb1086b3e590d902a465ae3 /Lib/test/test_winconsoleio.py
parenteacee98679f324fca16852871e76f7be3a685b7c (diff)
downloadcpython-722e3e2705e1f7dbbbc2ad58e2957f9fb759ad76.zip
cpython-722e3e2705e1f7dbbbc2ad58e2957f9fb759ad76.tar.gz
cpython-722e3e2705e1f7dbbbc2ad58e2957f9fb759ad76.tar.bz2
Issue #28164: Correctly handle special console filenames (patch by Eryk Sun)
Diffstat (limited to 'Lib/test/test_winconsoleio.py')
-rw-r--r--Lib/test/test_winconsoleio.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/Lib/test/test_winconsoleio.py b/Lib/test/test_winconsoleio.py
index b1a2f7a..06467e9 100644
--- a/Lib/test/test_winconsoleio.py
+++ b/Lib/test/test_winconsoleio.py
@@ -1,9 +1,11 @@
'''Tests for WindowsConsoleIO
'''
+import os
import io
-import unittest
import sys
+import unittest
+import tempfile
if sys.platform != 'win32':
raise unittest.SkipTest("test only relevant on win32")
@@ -19,6 +21,16 @@ class WindowsConsoleIOTests(unittest.TestCase):
self.assertFalse(issubclass(ConIO, io.TextIOBase))
def test_open_fd(self):
+ self.assertRaisesRegex(ValueError,
+ "negative file descriptor", ConIO, -1)
+
+ fd, _ = tempfile.mkstemp()
+ try:
+ self.assertRaisesRegex(ValueError,
+ "Cannot open non-console file", ConIO, fd)
+ finally:
+ os.close(fd)
+
try:
f = ConIO(0)
except ValueError:
@@ -56,6 +68,20 @@ class WindowsConsoleIOTests(unittest.TestCase):
f.close()
def test_open_name(self):
+ self.assertRaises(ValueError, ConIO, sys.executable)
+
+ f = open('C:/con', 'rb', buffering=0)
+ self.assertIsInstance(f, ConIO)
+ f.close()
+
+ f = open(r'\\.\conin$', 'rb', buffering=0)
+ self.assertIsInstance(f, ConIO)
+ f.close()
+
+ f = open('//?/conout$', 'wb', buffering=0)
+ self.assertIsInstance(f, ConIO)
+ f.close()
+
f = ConIO("CON")
self.assertTrue(f.readable())
self.assertFalse(f.writable())