Skip to content

Commit 0c8ee60

Browse files
committed
Updates test_winconsoleio to better show the source of its issues.
1 parent c008dde commit 0c8ee60

1 file changed

Lines changed: 27 additions & 15 deletions

File tree

Lib/test/test_winconsoleio.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'''Tests for WindowsConsoleIO
22
'''
33

4-
import os
54
import io
5+
import os
66
import sys
7-
import unittest
87
import tempfile
8+
import unittest
99

1010
if sys.platform != 'win32':
1111
raise unittest.SkipTest("test only relevant on win32")
@@ -26,8 +26,10 @@ def test_open_fd(self):
2626

2727
fd, _ = tempfile.mkstemp()
2828
try:
29+
# Windows 10: "Cannot open non-console file"
30+
# Earlier: "Cannot open console output buffer for reading"
2931
self.assertRaisesRegex(ValueError,
30-
"Cannot open non-console file", ConIO, fd)
32+
"Cannot open (console|non-console file)", ConIO, fd)
3133
finally:
3234
os.close(fd)
3335

@@ -70,18 +72,6 @@ def test_open_fd(self):
7072
def test_open_name(self):
7173
self.assertRaises(ValueError, ConIO, sys.executable)
7274

73-
f = open('C:/con', 'rb', buffering=0)
74-
self.assertIsInstance(f, ConIO)
75-
f.close()
76-
77-
f = open(r'\\.\conin$', 'rb', buffering=0)
78-
self.assertIsInstance(f, ConIO)
79-
f.close()
80-
81-
f = open('//?/conout$', 'wb', buffering=0)
82-
self.assertIsInstance(f, ConIO)
83-
f.close()
84-
8575
f = ConIO("CON")
8676
self.assertTrue(f.readable())
8777
self.assertFalse(f.writable())
@@ -103,6 +93,28 @@ def test_open_name(self):
10393
f.close()
10494
f.close()
10595

96+
f = open('C:/con', 'rb', buffering=0)
97+
self.assertIsInstance(f, ConIO)
98+
f.close()
99+
100+
try:
101+
f = open(r'\\.\conin$', 'rb', buffering=0)
102+
except FileNotFoundError:
103+
# If we cannot find the file, this part should be skipped
104+
print('\\\\.\\conin$ was not found on this OS')
105+
else:
106+
self.assertIsInstance(f, ConIO)
107+
f.close()
108+
109+
try:
110+
f = open('//?/conout$', 'wb', buffering=0)
111+
except FileNotFoundError:
112+
# If we cannot find the file, this part should be skipped
113+
print('//?/conout$ was not found on this OS')
114+
else:
115+
self.assertIsInstance(f, ConIO)
116+
f.close()
117+
106118
def assertStdinRoundTrip(self, text):
107119
stdin = open('CONIN$', 'r')
108120
old_stdin = sys.stdin

0 commit comments

Comments
 (0)