Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2dfa6cb

Browse files
committed
Issue python#28164: Improves test on Windows 7
1 parent f007b49 commit 2dfa6cb

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

Lib/test/test_winconsoleio.py

+22-16
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import sys
77
import tempfile
88
import unittest
9+
from test import support
910

1011
if sys.platform != 'win32':
1112
raise unittest.SkipTest("test only relevant on win32")
@@ -97,23 +98,28 @@ def test_open_name(self):
9798
self.assertIsInstance(f, ConIO)
9899
f.close()
99100

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()
101+
@unittest.skipIf(sys.getwindowsversion()[:2] <= (6, 1),
102+
"test does not work on Windows 7 and earlier")
103+
def test_conin_conout_names(self):
104+
f = open(r'\\.\conin$', 'rb', buffering=0)
105+
self.assertIsInstance(f, ConIO)
106+
f.close()
108107

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()
108+
f = open('//?/conout$', 'wb', buffering=0)
109+
self.assertIsInstance(f, ConIO)
110+
f.close()
111+
112+
def test_conout_path(self):
113+
temp_path = tempfile.mkdtemp()
114+
self.addCleanup(support.rmtree, temp_path)
115+
116+
conout_path = os.path.join(temp_path, 'CONOUT$')
117+
118+
with open(conout_path, 'wb', buffering=0) as f:
119+
if sys.getwindowsversion()[:2] > (6, 1):
120+
self.assertIsInstance(f, ConIO)
121+
else:
122+
self.assertNotIsInstance(f, ConIO)
117123

118124
def assertStdinRoundTrip(self, text):
119125
stdin = open('CONIN$', 'r')

0 commit comments

Comments
 (0)