Skip to content

Commit

Permalink
Merge pull request #1 from kcz358/dev/unittest_workflows
Browse files Browse the repository at this point in the history
[Setup] Unittest workflows
  • Loading branch information
kcz358 authored Oct 12, 2024
2 parents 5a73562 + 717a1dd commit c19675f
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Unittest

on:
push:
branches: [ main ]
paths:
- "src/**"
- "test/**"
pull_request:
branches: [ main ]
paths:
- "src/**"
- "test/**"
workflow_dispatch:


jobs:
unit-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install dependencies
run: |
pip install --upgrade pip
pip install -e .
- name: Run test
timeout-minutes: 20
run: |
python3 test/run_suite.py
9 changes: 9 additions & 0 deletions test/run_suite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import glob

from utils import run_unittest_files

if __name__ == "__main__":
files = glob.glob("**/test_*.py", recursive=True)

exit_code = run_unittest_files(files)
exit(exit_code)
10 changes: 10 additions & 0 deletions test/test_foo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import unittest


class TestFoo(unittest.TestCase):
def test_foo(self):
self.assertEqual(1, 1)


if __name__ == "__main__":
unittest.main()
38 changes: 38 additions & 0 deletions test/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"Copied from sglang https://github.com/sgl-project/sglang/blob/main/python/sglang/test/test_utils.py"
import os
import subprocess
import time
from typing import List


def run_unittest_files(files: List[str]):
tic = time.time()
success = True

for filename in files:

def run_one_file(filename):
filename = os.path.join(os.getcwd(), filename)
print(f"\n\nRun:\npython3 {filename}\n\n", flush=True)
process = subprocess.Popen(["python3", filename], stdout=None, stderr=None, env=os.environ)
process.wait()
return process.returncode

try:
ret_code = run_one_file(filename)
assert ret_code == 0
except Exception as e:
time.sleep(5)
print(
f"\nError {e} when running {filename}\n",
flush=True,
)
success = False
break

if success:
print(f"Success. Time elapsed: {time.time() - tic:.2f}s", flush=True)
else:
print(f"Fail. Time elapsed: {time.time() - tic:.2f}s", flush=True)

return 0 if success else -1

0 comments on commit c19675f

Please sign in to comment.