Skip to content

Commit dd07aec

Browse files
committed
Update tests
1 parent 510ef3f commit dd07aec

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

Lib/test/test_pathlib/test_pathlib.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2747,7 +2747,8 @@ def test_is_socket_false(self):
27472747
@unittest.skipIf(
27482748
is_wasi, "Cannot create socket on WASI."
27492749
)
2750-
@unittest.skipIf(sys.platform=='win32', "didn't work on Windows")
2750+
@unittest.skipIf(sys.platform=='win32',
2751+
"detecting if file is socket is not supported by Windows")
27512752
def test_is_socket_true(self):
27522753
P = self.cls(self.base, 'mysock')
27532754
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
@@ -2764,6 +2765,25 @@ def test_is_socket_true(self):
27642765
self.assertIs(self.cls(self.base, 'mysock\udfff').is_socket(), False)
27652766
self.assertIs(self.cls(self.base, 'mysock\x00').is_socket(), False)
27662767

2768+
@unittest.skipUnless(hasattr(socket, "AF_UNIX"), "Unix sockets required")
2769+
@unittest.skipUnless(sys.platform=='win32',
2770+
"socket file on Windows is a normal file")
2771+
def test_is_socket_on_windows(self):
2772+
P = self.cls(self.base, 'mysock')
2773+
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
2774+
self.addCleanup(sock.close)
2775+
try:
2776+
sock.bind(str(P))
2777+
except OSError as e:
2778+
if (isinstance(e, PermissionError) or
2779+
"AF_UNIX path too long" in str(e)):
2780+
self.skipTest("cannot bind Unix socket: " + str(e))
2781+
self.assertFalse(P.is_socket())
2782+
self.assertFalse(P.is_fifo())
2783+
self.assertTrue(P.is_file())
2784+
self.assertIs(self.cls(self.base, 'mysock\udfff').is_socket(), False)
2785+
self.assertIs(self.cls(self.base, 'mysock\x00').is_socket(), False)
2786+
27672787
def test_is_block_device_false(self):
27682788
P = self.cls(self.base)
27692789
self.assertFalse((P / 'fileA').is_block_device())

Lib/test/test_socket.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6194,6 +6194,11 @@ def testUnbound(self):
61946194
# Issue #30205 (note getsockname() can return None on OS X)
61956195
self.assertIn(self.sock.getsockname(), ('', None))
61966196

6197+
@unittest.skipUnless(sys.platform == 'win32',
6198+
'Windows-specific behavior')
6199+
def test_unbound_on_windows(self):
6200+
self.assertRaisesRegex(OSError, 'WinError 10022', self.sock.getsockname)
6201+
61976202
def testStrAddr(self):
61986203
# Test binding to and retrieving a normal string pathname.
61996204
path = os.path.abspath(os_helper.TESTFN)
@@ -6240,6 +6245,12 @@ def testEmptyAddress(self):
62406245
# Test that binding empty address fails.
62416246
self.assertRaises(OSError, self.sock.bind, "")
62426247

6248+
@unittest.skipUnless(sys.platform == 'win32',
6249+
'Windows-specified behavior')
6250+
def test_empty_address_on_windows(self):
6251+
self.sock.bind('')
6252+
self.assertEqual(self.sock.getsockname(), '')
6253+
62436254

62446255
class BufferIOTest(SocketConnectedTest):
62456256
"""

Lib/test/test_stat.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,15 @@ def test_socket(self):
223223
self.assertEqual(modestr[0], 's')
224224
self.assertS_IS("SOCK", st_mode)
225225

226+
@socket_helper.skip_unless_bind_unix_socket
227+
@unittest.skipUnless(sys.platform=='win32', "didn't work on Windows")
228+
def test_socket_on_windows(self):
229+
with socket.socket(socket.AF_UNIX) as s:
230+
s.bind(TESTFN)
231+
st_mode, modestr = self.get_mode()
232+
self.assertNotEqual(modestr[0], 's')
233+
self.assertS_IS("REG", st_mode)
234+
226235
def test_module_attributes(self):
227236
for key, value in self.stat_struct.items():
228237
modvalue = getattr(self.statmod, key)

0 commit comments

Comments
 (0)