From cd1500a24a1b46ce85c6d38e3142d82dad90c635 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 9 Feb 2025 17:22:03 +0100 Subject: [PATCH] Merging upstream version 1.14.0. Signed-off-by: Daniel Baumann --- .bumpversion.cfg | 2 +- .dockerignore | 7 ++++ .github/workflows/test.yaml | 3 +- CHANGELOG.md | 27 +++++++++---- Dockerfile | 28 ++++++------- README.md | 2 +- iredis/__init__.py | 2 +- iredis/client.py | 1 + iredis/config.py | 3 ++ iredis/data/iredisrc | 4 ++ iredis/entry.py | 22 ++++++++--- poetry.lock | 57 +++++++++++---------------- pyproject.toml | 13 +++--- tests/cli_tests/test_cli_start.py | 8 ++-- tests/cli_tests/test_command_input.py | 8 ++-- tests/cli_tests/test_completer.py | 3 +- tests/cli_tests/test_pager.py | 19 ++++----- tests/conftest.py | 4 +- tests/unittests/test_client.py | 53 ++++++++++++++----------- 19 files changed, 152 insertions(+), 114 deletions(-) create mode 100644 .dockerignore diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 0baaf8e..9ef25fa 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.13.2 +current_version = 1.14.0 commit = True tag = True diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..51a2276 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +tests +scripts +CHANGELOG.md +Dockerfile +docs +pyoxidizer.template.bzl +redis-doc diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 01a9dfd..9516dd9 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,10 +10,11 @@ jobs: test: name: Pytest strategy: + fail-fast: false matrix: os: ["ubuntu-20.04"] python: ["3.7", "3.8", "3.9", "3.10", "3.11.1"] - redis: [5, 6, 7] + redis: [5, 6, 7, 7.2] runs-on: ${{ matrix.os }} services: diff --git a/CHANGELOG.md b/CHANGELOG.md index b6f62c9..c98e9f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,23 +1,32 @@ ## UPCOMING -## 1.3.1 +## 1.14 + +- Dependency: upgrade redis-py to 5 (thanks to [chayim]) +- Feature: porting to redis-server 7.2 now +- Feature: supports python 3.10, 3.11 now +- Doc: update commands.json from redis-doc to latest version + +## 1.13.2 - Dependency: upgrade markdown render mistune to v3 -- Dependency: deprecated importlib_resources, use Python build in `importlib.resources` now +- Dependency: deprecated importlib_resources, use Python build in + `importlib.resources` now - Dependency: upgrade redis-py to 4.5 - Doc: update homepage link to iredis.xbin.io - Bugfix: Fix restore command caused by string literal escape -## 1.3 +## 1.13 - Dependency: Drop Python 3.6 support. - Bugfix: fix some typos. ### 1.12.2 -- Feature: IRedis now honors the `ssl_cert_reqs` strategy, either specifying it via - command line (`--verify-ssl=`) or as an url parameter (`ssl_cert_reqs`) - when the connection is secured via tls (`rediss://`). (authored by [torrefatto]) +- Feature: IRedis now honors the `ssl_cert_reqs` strategy, either specifying it + via command line (`--verify-ssl=`) or as an url + parameter (`ssl_cert_reqs`) when the connection is secured via tls + (`rediss://`). (authored by [torrefatto]) ### 1.12.1 @@ -25,7 +34,8 @@ - Bugfix: all tests pass on redis:7 now. - Feature: IRedis now accept `username` for auth, redis server version under 6 will ignore `username`. -- Feature: IRedis support prompt now, you can customize prompt string. (thanks to [aymericbeaumet]) +- Feature: IRedis support prompt now, you can customize prompt string. (thanks + to [aymericbeaumet]) ## 1.12 @@ -278,7 +288,7 @@ ### 0.8.12 -- Bugfix: Multi spaces between commands can be recongnised as correct commands +- Bugfix: Multi spaces between commands can be recognised as correct commands now. - Feature: Warning on dangerous command. @@ -316,3 +326,4 @@ [tssujt]: https://github.com/tssujt [aymericbeaumet]: https://github.com/aymericbeaumet [torrefatto]: https://github.com/torrefatto +[chayim]: https://github.com/chayim diff --git a/Dockerfile b/Dockerfile index 99c0463..a0baf16 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,16 @@ -FROM python:3 +FROM redis/redis-stack-server:latest +COPY . /iredis + +RUN apt-get update --fix-missing +RUN apt-get install -yqq python3 python3-pip python-is-python3 +RUN python3 -m pip install poetry WORKDIR /iredis -COPY README.md poetry.lock pyproject.toml ./ -COPY iredis ./iredis +RUN poetry config virtualenvs.create false +RUN poetry build +RUN pip install dist/iredis*.tar.gz +WORKDIR / +RUN rm -rf .cache /var/cache/apt +RUN rm -rf /iredis -RUN apt-get update && apt-get install -y --allow-unauthenticated \ - redis-server && \ - rm -rf /var/lib/apt/lists/* - - -RUN python3 -m venv iredis_env && \ - . iredis_env/bin/activate && \ - pip install poetry && \ - poetry install --no-dev && \ - rm -rf ~/.cache - -CMD ["sh","-c","redis-server --daemonize yes && . iredis_env/bin/activate && iredis"] +CMD ["sh", "-c", "/opt/redis-stack/bin/redis-stack-server --daemonize yes && iredis"] diff --git a/README.md b/README.md index 329ca42..41927fc 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@

Github Action PyPI version -Python version +Python version Download stats

diff --git a/iredis/__init__.py b/iredis/__init__.py index 8d7257c..b9f68ed 100644 --- a/iredis/__init__.py +++ b/iredis/__init__.py @@ -1 +1 @@ -__version__ = "1.13.2" +__version__ = "1.14.0" diff --git a/iredis/client.py b/iredis/client.py index 198d209..f7164b8 100644 --- a/iredis/client.py +++ b/iredis/client.py @@ -95,6 +95,7 @@ class Client: try: self.connection.connect() except Exception as e: + logger.exception("Can not create connection to server") print(str(e), file=sys.stderr) sys.exit(1) if not config.no_info: diff --git a/iredis/config.py b/iredis/config.py index ff31d4e..4041bb6 100644 --- a/iredis/config.py +++ b/iredis/config.py @@ -63,6 +63,8 @@ class Config: self.withscores = False self.version = "Unknown" + self.greetings = True + self.prompt = None def __setter__(self, name, value): @@ -129,5 +131,6 @@ def load_config_files(iredisrc): config.pager = config_obj["main"].get("pager") config.enable_pager = config_obj["main"].as_bool("enable_pager") config.prompt = config_obj["main"].get("prompt") + config.greetings = config_obj["main"].as_bool("greetings") return config_obj diff --git a/iredis/data/iredisrc b/iredis/data/iredisrc index 6db02a7..978aa4b 100644 --- a/iredis/data/iredisrc +++ b/iredis/data/iredisrc @@ -76,6 +76,10 @@ prompt = # History file location history_location = ~/.iredis_history +# if set to True, will display version information on startup +# can set to False to disable it. +greetings = True + [alias_dsn] # example_dsn = redis://[[username]:[password]]@localhost:6379/0 # example_dsn = rediss://[[username]:[password]]@localhost:6379/0 diff --git a/iredis/entry.py b/iredis/entry.py index c7ae76c..0799a07 100644 --- a/iredis/entry.py +++ b/iredis/entry.py @@ -61,8 +61,8 @@ def greetings(): reason = "" server_version = f"redis-server {config.version} {reason}" - home_page = "Home: https://iredis.io" - issues = "Issues: https://iredis.io/issues" + home_page = "Home: https://iredis.xbin.io/" + issues = "Issues: https://github.com/laixintao/iredis/issues" display = "\n".join([iredis_version, server_version, home_page, issues]) if config.raw: display = display.encode() @@ -177,9 +177,9 @@ def repl(client, session, start_time): try: command = session.prompt( prompt_message(client), - bottom_toolbar=BottomToolbar(command_holder).render - if config.bottom_bar - else None, + bottom_toolbar=( + BottomToolbar(command_holder).render if config.bottom_bar else None + ), input_processors=[ UpdateBottomProcessor(command_holder, session), PasswordProcessor(), @@ -274,6 +274,12 @@ VERIFY_SSL_HELP = """Set the TLS certificate verification strategy""" @click.option("--rainbow/--no-rainbow", default=None, is_flag=True, help=RAINBOW) @click.option("--shell/--no-shell", default=None, is_flag=True, help=SHELL) @click.option("--pager/--no-pager", default=None, is_flag=True, help=PAGER_HELP) +@click.option( + "--greetings/--no-greetings", + default=None, + is_flag=True, + help="Enable or disable greeting messages", +) @click.option( "--verify-ssl", default=None, @@ -309,6 +315,7 @@ def gather_args( socket, shell, pager, + greetings, verify_ssl, prompt, ): @@ -354,6 +361,8 @@ def gather_args( config.enable_pager = pager if verify_ssl is not None: config.verify_ssl = verify_ssl + if greetings is not None: + config.greetings = greetings return ctx @@ -492,5 +501,6 @@ def main(): ) # print hello message - greetings() + if config.greetings: + greetings() repl(client, session, enter_main_time) diff --git a/poetry.lock b/poetry.lock index adf8451..752359a 100644 --- a/poetry.lock +++ b/poetry.lock @@ -16,15 +16,19 @@ typing-extensions = {version = ">=3.6.5", markers = "python_version < \"3.8\""} [[package]] name = "click" -version = "7.1.2" +version = "8.1.7" description = "Composable command line interface toolkit" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +python-versions = ">=3.7" files = [ - {file = "click-7.1.2-py2.py3-none-any.whl", hash = "sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc"}, - {file = "click-7.1.2.tar.gz", hash = "sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a"}, + {file = "click-8.1.7-py3-none-any.whl", hash = "sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28"}, + {file = "click-8.1.7.tar.gz", hash = "sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de"}, ] +[package.dependencies] +colorama = {version = "*", markers = "platform_system == \"Windows\""} +importlib-metadata = {version = "*", markers = "python_version < \"3.8\""} + [[package]] name = "colorama" version = "0.4.6" @@ -97,29 +101,26 @@ files = [ [[package]] name = "mistune" -version = "3.0.1" +version = "3.0.2" description = "A sane and fast Markdown parser with useful plugins and renderers" optional = false python-versions = ">=3.7" files = [ - {file = "mistune-3.0.1-py3-none-any.whl", hash = "sha256:b9b3e438efbb57c62b5beb5e134dab664800bdf1284a7ee09e8b12b13eb1aac6"}, - {file = "mistune-3.0.1.tar.gz", hash = "sha256:e912116c13aa0944f9dc530db38eb88f6a77087ab128f49f84a48f4c05ea163c"}, + {file = "mistune-3.0.2-py3-none-any.whl", hash = "sha256:71481854c30fdbc938963d3605b72501f5c10a9320ecd412c121c163a1c7d205"}, + {file = "mistune-3.0.2.tar.gz", hash = "sha256:fc7f93ded930c92394ef2cb6f04a8aabab4117a91449e72dcc8dfa646a508be8"}, ] [[package]] name = "packaging" -version = "21.3" +version = "23.2" description = "Core utilities for Python packages" optional = false -python-versions = ">=3.6" +python-versions = ">=3.7" files = [ - {file = "packaging-21.3-py3-none-any.whl", hash = "sha256:ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522"}, - {file = "packaging-21.3.tar.gz", hash = "sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb"}, + {file = "packaging-23.2-py3-none-any.whl", hash = "sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7"}, + {file = "packaging-23.2.tar.gz", hash = "sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5"}, ] -[package.dependencies] -pyparsing = ">=2.0.2,<3.0.5 || >3.0.5" - [[package]] name = "pendulum" version = "2.1.2" @@ -225,29 +226,15 @@ files = [ [package.extras] plugins = ["importlib-metadata"] -[[package]] -name = "pyparsing" -version = "3.1.1" -description = "pyparsing module - Classes and methods to define and execute parsing grammars" -optional = false -python-versions = ">=3.6.8" -files = [ - {file = "pyparsing-3.1.1-py3-none-any.whl", hash = "sha256:32c7c0b711493c72ff18a981d24f28aaf9c1fb7ed5e9667c9e84e3db623bdbfb"}, - {file = "pyparsing-3.1.1.tar.gz", hash = "sha256:ede28a1a32462f5a9705e07aea48001a08f7cf81a021585011deba701581a0db"}, -] - -[package.extras] -diagrams = ["jinja2", "railroad-diagrams"] - [[package]] name = "pytest" -version = "7.4.2" +version = "7.4.3" description = "pytest: simple powerful testing with Python" optional = false python-versions = ">=3.7" files = [ - {file = "pytest-7.4.2-py3-none-any.whl", hash = "sha256:1d881c6124e08ff0a1bb75ba3ec0bfd8b5354a01c194ddd5a0a870a48d99b002"}, - {file = "pytest-7.4.2.tar.gz", hash = "sha256:a766259cfab564a2ad52cb1aae1b881a75c3eb7e34ca3779697c23ed47c47069"}, + {file = "pytest-7.4.3-py3-none-any.whl", hash = "sha256:0d009c083ea859a71b76adf7c1d502e4bc170b80a8ef002da5806527b9591fac"}, + {file = "pytest-7.4.3.tar.gz", hash = "sha256:d989d136982de4e3b29dabcc838ad581c64e8ed52c11fbe86ddebd9da0818cd5"}, ] [package.dependencies] @@ -289,13 +276,13 @@ files = [ [[package]] name = "redis" -version = "4.6.0" +version = "5.0.1" description = "Python client for Redis database and key-value store" optional = false python-versions = ">=3.7" files = [ - {file = "redis-4.6.0-py3-none-any.whl", hash = "sha256:e2b03db868160ee4591de3cb90d40ebb50a90dd302138775937f6a42b7ed183c"}, - {file = "redis-4.6.0.tar.gz", hash = "sha256:585dc516b9eb042a619ef0a39c3d7d55fe81bdb4df09a52c9cdde0d07bf1aa7d"}, + {file = "redis-5.0.1-py3-none-any.whl", hash = "sha256:ed4802971884ae19d640775ba3b03aa2e7bd5e8fb8dfaed2decce4d0fc48391f"}, + {file = "redis-5.0.1.tar.gz", hash = "sha256:0dab495cd5753069d3bc650a0dde8a8f9edde16fc5691b689a566eda58100d0f"}, ] [package.dependencies] @@ -369,4 +356,4 @@ testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more [metadata] lock-version = "2.0" python-versions = "^3.7" -content-hash = "e772d54a2ce1e2f5acbc47a2316420dc652a4c745db08d44fd364222bbeae7ae" +content-hash = "33eaaf0e62340be5fa5c74233fd0760e61c9635cbad8f38d625f3c253fb9df4c" diff --git a/pyproject.toml b/pyproject.toml index 0f2854a..088fb45 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "iredis" -version = "1.13.2" +version = "1.14.0" description = "Terminal client for Redis with auto-completion and syntax highlighting." authors = ["laixintao "] readme = 'README.md' @@ -19,6 +19,8 @@ classifiers = [ "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + # "Programming Language :: Python :: 3.12", "Topic :: Database", "License :: OSI Approved :: MIT License", "Intended Audience :: Developers", @@ -26,7 +28,6 @@ classifiers = [ packages = [ { include = "iredis" }, - { include = "tests", format = "sdist" }, ] [tool.poetry.dependencies] @@ -35,12 +36,12 @@ prompt_toolkit = "^3" Pygments = "^2" mistune = "^3.0" configobj = "^5.0" -click = "^7.0" -pendulum = "^2.0" +click = "^8.0" +pendulum = "^2.1.0" # wcwidth 0.2.x uses pkg_resources which is not supported by PyOxidizer wcwidth = "0.1.9" -packaging = "^21.3" -redis = "^4.5.3" +packaging = "^23.0" +redis = "^5.0.0" [tool.poetry.dev-dependencies] pytest = "^7.2" diff --git a/tests/cli_tests/test_cli_start.py b/tests/cli_tests/test_cli_start.py index 8045947..819b24f 100644 --- a/tests/cli_tests/test_cli_start.py +++ b/tests/cli_tests/test_cli_start.py @@ -1,6 +1,8 @@ +from textwrap import dedent + +from packaging.version import parse as version_parse # noqa: F401 import pexpect import pytest -from textwrap import dedent def test_start_on_connection_error(): @@ -29,14 +31,14 @@ def test_short_help_option(config): c.close() -@pytest.mark.skipif("int(os.environ['REDIS_VERSION']) != 5") +@pytest.mark.skipif("version_parse(os.environ['REDIS_VERSION']) != version_parse('5')") def test_server_version_in_starting_on5(): c = pexpect.spawn("iredis", timeout=2) c.expect("redis-server 5") c.close() -@pytest.mark.skipif("int(os.environ['REDIS_VERSION']) != 6") +@pytest.mark.skipif("version_parse(os.environ['REDIS_VERSION']) != version_parse('6')") def test_server_version_in_starting_on6(): c = pexpect.spawn("iredis", timeout=2) c.expect("redis-server 6") diff --git a/tests/cli_tests/test_command_input.py b/tests/cli_tests/test_command_input.py index 75917cb..f0aab4a 100644 --- a/tests/cli_tests/test_command_input.py +++ b/tests/cli_tests/test_command_input.py @@ -1,4 +1,6 @@ import os + +from packaging.version import parse as version_parse import pytest @@ -9,7 +11,7 @@ def test_wrong_select_db_index(cli): cli.sendline("select 128") cli.expect(["DB index is out of range", "127.0.0.1:6379[1]>"]) - if int(os.environ["REDIS_VERSION"]) > 5: + if version_parse(os.environ["REDIS_VERSION"]) > version_parse("5"): text = "value is not an integer or out of range" else: text = "invalid DB index" @@ -42,14 +44,14 @@ def test_enter_key_binding(clean_redis, cli): cli.expect(r"hello") -@pytest.mark.skipif("int(os.environ['REDIS_VERSION']) < 6") +@pytest.mark.skipif("version_parse(os.environ['REDIS_VERSION']) < version_parse('6')") def test_auth_hidden_password_with_username(clean_redis, cli): cli.send("auth default hello-world") cli.expect("default") cli.expect(r"\*{11}") -@pytest.mark.skipif("int(os.environ['REDIS_VERSION']) > 5") +@pytest.mark.skipif("version_parse(os.environ['REDIS_VERSION']) > version_parse('5')") def test_auth_hidden_password(clean_redis, cli): cli.send("auth hello-world") cli.expect("auth") diff --git a/tests/cli_tests/test_completer.py b/tests/cli_tests/test_completer.py index 4ffd058..adf8040 100644 --- a/tests/cli_tests/test_completer.py +++ b/tests/cli_tests/test_completer.py @@ -1,3 +1,4 @@ +from packaging.version import parse as version_parse # noqa: F401 import pytest @@ -37,7 +38,7 @@ def test_command_completion_when_space_command(cli, clean_redis): cli.expect("command info") -@pytest.mark.skipif("int(os.environ['REDIS_VERSION']) < 6") +@pytest.mark.skipif("version_parse(os.environ['REDIS_VERSION']) < version_parse('6')") def test_username_completer(cli, iredis_client): iredis_client.execute("acl setuser", "foo1") iredis_client.execute("acl setuser", "bar2") diff --git a/tests/cli_tests/test_pager.py b/tests/cli_tests/test_pager.py index 5a285a8..c3f9fb0 100644 --- a/tests/cli_tests/test_pager.py +++ b/tests/cli_tests/test_pager.py @@ -1,10 +1,12 @@ # noqa: F541 -import os -import sys -import pexpect -import pathlib from contextlib import contextmanager +import os +import pathlib +import sys from textwrap import dedent +from packaging.version import parse as version_parse + +import pexpect TEST_IREDISRC = "/tmp/.iredisrc.test" @@ -22,6 +24,10 @@ env_pager_numbers = "{0} {1} {2}".format( TEST_PAGER_BOUNDARY_NUMBER, ) +long_list_type = "quicklist" +if version_parse(os.environ["REDIS_VERSION"]) >= version_parse("7"): + long_list_type = "listpack" + @contextmanager def pager_enabled_cli(): @@ -54,11 +60,6 @@ def test_using_pager_works_for_help(): child.expect(TEST_PAGER_BOUNDARY) -long_list_type = "quicklist" -if os.environ["REDIS_VERSION"] == "7": - long_list_type = "listpack" - - def test_pager_works_for_peek(clean_redis): for index in range(100): clean_redis.lpush("long-list", f"value-{index}") diff --git a/tests/conftest.py b/tests/conftest.py index b70bf95..593e8a8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -105,7 +105,7 @@ def cli(): child = pexpect.spawn(f"iredis -n 15 --iredisrc {f.name}", timeout=TIMEOUT, env=env) child.logfile_read = open("cli_test.log", "ab") - child.expect(["https://iredis.io/issues", "127.0.0.1"]) + child.expect(["https://github.com/laixintao/iredis/issues", "127.0.0.1"]) yield child child.close() @@ -129,7 +129,7 @@ def raw_cli(): f"iredis --raw -n 15 --iredisrc {TEST_IREDISRC}", timeout=TIMEOUT ) child.logfile_read = open("cli_test.log", "ab") - child.expect(["https://iredis.io/issues", "127.0.0.1"]) + child.expect(["https://github.com/laixintao/iredis/issues", "127.0.0.1"]) yield child child.close() diff --git a/tests/unittests/test_client.py b/tests/unittests/test_client.py index 77a48de..c0f4c07 100644 --- a/tests/unittests/test_client.py +++ b/tests/unittests/test_client.py @@ -1,18 +1,20 @@ import os import re +from textwrap import dedent +from unittest.mock import MagicMock, patch + +from packaging.version import parse as version_parse +from prompt_toolkit.formatted_text import FormattedText import pytest import redis -from unittest.mock import MagicMock, patch -from textwrap import dedent - -from prompt_toolkit.formatted_text import FormattedText from iredis.client import Client -from iredis.config import config, load_config_files +from iredis.commands import command2syntax from iredis.completers import IRedisCompleter +from iredis.config import config, load_config_files from iredis.entry import Rainbow, prompt_message from iredis.exceptions import NotSupport -from iredis.commands import command2syntax + from ..helpers import formatted_text_rematch @@ -24,7 +26,7 @@ def completer(): zset_type = "ziplist" hash_type = "hashtable" list_type = "quicklist" -if os.environ["REDIS_VERSION"] == "7": +if version_parse(os.environ["REDIS_VERSION"]) >= version_parse("7"): zset_type = "listpack" hash_type = "listpack" list_type = "listpack" @@ -40,7 +42,7 @@ if os.environ["REDIS_VERSION"] == "7": ], ) def test_send_command(_input, command_name, expect_args): - client = Client("127.0.0.1", "6379", None) + client = Client("127.0.0.1", 6379, None) client.execute = MagicMock() next(client.send_command(_input, None)) args, _ = client.execute.call_args @@ -180,7 +182,7 @@ def test_not_retry_on_authentication_error(iredis_client, config): @pytest.mark.skipif( - "int(os.environ['REDIS_VERSION']) != 6", + "version_parse(os.environ['REDIS_VERSION']) != version_parse('6')", reason=""" in redis7, it will not work if you: 1. connect redis without password @@ -213,7 +215,7 @@ def test_auto_select_db_and_auth_for_reconnect_only_6(iredis_client, config): ) -@pytest.mark.skipif("int(os.environ['REDIS_VERSION']) > 5") +@pytest.mark.skipif("version_parse(os.environ['REDIS_VERSION']) > version_parse('5')") def test_auto_select_db_and_auth_for_reconnect_only_5(iredis_client, config): config.retry_times = 2 config.raw = True @@ -554,23 +556,29 @@ def test_version_parse_for_auth(iredis_client): "info, version", [ ( - "# Server\r\nredis_version:df--128-NOTFOUND\r\n" - "redis_mode:standalone\r\narch_bits:64", + ( + "# Server\r\nredis_version:df--128-NOTFOUND\r\n" + "redis_mode:standalone\r\narch_bits:64" + ), "df--128-NOTFOUND", ), ( - "# Server\r\nredis_version:6.2.5\r\n" - "redis_git_sha1:00000000\r\n" - "redis_git_dirty:0\r\n" - "redis_build_id:915e5480613bc9b6\r\n" - "redis_mode:standalone ", + ( + "# Server\r\nredis_version:6.2.5\r\n" + "redis_git_sha1:00000000\r\n" + "redis_git_dirty:0\r\n" + "redis_build_id:915e5480613bc9b6\r\n" + "redis_mode:standalone " + ), "6.2.5", ), ( - "# Server\r\nredis_version:5.0.14.1\r\n" - "redis_git_sha1:00000000\r\nredis_git_dirty:0\r\n" - "redis_build_id:915e5480613bc9b6\r\n" - "redis_mode:standalone ", + ( + "# Server\r\nredis_version:5.0.14.1\r\n" + "redis_git_sha1:00000000\r\nredis_git_dirty:0\r\n" + "redis_build_id:915e5480613bc9b6\r\n" + "redis_mode:standalone " + ), "5.0.14.1", ), ], @@ -580,9 +588,10 @@ def test_version_path(info, version): mock_config.no_info = True mock_config.pager = "less" mock_config.version = "5.0.0" + mock_config.decode = "utf-8" with patch("iredis.client.Client.execute") as mock_execute: mock_execute.return_value = info - client = Client("127.0.0.1", "6379", None) + client = Client("127.0.0.1", 6379) client.get_server_info() assert mock_config.version == version