diff options
author | Daniel Baumann <mail@daniel-baumann.ch> | 2023-11-04 18:52:12 +0000 |
---|---|---|
committer | Daniel Baumann <mail@daniel-baumann.ch> | 2023-11-04 18:52:12 +0000 |
commit | a596894f2d782b9df54c026696e55da1267f7936 (patch) | |
tree | e2696ad38feb91700ac875966e6aa0b30e732566 /tests/unittests | |
parent | Adding upstream version 1.13.1. (diff) | |
download | iredis-a596894f2d782b9df54c026696e55da1267f7936.tar.xz iredis-a596894f2d782b9df54c026696e55da1267f7936.zip |
Adding upstream version 1.14.0.upstream/1.14.0
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'tests/unittests')
-rw-r--r-- | tests/unittests/test_client.py | 61 | ||||
-rw-r--r-- | tests/unittests/test_entry.py | 1 | ||||
-rw-r--r-- | tests/unittests/test_markdown_doc_render.py | 2 |
3 files changed, 38 insertions, 26 deletions
diff --git a/tests/unittests/test_client.py b/tests/unittests/test_client.py index 45f0054..c0f4c07 100644 --- a/tests/unittests/test_client.py +++ b/tests/unittests/test_client.py @@ -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 @@ -22,8 +24,12 @@ def completer(): zset_type = "ziplist" -if os.environ["REDIS_VERSION"] == "7": +hash_type = "hashtable" +list_type = "quicklist" +if version_parse(os.environ["REDIS_VERSION"]) >= version_parse("7"): zset_type = "listpack" + hash_type = "listpack" + list_type = "listpack" @pytest.mark.parametrize( @@ -36,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 @@ -176,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 @@ -209,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 @@ -303,7 +309,7 @@ def test_peek_list_fetch_all(iredis_client, clean_redis): FormattedText( [ ("class:dockey", "key: "), - ("", r"list \(quicklist\) mem: \d+ bytes, ttl: -1"), + ("", rf"list \({list_type}\) mem: \d+ bytes, ttl: -1"), ("", "\n"), ("class:dockey", "llen: "), ("", "5"), @@ -351,7 +357,7 @@ def test_peek_set_fetch_part(iredis_client, clean_redis): peek_result = list(iredis_client.do_peek("myset")) assert peek_result[0][0] == ("class:dockey", "key: ") - assert peek_result[0][1][1].startswith("set (hashtable) mem: 2") + assert peek_result[0][1][1].startswith(f"set ({hash_type}) mem: ") def test_peek_zset_fetch_all(iredis_client, clean_redis): @@ -425,7 +431,7 @@ def test_peek_stream(iredis_client, clean_redis): assert peek_result[0][0] == ("class:dockey", "key: ") assert re.match( - r"stream \((stream|unknown)\) mem: 6\d\d bytes, ttl: -1", peek_result[0][1][1] + r"stream \((stream|unknown)\) mem: \d+ bytes, ttl: -1", peek_result[0][1][1] ) assert peek_result[0][2:18] == FormattedText( [ @@ -550,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", ), ], @@ -576,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 diff --git a/tests/unittests/test_entry.py b/tests/unittests/test_entry.py index 912aabf..e53861e 100644 --- a/tests/unittests/test_entry.py +++ b/tests/unittests/test_entry.py @@ -28,7 +28,6 @@ from iredis.utils import DSN def test_command_entry_tty(is_tty, raw_arg_is_raw, final_config_is_raw, config): # is tty + raw -> raw with patch("sys.stdout.isatty") as patch_tty: - patch_tty.return_value = is_tty if raw_arg_is_raw is None: call = ["iredis"] diff --git a/tests/unittests/test_markdown_doc_render.py b/tests/unittests/test_markdown_doc_render.py index 0538299..0c66260 100644 --- a/tests/unittests/test_markdown_doc_render.py +++ b/tests/unittests/test_markdown_doc_render.py @@ -6,7 +6,7 @@ https://github.com/antirez/redis-doc/commit/02b3d1a345093c1794fd86273e9d516fffd3 """ import pytest -from importlib_resources import read_text +from importlib.resources import read_text from iredis.commands import commands_summary from iredis.data import commands as commands_data |