Skip to content
This repository has been archived by the owner on Sep 7, 2024. It is now read-only.

Commit

Permalink
ci(python): adding python linter ruff (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
kehiy authored Jul 23, 2024
1 parent 7f95dc8 commit 5710be7
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 42 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21.1'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v6
with:
version: v1.54
4 changes: 2 additions & 2 deletions .github/workflows/releaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
sudo apt install zip
- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: 1.21.1

Expand Down Expand Up @@ -59,7 +59,7 @@ jobs:
needs: [build-cli]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Create SHA256SUMS file
run: |
echo "${{ needs.build-cli.outputs.checksums }}" >> SHA256SUMS
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/ruff-python-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Python linter (Ruff)

on: [ push, pull_request ]

jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
4 changes: 2 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: '1.21.1'

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ fmt:
go mod tidy

check:
golangci-lint run --build-tags "${BUILD_TAG}" --timeout=20m0s
golangci-lint run --build-tags "${BUILD_TAG}" --timeout=20m0s
123 changes: 90 additions & 33 deletions test/normal_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import socket
import time
import utils
import random

#! GET method is not tested here now.
# TODO: writing test for method GET.
Expand All @@ -11,29 +10,33 @@

st = time.time()

#? Global variables
# ? Global variables
sub_set_names = []
set_names = []
elements_value = []

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

server_address = ('localhost', 7070) #! You can change port and host for testing.
server_address = ("localhost", 7070) #! You can change port and host for testing.
sock.connect(server_address)


def test_connect_ok():
"""
Connecting to database and creating a session.
Testing: CON TQL command
Error: null
"""
query = "CON root super_secret_password" #! Considers you config is default.
query = "CON root super_secret_password" #! Considers you config is default.
response = utils.make_query(query, sock)

assert response == "OK", f"\033[91mCan't connect to server with default info, received: {response}, expected: OK\033[0m"
assert (
response == "OK"
), f"\033[91mCan't connect to server with default info, received: {response}, expected: OK\033[0m"

print(f"\033[32mReceived response: {response}, Connection test Passed.\033[32m")


def test_ping_ok():
"""
Ping the database to check session health.
Expand All @@ -42,25 +45,33 @@ def test_ping_ok():
"""
response = utils.make_query("PING", sock)

assert response == "PONG", f"\033[91mCan't ping the database, received: {response}, expected: PONG\033[0m"
assert (
response == "PONG"
), f"\033[91mCan't ping the database, received: {response}, expected: PONG\033[0m"

print(f"\033[32mReceived response: {response}, we are connected!\033[32m")


def test_new_set_ok():
"""
Creating random sets.
Testing: SET TQL command
Error: null
"""
for i in range(10):
set_names.append(utils.get_random_string_name(i+2))
set_names.append(utils.get_random_string_name(i + 2))

query = f"SET {set_names[i]}"
response = utils.make_query(query, sock)

assert response == "OK", f"\033[91mCan't create set: {set_names[i]}, received: {response}, expected: OK\033[0m"
assert (
response == "OK"
), f"\033[91mCan't create set: {set_names[i]}, received: {response}, expected: OK\033[0m"

print(
f"\033[32mReceived response: {response}, {len(set_names)} sets created successfully.\nSets: {set_names}\033[32m"
)

print(f"\033[32mReceived response: {response}, {len(set_names)} sets created successfully.\nSets: {set_names}\033[32m")

def test_new_sub_set_ok():
"""
Expand All @@ -70,14 +81,19 @@ def test_new_sub_set_ok():
"""
for s in set_names:
for i in range(7):
sub_set_names.append(utils.get_random_string_name(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)

assert response == "OK", f"\033[91mCan't create subset: {sub_set_names[i]} in set {s}, received: {response}, expected: OK\033[0m"
assert (
response == "OK"
), f"\033[91mCan't create subset: {sub_set_names[i]} in set {s}, received: {response}, expected: OK\033[0m"

print(
f"\033[32mReceived response: {response}, {len(sub_set_names)} subsets created successfully.\nSubsets: {sub_set_names}\033[32m"
)

print(f"\033[32mReceived response: {response}, {len(sub_set_names)} subsets created successfully.\nSubsets: {sub_set_names}\033[32m")

def test_push_element_ok():
"""
Expand All @@ -90,19 +106,24 @@ 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_name(i+8)
element_value = utils.get_random_string_name(i + 8)
elements_value.append(element_value)

element_time = int(time.mktime(time.gmtime()))
query = f"PUSH {s} {sub_set_names[i]} {element_value} {element_time}"
response = utils.make_query(query, sock)

assert response == "OK", f"\033[91mCan't push element with value of: {elements_value[i]} and time of: {element_time}, received: {response}, expected: OK\033[0m"
assert (
response == "OK"
), f"\033[91mCan't push element with value of: {elements_value[i]} and time of: {element_time}, received: {response}, expected: OK\033[0m"

set_index += 7

#? Change `elements_value[:10]` to get more or less elements.
print(f"\033[32mReceived response: {response}, {len(elements_value)} elements pushed successfully.\nElements: {elements_value[:10]}\033[32m")
# ? Change `elements_value[:10]` to get more or less elements.
print(
f"\033[32mReceived response: {response}, {len(elements_value)} elements pushed successfully.\nElements: {elements_value[:10]}\033[32m"
)


def test_count_sets_ok():
"""
Expand All @@ -112,11 +133,16 @@ def test_count_sets_ok():
"""
response = utils.make_query("CNTS", sock)

assert response == str(len(set_names)), f"\033[91mCan't count sets, received: {response}, expected: {len(set_names)}\033[0m"
assert (
response == str(len(set_names))
), f"\033[91mCan't count sets, received: {response}, expected: {len(set_names)}\033[0m"

print(f"\033[32mReceived response: {response}, sets number counted successfully.\033[32m")
print(
f"\033[32mReceived response: {response}, sets number counted successfully.\033[32m"
)

def test_count_sub_sets_ok():

def test_count_sub_sets_ok():
"""
Counting all subsets.
Testing: CNTSS TQL command
Expand All @@ -130,9 +156,14 @@ def test_count_sub_sets_ok():

sub_sets_count += int(response)

assert sub_sets_count == len(sub_set_names), f"\033[91mCan't count subsets, received: {sub_sets_count}, expected: {len(sub_set_names)}\033[0m"
assert (
sub_sets_count == len(sub_set_names)
), f"\033[91mCan't count subsets, received: {sub_sets_count}, expected: {len(sub_set_names)}\033[0m"

print(
f"\033[32mReceived response: {sub_sets_count}, subsets counted successfully.\033[32m"
)

print(f"\033[32mReceived response: {sub_sets_count}, subsets counted successfully.\033[32m")

def test_count_elements_ok():
"""
Expand All @@ -149,12 +180,17 @@ def test_count_elements_ok():
response = utils.make_query(query, sock)

elements_count += int(response)

set_index += 7

assert elements_count == len(elements_value), f"\033[91mCan't count elements, received: {elements_count}, expected: {len(elements_value)}\033[0m"
assert (
elements_count == len(elements_value)
), f"\033[91mCan't count elements, received: {elements_count}, expected: {len(elements_value)}\033[0m"

print(
f"\033[32mReceived response: {elements_count}, elements counted successfully.\033[32m"
)

print(f"\033[32mReceived response: {elements_count}, elements counted successfully.\033[32m")

def test_clean_sub_sets_elements_ok():
"""
Expand All @@ -169,11 +205,16 @@ def test_clean_sub_sets_elements_ok():
query = f"CLNSS {s} {sub_set_names[i]}"
response = utils.make_query(query, sock)

assert response == "OK", f"\033[91mCan't clean subset: {sub_set_names[i]} of set {s}, received: {response}, expected: OK\033[0m"
assert (
response == "OK"
), f"\033[91mCan't clean subset: {sub_set_names[i]} of set {s}, received: {response}, expected: OK\033[0m"

set_index += 7

print(f"\033[32mReceived response: {response}, subset elements cleaned successfully.\033[32m")
print(
f"\033[32mReceived response: {response}, subset elements cleaned successfully.\033[32m"
)


def test_drop_sub_sets_ok():
"""
Expand All @@ -188,11 +229,16 @@ def test_drop_sub_sets_ok():
query = f"DRPSS {s} {sub_set_names[i]}"
response = utils.make_query(query, sock)

assert response == "OK", f"\033[91mCan't drop subset: {sub_set_names[i]} from set: {s}, received: {response}, expected: OK\033[0m"

assert (
response == "OK"
), f"\033[91mCan't drop subset: {sub_set_names[i]} from set: {s}, received: {response}, expected: OK\033[0m"

set_index += 7

print(f"\033[32mReceived response: {response}, subsets dropped successfully.\033[32m")
print(
f"\033[32mReceived response: {response}, subsets dropped successfully.\033[32m"
)


def test_clean_sub_sets_ok():
"""
Expand All @@ -204,10 +250,13 @@ def test_clean_sub_sets_ok():
query = f"CLNS {s}"
response = utils.make_query(query, sock)

assert response == "OK", f"\033[91mCan't clean set: {s}, received: {response}, expected: OK\033[0m"
assert (
response == "OK"
), f"\033[91mCan't clean set: {s}, received: {response}, expected: OK\033[0m"

print(f"\033[32mReceived response: {response}, sets cleaned successfully.\033[32m")


def test_drop_sets_ok():
"""
Dropping all sets.
Expand All @@ -218,10 +267,13 @@ def test_drop_sets_ok():
query = f"DRPS {s}"
response = utils.make_query(query, sock)

assert response == "OK", f"\033[91mCan't drop set: {s}, received: {response}, expected: OK\033[0m"
assert (
response == "OK"
), f"\033[91mCan't drop set: {s}, received: {response}, expected: OK\033[0m"

print(f"\033[32mReceived response: {response}, sets dropped successfully.\033[32m")


def test_clean_sets_ok():
"""
Cleaning all sets.
Expand All @@ -230,7 +282,9 @@ def test_clean_sets_ok():
"""
response = utils.make_query("CLN", sock)

assert response == "OK", f"\033[91mCan't clean sets, received: {response}, expected: OK\033[0m"
assert (
response == "OK"
), f"\033[91mCan't clean sets, received: {response}, expected: OK\033[0m"

print(f"\033[32mReceived response: {response},sets cleaned successfully.\033[32m")

Expand All @@ -250,7 +304,10 @@ def main():
test_drop_sets_ok()
test_clean_sets_ok()


if __name__ == "__main__":
main()
sock.close()
print('\033[34mAll tests successfully passed in:\033[34m', time.time() - st, 'seconds')
print(
"\033[34mAll tests successfully passed in:\033[34m", time.time() - st, "seconds"
)
4 changes: 3 additions & 1 deletion test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
import string
import socket


def get_random_string_name(length: int) -> str:
return ''.join(random.choice(string.ascii_lowercase) for i in range(length))
return "".join(random.choice(string.ascii_lowercase) for i in range(length))


def make_query(query: str, sock: socket.socket) -> str:
sock.sendall(query.encode())
Expand Down

0 comments on commit 5710be7

Please sign in to comment.