|
6 | 6 | import sys
|
7 | 7 | import tempfile
|
8 | 8 | import unittest
|
| 9 | +from test import support |
9 | 10 |
|
10 | 11 | if sys.platform != 'win32':
|
11 | 12 | raise unittest.SkipTest("test only relevant on win32")
|
@@ -97,23 +98,28 @@ def test_open_name(self):
|
97 | 98 | self.assertIsInstance(f, ConIO)
|
98 | 99 | f.close()
|
99 | 100 |
|
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() |
108 | 107 |
|
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) |
117 | 123 |
|
118 | 124 | def assertStdinRoundTrip(self, text):
|
119 | 125 | stdin = open('CONIN$', 'r')
|
|
0 commit comments