def test_create_connection_with_source_address_calls_bind(self): sock = mock.Mock() with mock.patch('socket.socket') as fake_socket: fake_socket.return_value = sock sock.getsockopt.return_value = 0 sock.connect_ex.return_value = 0 sock.gettimeout.return_value = None try: rfc6555.create_connection(('::1', 0), source_address=('::1', 123)) except Exception: pass sock.bind.assert_called_with(('::1', 123))
def open_socket(self): """open_socket() Open socket choosing first address family available.""" if self.af == socket.AF_UNSPEC: # happy-eyeballs! return rfc6555.create_connection((self.host, self.port)) else: return self._open_socket_for_af(self.af)
def test_create_connection_google(self): sock = rfc6555.create_connection(('www.google.com', 80))
def test_create_connection_cached_value(self): sock = rfc6555.create_connection(('www.google.com', 80)) sock2 = rfc6555.create_connection(('www.google.com', 80))
def test_getaddr_info_empty_list(self): with mock.patch('socket.getaddrinfo') as fake_getaddrinfo: fake_getaddrinfo.return_value = [] with pytest.raises(socket.error): rfc6555.create_connection(('::1', 0))
def test_create_connection_has_proper_timeout(self, timeout): sock = rfc6555.create_connection(('www.google.com', 80), timeout=timeout) assert sock.gettimeout() == timeout