diff options
Diffstat (limited to 'tests/unittests/test_client.py')
-rw-r--r-- | tests/unittests/test_client.py | 102 |
1 files changed, 54 insertions, 48 deletions
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"), |