def test_raise_exception(self): with pytest.raises(Exception): accepts_argument(None, 'foo') if not PY3: with pytest.raises(Exception): accepts_argument(test_accepts_arg, 'foo')
def _connparams(self, asynchronous=False): conninfo = self.connection.client connparams = { "host": conninfo.hostname or "127.0.0.1", "port": conninfo.port or self.connection.default_port, "virtual_host": conninfo.virtual_host, "password": conninfo.password, "max_connections": self.max_connections, "socket_timeout": self.socket_timeout, "socket_connect_timeout": self.socket_connect_timeout, "socket_keepalive": self.socket_keepalive, "socket_keepalive_options": self.socket_keepalive_options, "health_check_interval": self.health_check_interval, "retry_on_timeout": self.retry_on_timeout, } conn_class = self.connection_class # If the connection class does not support the `health_check_interval` # argument then remove it. if hasattr(conn_class, "__init__") and not accepts_argument( conn_class.__init__, "health_check_interval"): connparams.pop("health_check_interval") if conninfo.ssl: # Connection(ssl={}) must be a dict containing the keys: # 'ssl_cert_reqs', 'ssl_ca_certs', 'ssl_certfile', 'ssl_keyfile' try: connparams.update(conninfo.ssl) connparams["connection_class"] = redis.SSLConnection except TypeError: pass host = connparams["host"] if "://" in host: scheme, _, _, _, password, path, query = _parse_url(host) if scheme == "socket": connparams = self._filter_tcp_connparams(**connparams) connparams.update( { "connection_class": redis.UnixDomainSocketConnection, "path": "/" + path, }, **query) connparams.pop("socket_connect_timeout", None) connparams.pop("socket_keepalive", None) connparams.pop("socket_keepalive_options", None) connparams["password"] = password connparams.pop("host", None) connparams.pop("port", None) connparams["db"] = self._prepare_virtual_host( connparams.pop("virtual_host", None)) channel = self connection_cls = connparams.get( "connection_class") or self.connection_class if asynchronous: class Connection(connection_cls): def disconnect(self): super(Connection, self).disconnect() channel._on_connection_disconnect(self) connection_cls = Connection connparams["connection_class"] = connection_cls return connparams
def test_invalid_argument(self): assert not accepts_argument(self.function, 'random_argument')
def test_valid_argument(self): assert accepts_argument(self.function, 'self') assert accepts_argument(self.function, 'foo') assert accepts_argument(self.function, 'baz')
def _connparams(self, asynchronous=False): conninfo = self.connection.client connparams = { 'host': conninfo.hostname or '127.0.0.1', 'port': conninfo.port or self.connection.default_port, 'virtual_host': conninfo.virtual_host, 'password': conninfo.password, 'max_connections': self.max_connections, 'socket_timeout': self.socket_timeout, 'socket_connect_timeout': self.socket_connect_timeout, 'socket_keepalive': self.socket_keepalive, 'socket_keepalive_options': self.socket_keepalive_options, 'health_check_interval': self.health_check_interval, 'retry_on_timeout': self.retry_on_timeout, } conn_class = self.connection_class # If the connection class does not support the `health_check_interval` # argument then remove it. if ( hasattr(conn_class, '__init__') and not accepts_argument(conn_class.__init__, 'health_check_interval') ): connparams.pop('health_check_interval') if conninfo.ssl: # Connection(ssl={}) must be a dict containing the keys: # 'ssl_cert_reqs', 'ssl_ca_certs', 'ssl_certfile', 'ssl_keyfile' try: connparams.update(conninfo.ssl) connparams['connection_class'] = redis.SSLConnection except TypeError: pass host = connparams['host'] if '://' in host: scheme, _, _, _, password, path, query = _parse_url(host) if scheme == 'socket': connparams = self._filter_tcp_connparams(**connparams) connparams.update({ 'connection_class': redis.UnixDomainSocketConnection, 'path': '/' + path}, **query) connparams.pop('socket_connect_timeout', None) connparams.pop('socket_keepalive', None) connparams.pop('socket_keepalive_options', None) connparams['password'] = password connparams.pop('host', None) connparams.pop('port', None) connparams['db'] = self._prepare_virtual_host( connparams.pop('virtual_host', None)) channel = self connection_cls = ( connparams.get('connection_class') or self.connection_class ) if asynchronous: class Connection(connection_cls): def disconnect(self): super().disconnect() channel._on_connection_disconnect(self) connection_cls = Connection connparams['connection_class'] = connection_cls return connparams
def test_invalid_argument(self): assert not accepts_argument(self.function, 'random_argument') if PY3: assert not accepts_argument(test_accepts_arg, 'foo')