Decorator for tests requiring a functional bind() for unix sockets.
(test)
| 146 | |
| 147 | _bind_nix_socket_error = None |
| 148 | def skip_unless_bind_unix_socket(test): |
| 149 | """Decorator for tests requiring a functional bind() for unix sockets.""" |
| 150 | if not hasattr(socket, 'AF_UNIX'): |
| 151 | return unittest.skip('No UNIX Sockets')(test) |
| 152 | global _bind_nix_socket_error |
| 153 | if _bind_nix_socket_error is None: |
| 154 | from .os_helper import TESTFN, unlink |
| 155 | path = TESTFN + "can_bind_unix_socket" |
| 156 | with socket.socket(socket.AF_UNIX) as sock: |
| 157 | try: |
| 158 | sock.bind(path) |
| 159 | _bind_nix_socket_error = False |
| 160 | except OSError as e: |
| 161 | _bind_nix_socket_error = e |
| 162 | finally: |
| 163 | unlink(path) |
| 164 | if _bind_nix_socket_error: |
| 165 | msg = 'Requires a functional unix bind(): %s' % _bind_nix_socket_error |
| 166 | return unittest.skip(msg)(test) |
| 167 | else: |
| 168 | return test |
| 169 | |
| 170 | |
| 171 | def get_socket_conn_refused_errs(): |