Commit 0c8ee60e authored by Steve Dower's avatar Steve Dower

Updates test_winconsoleio to better show the source of its issues.

parent c008ddeb
'''Tests for WindowsConsoleIO '''Tests for WindowsConsoleIO
''' '''
import os
import io import io
import os
import sys import sys
import unittest
import tempfile import tempfile
import unittest
if sys.platform != 'win32': if sys.platform != 'win32':
raise unittest.SkipTest("test only relevant on win32") raise unittest.SkipTest("test only relevant on win32")
...@@ -26,8 +26,10 @@ class WindowsConsoleIOTests(unittest.TestCase): ...@@ -26,8 +26,10 @@ class WindowsConsoleIOTests(unittest.TestCase):
fd, _ = tempfile.mkstemp() fd, _ = tempfile.mkstemp()
try: try:
# Windows 10: "Cannot open non-console file"
# Earlier: "Cannot open console output buffer for reading"
self.assertRaisesRegex(ValueError, self.assertRaisesRegex(ValueError,
"Cannot open non-console file", ConIO, fd) "Cannot open (console|non-console file)", ConIO, fd)
finally: finally:
os.close(fd) os.close(fd)
...@@ -70,18 +72,6 @@ class WindowsConsoleIOTests(unittest.TestCase): ...@@ -70,18 +72,6 @@ class WindowsConsoleIOTests(unittest.TestCase):
def test_open_name(self): def test_open_name(self):
self.assertRaises(ValueError, ConIO, sys.executable) 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") f = ConIO("CON")
self.assertTrue(f.readable()) self.assertTrue(f.readable())
self.assertFalse(f.writable()) self.assertFalse(f.writable())
...@@ -103,6 +93,28 @@ class WindowsConsoleIOTests(unittest.TestCase): ...@@ -103,6 +93,28 @@ class WindowsConsoleIOTests(unittest.TestCase):
f.close() f.close()
f.close() f.close()
f = open('C:/con', 'rb', buffering=0)
self.assertIsInstance(f, ConIO)
f.close()
try:
f = open(r'\\.\conin$', 'rb', buffering=0)
except FileNotFoundError:
# If we cannot find the file, this part should be skipped
print('\\\\.\\conin$ was not found on this OS')
else:
self.assertIsInstance(f, ConIO)
f.close()
try:
f = open('//?/conout$', 'wb', buffering=0)
except FileNotFoundError:
# If we cannot find the file, this part should be skipped
print('//?/conout$ was not found on this OS')
else:
self.assertIsInstance(f, ConIO)
f.close()
def assertStdinRoundTrip(self, text): def assertStdinRoundTrip(self, text):
stdin = open('CONIN$', 'r') stdin = open('CONIN$', 'r')
old_stdin = sys.stdin old_stdin = sys.stdin
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment