Skip to content

Commit

Permalink
Merge pull request #479 from laixintao/fix-ci
Browse files Browse the repository at this point in the history
fix test cases caused by type not matching, and redis-server 7.2 integration
  • Loading branch information
laixintao committed Oct 30, 2023
2 parents 941c16a + 8614110 commit 9cc5b02
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-20.04"]
python: ["3.7", "3.8", "3.9", "3.10", "3.11.1", "3.12.0"]
python: ["3.7", "3.8", "3.9", "3.10", "3.11.1"]
redis: [5, 6, 7, 7.2]
runs-on: ${{ matrix.os }}

Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## UPCOMING

## 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
Expand Down Expand Up @@ -316,3 +323,4 @@
[tssujt]: https://github.com/tssujt
[aymericbeaumet]: https://github.com/aymericbeaumet
[torrefatto]: https://github.com/torrefatto
[chayim]: https://github.com/chayim
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<p align="center">
<a href="https://github.com/laixintao/iredis/actions"><img src="https://github.com/laixintao/iredis/workflows/Test/badge.svg" alt="Github Action"></a>
<a href="https://badge.fury.io/py/iredis"><img src="https://badge.fury.io/py/iredis.svg" alt="PyPI version"></a>
<img src="https://badgen.net/badge/python/3.7%20%7C%203.8%20%7C%203.9%20%7C%203.10/" alt="Python version">
<img src="https://badgen.net/badge/python/3.7%20%7C%203.8%20%7C%203.9%20%7C%203.10%20%7C%203.11" alt="Python version">
<a href="https://pepy.tech/project/iredis"><img src="https://pepy.tech/badge/iredis" alt="Download stats"></a>
</p>

Expand Down
1 change: 1 addition & 0 deletions iredis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def __init__(
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:
Expand Down
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
# "Programming Language :: Python :: 3.12",
"Topic :: Database",
"License :: OSI Approved :: MIT License",
"Intended Audience :: Developers",
Expand Down
8 changes: 5 additions & 3 deletions tests/cli_tests/test_cli_start.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down Expand Up @@ -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")
Expand Down
8 changes: 5 additions & 3 deletions tests/cli_tests/test_command_input.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os

from packaging.version import parse as version_parse
import pytest


Expand All @@ -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"
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion tests/cli_tests/test_completer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from packaging.version import parse as version_parse # noqa: F401
import pytest


Expand Down Expand Up @@ -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")
Expand Down
17 changes: 9 additions & 8 deletions tests/cli_tests/test_pager.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# noqa: F541
from contextlib import contextmanager
import os
import sys
import pexpect
import pathlib
from contextlib import contextmanager
import sys
from textwrap import dedent
from packaging.version import parse as version_parse

import pexpect


TEST_IREDISRC = "/tmp/.iredisrc.test"
Expand All @@ -22,6 +24,10 @@
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():
Expand Down Expand Up @@ -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}")
Expand Down
51 changes: 30 additions & 21 deletions tests/unittests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import os
import re
import pytest
import redis
from unittest.mock import MagicMock, patch
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 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


Expand All @@ -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"
Expand All @@ -40,7 +42,7 @@ def completer():
],
)
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
),
],
Expand All @@ -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

Expand Down

0 comments on commit 9cc5b02

Please sign in to comment.