From a61e45090e76ad99269ccdd3e56650d4b7fc4c9f Mon Sep 17 00:00:00 2001 From: kehiy Date: Mon, 15 Jul 2024 16:11:28 +0330 Subject: [PATCH] refactor: python normal test --- .gitignore | 3 +++ test/normal_test.py | 6 +++--- test/utils.py | 5 +++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index d8db0d2..cf7bbc6 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,6 @@ cmd/config.yaml /client log.ttrace build/ + +# python cache files +test/__pycache__ diff --git a/test/normal_test.py b/test/normal_test.py index d9ef148..6acbd05 100644 --- a/test/normal_test.py +++ b/test/normal_test.py @@ -39,7 +39,7 @@ def test_ping_ok(): def test_new_set_ok(): #* Creating some random sets. for i in range(10): - set_names.append(utils.get_random_string(i+2)) + set_names.append(utils.get_random_string_name(i+2)) query = f"SET {set_names[i]}" response = utils.make_query(query, sock) @@ -52,7 +52,7 @@ def test_new_sub_set_ok(): #* Creating some random sub sets. for s in set_names: for i in range(7): - sub_set_names.append(utils.get_random_string(i+2)) + sub_set_names.append(utils.get_random_string_name(i+2)) query = f"SSET {s} {sub_set_names[i]}" response = utils.make_query(query, sock) @@ -67,7 +67,7 @@ def test_push_element_ok(): for s in set_names: for i in range(7): for _ in range(1_000): - element_value = utils.get_random_string(i+8) + element_value = utils.get_random_string_name(i+8) elements_value.append(element_value) query = f"PUSH {s} {sub_set_names[i]} {element_value} {int(time.mktime(time.gmtime()))}" diff --git a/test/utils.py b/test/utils.py index a523551..46cf925 100644 --- a/test/utils.py +++ b/test/utils.py @@ -1,9 +1,10 @@ import random import string +import socket -def get_random_string(length): +def get_random_string_name(length: int) -> str: return ''.join(random.choice(string.ascii_lowercase) for i in range(length)) -def make_query(query, sock): +def make_query(query: str, sock: socket.socket) -> str: sock.sendall(query.encode()) return sock.recv(1024).decode()