Skip to content

Commit

Permalink
adding tests and github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
kerrychu committed Jan 23, 2024
1 parent 94810a2 commit e203583
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Pytest

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
- name: Run tests with Pytest
run: |
pytest tests -vv
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
8 changes: 4 additions & 4 deletions src/utils/subprocess_operations.py
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
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 e203583

Please sign in to comment.