@@ -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 ())
0 commit comments