-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from kcz358/dev/unittest_workflows
[Setup] Unittest workflows
- Loading branch information
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |