Skip to content

Commit

Permalink
Realiability/pytest (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
kerrychu committed Jan 23, 2024
1 parent d8031ea commit 73e8f39
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 34 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Code Quality

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
linting:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
- name: Run Pylint
run: |
python -m pylint $(git ls-files '*.py')
testing:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run Pytest
run: |
python -m pytest tests -vv
23 changes: 0 additions & 23 deletions .github/workflows/pylint.yml

This file was deleted.

3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exceptiongroup==1.2.0
executing==2.0.1
idna==3.6
importlib-metadata==7.0.1
iniconfig==2.0.0
ipython==8.18.1
isort==5.13.2
jaraco.classes==3.3.0
Expand All @@ -32,12 +33,14 @@ pathspec==0.12.1
pexpect==4.9.0
pkginfo==1.9.6
platformdirs==4.1.0
pluggy==1.3.0
prompt-toolkit==3.0.43
ptyprocess==0.7.0
pure-eval==0.2.2
Pygments==2.17.2
pylint==3.0.3
pyproject_hooks==1.0.0
pytest==7.4.4
python-dateutil==2.8.2
python-dotenv==1.0.0
pytz==2023.3.post1
Expand Down
4 changes: 2 additions & 2 deletions gpu_jobs.py → src/gpu_jobs.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os
from dotenv import load_dotenv
from utils.subprocess_operations import (
from src.utils.subprocess_operations import (
get_piped_stdout,
stdout_to_gpu_records,
job_records_to_slack_message,
)
from hooks.slack import send_slack_message
from src.hooks.slack import send_slack_message

load_dotenv()
SLACK_WEBHOOK = os.getenv("SLACK_GPU_JOBS_WEBHOOK")
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions my_jobs.py → src/my_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from typing import Optional

from dotenv import load_dotenv
from hooks.slack import send_slack_message
from utils.data_serialization import (
from src.hooks.slack import send_slack_message
from src.utils.data_serialization import (
read_json_as_job_records,
write_job_records_to_json,
)
from utils.subprocess_operations import (
from src.utils.subprocess_operations import (
stdout_to_job_records,
JOB_RECORDS,
job_records_to_slack_message,
Expand Down
4 changes: 2 additions & 2 deletions quota.py → src/quota.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from dotenv import load_dotenv
from utils.subprocess_operations import get_piped_stdout, stdout_to_quota_records
from hooks.slack import send_slack_message
from src.utils.subprocess_operations import get_piped_stdout, stdout_to_quota_records
from src.hooks.slack import send_slack_message

load_dotenv()

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ def get_piped_stdout(main_command: str, piped_command: str) -> Optional[str]:
)


def strip_spaces(l: list[str]) -> list[str]:
def strip_empty_string(l: list[str]) -> list[str]:
return [x for x in l if x != ""]


def stdout_to_job_records(s: str) -> JOB_RECORDS:
s = s.strip()
s_list = s.split("\n")
headers = strip_spaces(s_list[0].split(" "))
data = [strip_spaces(element.split(" ")) for element in s_list[1:]]
headers = strip_empty_string(s_list[0].split(" "))
data = [strip_empty_string(element.split(" ")) for element in s_list[1:]]
job_records = []
for l in data:
d = {}
Expand Down Expand Up @@ -82,7 +82,7 @@ def stdout_to_gpu_records(s: str) -> JOB_RECORDS:
s = s.strip()
s_list = s.split("\n")
headers = ["JOBID", "PARTITION", "NAME", "USER", "ST", "TIME", "NODES"]
data = [strip_spaces(element.split(" ")) for element in s_list]
data = [strip_empty_string(element.split(" ")) for element in s_list]
job_records = []
for l in data:
d = {}
Expand Down
File renamed without changes.
Empty file added tests/test_gpu_jobs.py
Empty file.
Empty file added tests/test_hooks/__init__.py
Empty file.
Empty file added tests/test_my_jobs.py
Empty file.
Empty file added tests/test_quota.py
Empty file.
Empty file added tests/test_utils/__init__.py
Empty file.
17 changes: 17 additions & 0 deletions tests/test_utils/test_subprocess_operations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from src.utils.subprocess_operations import (
strip_empty_string,
job_records_to_slack_message,
)


def test_strip_empty_string():
assert strip_empty_string(["hello", "world", ""]) == ["hello", "world"]


def test_job_records_to_slack_message():
header = "header"
job_records = [{"key1": "value1", "key2": "value2", "key3": "value3"}]
assert (
job_records_to_slack_message(header, job_records)
== "header\n\t⦿ key1: value1\n\t⦿ key2: value2\n\t⦿ key3: value3\n"
)

0 comments on commit 73e8f39

Please sign in to comment.