def redis_proc_fixture(request): """ #. Get configs. #. Run redis process. #. Stop redis process after tests. :param FixtureRequest request: fixture request object :rtype: pytest_dbfixtures.executors.TCPExecutor :returns: tcp executor """ config = get_config(request) redis_exec = executable or config.redis.redis_exec redis_params = params or config.redis.params redis_conf = config_file or request.config.getvalue('redis_conf') redis_host = host or config.redis.host redis_port = get_port(port) or get_port(config.redis.port) pidfile = 'redis-server.{port}.pid'.format(port=redis_port) unixsocket = 'redis.{port}.sock'.format(port=redis_port) dbfilename = 'dump.{port}.rdb'.format(port=redis_port) logsdir = path(request.config.getvalue('logsdir')) logfile_path = logsdir / '{prefix}redis-server.{port}.log'.format( prefix=logs_prefix, port=redis_port ) redis_executor = TCPExecutor( '''{redis_exec} {config} --pidfile {pidfile} --unixsocket {unixsocket} --dbfilename {dbfilename} --logfile {logfile_path} --port {port} --dir {tmpdir} {params}''' .format( redis_exec=redis_exec, params=redis_params, config=redis_conf, pidfile=pidfile, unixsocket=unixsocket, dbfilename=dbfilename, logfile_path=logfile_path, port=redis_port, tmpdir=gettempdir(), ), host=redis_host, port=redis_port, ) redis_version = extract_version( os.popen('{0} --version'.format(redis_exec)).read() ) cv_result = compare_version(redis_version, REQUIRED_VERSION) if redis_version and cv_result < 0: raise RedisUnsupported( 'Your version of Redis is not supported. ' 'Consider updating to Redis {0} at least. ' 'The currently installed version of Redis: {1}.' .format(REQUIRED_VERSION, redis_version)) redis_executor.start() request.addfinalizer(redis_executor.stop) return redis_executor
def redis_proc_fixture(request): """ #. Get configs. #. Run redis process. #. Stop redis process after tests. :param FixtureRequest request: fixture request object :rtype: pytest_dbfixtures.executors.TCPExecutor :returns: tcp executor """ config = get_config(request) redis_exec = executable or config.redis.redis_exec redis_params = params or config.redis.params redis_conf = config_file or request.config.getvalue('redis_conf') redis_host = host or config.redis.host redis_port = get_port(port or config.redis.port) pidfile = 'redis-server.{port}.pid'.format(port=redis_port) unixsocket = 'redis.{port}.sock'.format(port=redis_port) dbfilename = 'dump.{port}.rdb'.format(port=redis_port) logsdir = path(request.config.getvalue('logsdir')) logfile_path = logsdir / '{prefix}redis-server.{port}.log'.format( prefix=logs_prefix, port=redis_port ) redis_executor = TCPExecutor( '''{redis_exec} {config} --pidfile {pidfile} --unixsocket {unixsocket} --dbfilename {dbfilename} --logfile {logfile_path} --port {port} {params}''' .format( redis_exec=redis_exec, params=redis_params, config=redis_conf, pidfile=pidfile, unixsocket=unixsocket, dbfilename=dbfilename, logfile_path=logfile_path, port=redis_port ), host=redis_host, port=redis_port, ) redis_version = extract_version( os.popen('{0} --version'.format(redis_exec)).read() ) cv_result = compare_version(redis_version, REQUIRED_VERSION) if redis_version and cv_result < 0: raise RedisUnsupported( 'Your version of Redis is not supported. ' 'Consider updating to Redis {0} at least. ' 'The currently installed version of Redis: {1}.' .format(REQUIRED_VERSION, redis_version)) redis_executor.start() request.addfinalizer(redis_executor.stop) return redis_executor
def test_extract_version(text, result): assert extract_version(text) == result