@@ -177,6 +177,17 @@ def _have_socket_bluetooth():
177177    return  True 
178178
179179
180+ def  _have_socket_bluetooth_l2cap ():
181+     """Check whether BTPROTO_L2CAP sockets are supported on this host.""" 
182+     try :
183+         s  =  socket .socket (socket .AF_BLUETOOTH , socket .SOCK_SEQPACKET , socket .BTPROTO_L2CAP )
184+     except  (AttributeError , OSError ):
185+         return  False 
186+     else :
187+         s .close ()
188+     return  True 
189+ 
190+ 
180191def  _have_socket_hyperv ():
181192    """Check whether AF_HYPERV sockets are supported on this host.""" 
182193    try :
@@ -219,6 +230,8 @@ def socket_setdefaulttimeout(timeout):
219230
220231HAVE_SOCKET_BLUETOOTH  =  _have_socket_bluetooth ()
221232
233+ HAVE_SOCKET_BLUETOOTH_L2CAP  =  _have_socket_bluetooth_l2cap ()
234+ 
222235HAVE_SOCKET_HYPERV  =  _have_socket_hyperv ()
223236
224237# Size in bytes of the int type 
@@ -2592,7 +2605,7 @@ def testCreateRfcommSocket(self):
25922605        with  socket .socket (socket .AF_BLUETOOTH , socket .SOCK_STREAM , socket .BTPROTO_RFCOMM ) as  s :
25932606            pass 
25942607
2595-     @unittest .skipIf ( sys . platform   ==   "win32" ,  "windows does not support L2CAP sockets" ) 
2608+     @unittest .skipUnless ( HAVE_SOCKET_BLUETOOTH_L2CAP ,  'Bluetooth L2CAP sockets required for this test' ) 
25962609    def  testCreateL2capSocket (self ):
25972610        with  socket .socket (socket .AF_BLUETOOTH , socket .SOCK_SEQPACKET , socket .BTPROTO_L2CAP ) as  s :
25982611            pass 
@@ -2608,7 +2621,7 @@ def testCreateScoSocket(self):
26082621        with  socket .socket (socket .AF_BLUETOOTH , socket .SOCK_SEQPACKET , socket .BTPROTO_SCO ) as  s :
26092622            pass 
26102623
2611-     @unittest .skipIf ( sys . platform   !=   "linux" ,  "expecting full  L2CAP support on linux only"  
2624+     @unittest .skipUnless ( HAVE_SOCKET_BLUETOOTH_L2CAP ,  'Bluetooth  L2CAP sockets required for this test'  
26122625    def  testBindLeAttL2capSocket (self ):
26132626        with  socket .socket (socket .AF_BLUETOOTH , socket .SOCK_SEQPACKET , socket .BTPROTO_L2CAP ) as  f :
26142627            # ATT is the only CID allowed in userspace by the Linux kernel 
@@ -2617,7 +2630,7 @@ def testBindLeAttL2capSocket(self):
26172630            addr  =  f .getsockname ()
26182631            self .assertEqual (addr , (socket .BDADDR_ANY , 0 , CID_ATT , socket .BDADDR_LE_PUBLIC ))
26192632
2620-     @unittest .skipIf ( sys . platform   !=   "linux" ,  "expecting full  L2CAP support on linux only"  
2633+     @unittest .skipUnless ( HAVE_SOCKET_BLUETOOTH_L2CAP ,  'Bluetooth  L2CAP sockets required for this test'  
26212634    def  testBindLePsmL2capSocket (self ):
26222635        with  socket .socket (socket .AF_BLUETOOTH , socket .SOCK_SEQPACKET , socket .BTPROTO_L2CAP ) as  f :
26232636            # First user PSM in LE L2CAP 
@@ -2626,7 +2639,7 @@ def testBindLePsmL2capSocket(self):
26262639            addr  =  f .getsockname ()
26272640            self .assertEqual (addr , (socket .BDADDR_ANY , psm , 0 , socket .BDADDR_LE_RANDOM ))
26282641
2629-     @unittest .skipIf ( sys . platform   !=   "linux" ,  "expecting full  L2CAP support on linux only"  
2642+     @unittest .skipUnless ( HAVE_SOCKET_BLUETOOTH_L2CAP ,  'Bluetooth  L2CAP sockets required for this test'  
26302643    def  testBindBrEdrL2capSocket (self ):
26312644        with  socket .socket (socket .AF_BLUETOOTH , socket .SOCK_SEQPACKET , socket .BTPROTO_L2CAP ) as  f :
26322645            # First user PSM in BR/EDR L2CAP 
0 commit comments