diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-07-17 07:34:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-07-17 07:34:57 +0000 |
commit | d71fd6264d58795c50b9350d7c39677b671e0896 (patch) | |
tree | 0aa9e0bd923a00b9ddda4e01af55a76ed314097c /tests/unittests | |
parent | Releasing debian version 1.9.1-3. (diff) | |
download | iredis-d71fd6264d58795c50b9350d7c39677b671e0896.tar.xz iredis-d71fd6264d58795c50b9350d7c39677b671e0896.zip |
Merging upstream version 1.9.4.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/unittests')
-rw-r--r-- | tests/unittests/__init__.py | 0 | ||||
-rw-r--r-- | tests/unittests/command_parse/test_cluster.py | 36 | ||||
-rw-r--r-- | tests/unittests/test_client.py | 102 | ||||
-rw-r--r-- | tests/unittests/test_render_functions.py | 6 | ||||
-rw-r--r-- | tests/unittests/test_utils.py | 6 |
5 files changed, 95 insertions, 55 deletions
diff --git a/tests/unittests/__init__.py b/tests/unittests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/unittests/__init__.py diff --git a/tests/unittests/command_parse/test_cluster.py b/tests/unittests/command_parse/test_cluster.py index e60fe92..6dd877f 100644 --- a/tests/unittests/command_parse/test_cluster.py +++ b/tests/unittests/command_parse/test_cluster.py @@ -26,9 +26,15 @@ def test_command_cluster_count_failure_reports(judge_command): ) judge_command("cluster count-failure-reports 1 2 3 4", None) judge_command("cluster count-failure-reports 1 a", None) - judge_command("cluster count-failure-reports a", None) + judge_command( + "cluster count-failure-reports a", + {"command": "cluster count-failure-reports", "node": "a"}, + ) judge_command("cluster count-failure-reports a 2", None) - judge_command("cluster count-failure-reports abc", None) + judge_command( + "cluster count-failure-reports abc", + {"command": "cluster count-failure-reports", "node": "abc"}, + ) def test_command_cluster_countkeysinslot(judge_command): @@ -88,9 +94,22 @@ def test_command_cluster_forget(judge_command): ) judge_command("cluster forget 1 2 3 4", None) judge_command("cluster forget 1 a", None) - judge_command("cluster forget a", None) + judge_command("cluster forget a", {"command": "cluster forget", "node": "a"}) judge_command("cluster forget a 2", None) - judge_command("cluster forget abc", None) + judge_command( + "cluster forget abc", + { + "command": "cluster forget", + "node": "abc", + }, + ) + judge_command( + "cluster forget 07c37dfeb235213a872192d90877d0cd55635b91", + { + "command": "cluster forget", + "node": "07c37dfeb235213a872192d90877d0cd55635b91", + }, + ) def test_command_cluster_getkeysinslot(judge_command): @@ -209,6 +228,15 @@ def test_command_cluster_set_slot(judge_command): }, ) judge_command( + "cluster setslot 123 node e7d1eecce10fd6bb5eb35b9f99a514335d9ba9ca", + { + "command": "cluster setslot", + "slot": "123", + "slotsubcmd": "node", + "node": "e7d1eecce10fd6bb5eb35b9f99a514335d9ba9ca", + }, + ) + judge_command( "cluster setslot 123 MIGRATING 123123", { "command": "cluster setslot", diff --git a/tests/unittests/test_client.py b/tests/unittests/test_client.py index e78da17..5887579 100644 --- a/tests/unittests/test_client.py +++ b/tests/unittests/test_client.py @@ -11,6 +11,7 @@ from iredis.config import config, load_config_files from iredis.completers import IRedisCompleter from iredis.entry import Rainbow, prompt_message from iredis.exceptions import NotSupport +from ..helpers import formatted_text_rematch @pytest.fixture @@ -258,19 +259,15 @@ def test_peek_string(iredis_client, clean_redis): clean_redis.set("foo", "bar") peek_result = list(iredis_client.do_peek("foo")) - assert peek_result == [ - FormattedText( - [ - ("class:dockey", "key: "), - ("", "string (embstr) mem: 50 bytes, ttl: -1"), - ("", "\n"), - ("class:dockey", "strlen: "), - ("", "3"), - ("", "\n"), - ("class:dockey", "value: "), - ("", '"bar"'), - ] - ) + assert peek_result[0][0] == ("class:dockey", "key: ") + assert re.match(r"string \(embstr\) mem: \d+ bytes, ttl: -1", peek_result[0][1][1]) + assert peek_result[0][2:] == [ + ("", "\n"), + ("class:dockey", "strlen: "), + ("", "3"), + ("", "\n"), + ("class:dockey", "value: "), + ("", '"bar"'), ] @@ -278,39 +275,40 @@ def test_peek_list_fetch_all(iredis_client, clean_redis): clean_redis.lpush("mylist", *[f"hello-{index}" for index in range(5)]) peek_result = list(iredis_client.do_peek("mylist")) - assert peek_result == [ + formatted_text_rematch( + peek_result[0], FormattedText( [ ("class:dockey", "key: "), - ("", "list (quicklist) mem: 176 bytes, ttl: -1"), + ("", r"list \(quicklist\) mem: \d+ bytes, ttl: -1"), ("", "\n"), ("class:dockey", "llen: "), ("", "5"), ("", "\n"), ("class:dockey", "elements: "), ("", "\n"), - ("", "1)"), + ("", r"1\)"), ("", " "), ("class:string", '"hello-4"'), ("", "\n"), - ("", "2)"), + ("", r"2\)"), ("", " "), ("class:string", '"hello-3"'), ("", "\n"), - ("", "3)"), + ("", r"3\)"), ("", " "), ("class:string", '"hello-2"'), ("", "\n"), - ("", "4)"), + ("", r"4\)"), ("", " "), ("class:string", '"hello-1"'), ("", "\n"), - ("", "5)"), + ("", r"5\)"), ("", " "), ("class:string", '"hello-0"'), ] - ) - ] + ), + ) def test_peek_list_fetch_part(iredis_client, clean_redis): @@ -338,18 +336,21 @@ def test_peek_zset_fetch_all(iredis_client, clean_redis): "myzset", dict(zip([f"hello-{index}" for index in range(3)], range(3))) ) peek_result = list(iredis_client.do_peek("myzset")) - assert peek_result[0][0:9] == FormattedText( - [ - ("class:dockey", "key: "), - ("", "zset (ziplist) mem: 92 bytes, ttl: -1"), - ("", "\n"), - ("class:dockey", "zcount: "), - ("", "3"), - ("", "\n"), - ("class:dockey", "members: "), - ("", "\n"), - ("", "1)"), - ] + formatted_text_rematch( + peek_result[0][0:9], + FormattedText( + [ + ("class:dockey", "key: "), + ("", r"zset \(ziplist\) mem: \d+ bytes, ttl: -1"), + ("", "\n"), + ("class:dockey", "zcount: "), + ("", "3"), + ("", "\n"), + ("class:dockey", "members: "), + ("", "\n"), + ("", r"1\)"), + ] + ), ) @@ -358,17 +359,20 @@ def test_peek_zset_fetch_part(iredis_client, clean_redis): "myzset", dict(zip([f"hello-{index}" for index in range(40)], range(40))) ) peek_result = list(iredis_client.do_peek("myzset")) - assert peek_result[0][0:8] == FormattedText( - [ - ("class:dockey", "key: "), - ("", "zset (ziplist) mem: 556 bytes, ttl: -1"), - ("", "\n"), - ("class:dockey", "zcount: "), - ("", "40"), - ("", "\n"), - ("class:dockey", "members (first 40): "), - ("", "\n"), - ] + formatted_text_rematch( + peek_result[0][0:8], + FormattedText( + [ + ("class:dockey", "key: "), + ("", r"zset \(ziplist\) mem: \d+ bytes, ttl: -1"), + ("", "\n"), + ("class:dockey", "zcount: "), + ("", "40"), + ("", "\n"), + ("class:dockey", r"members \(first 40\): "), + ("", "\n"), + ] + ), ) @@ -395,10 +399,12 @@ def test_peek_stream(iredis_client, clean_redis): clean_redis.xadd("mystream", {"foo": "bar", "hello": "world"}) peek_result = list(iredis_client.do_peek("mystream")) - assert peek_result[0][0:18] == FormattedText( + 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] + ) + assert peek_result[0][2:18] == FormattedText( [ - ("class:dockey", "key: "), - ("", "stream (unknown) mem: 601 bytes, ttl: -1"), ("", "\n"), ("class:dockey", "XINFO: "), ("", "\n"), diff --git a/tests/unittests/test_render_functions.py b/tests/unittests/test_render_functions.py index 2da9b35..30b328e 100644 --- a/tests/unittests/test_render_functions.py +++ b/tests/unittests/test_render_functions.py @@ -484,3 +484,9 @@ def test_render_bytes(config): def test_render_bytes_raw(config): assert renders.OutputRender.render_raw(b"bytes\n") == b"bytes\n" + + +def test_render_help(config): + assert renders.OutputRender.render_help([b"foo", b"bar"]) == FormattedText( + [("class:string", "foo\nbar")] + ) diff --git a/tests/unittests/test_utils.py b/tests/unittests/test_utils.py index c9b5eff..98ea8db 100644 --- a/tests/unittests/test_utils.py +++ b/tests/unittests/test_utils.py @@ -53,11 +53,11 @@ def test_timer(): (r""" "hello\"world" """, ['hello"world']), (r"''", [""]), # set foo "" is a legal command (r'""', [""]), # set foo "" is a legal command - (r"\\", ["\\\\"]), # blackslash are legal - ("\\hello\\", ["\\hello\\"]), # blackslash are legal + (r"\\", ["\\\\"]), # backslash are legal + ("\\hello\\", ["\\hello\\"]), # backslash are legal ], ) -def test_stipe_quote_escaple_in_quote(test_input, expected): +def test_stripe_quote_escape_in_quote(test_input, expected): assert list(strip_quote_args(test_input)) == expected |