Skip to content

Commit

Permalink
Add tests workflow (#18)
Browse files Browse the repository at this point in the history
* Add new `tests` workflow

* Use pip cache

* Unify env setup. Drop UV in favor of setup-python

* Update tests
  • Loading branch information
daavoo authored Nov 28, 2024
1 parent 226a034 commit 9ff8e23
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: '3.10'

cache: "pip"
- name: Configure git
run: |
git config user.name 'github-actions[bot]'
Expand Down
20 changes: 9 additions & 11 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,21 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Check out the repository
uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Set up venv
run: |
uv venv
source .venv/bin/activate
uv pip install pre-commit
- name: Install pre-commit
run: pip install pre-commit

- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit/
key: pre-commit-4|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}

- name: pre-commit
run: |
source .venv/bin/activate
pre-commit run --all-files
run: pre-commit run --all-files
28 changes: 28 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Tests

on:
push:
branches: [main]
pull_request:
workflow_dispatch:

jobs:
run-linter:
timeout-minutes: 30
runs-on: ubuntu-latest

steps:
- name: Check out the repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: "pip"

- name: Install
run: pip install -e '.[tests]'

- name: Run tests
run: pytest -v tests
17 changes: 2 additions & 15 deletions tests/integration/test_model_load_and_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ def test_model_load_and_inference_text_to_text():
"HuggingFaceTB/smollm-135M-instruct-v0.2-Q8_0-GGUF/smollm-135m-instruct-add-basics-q8_0.gguf"
)
result = text_to_text(
"What is the capital of France?",
"Answer to: What is the capital of France?",
model=model,
system_prompt="",
)
assert isinstance(result, str)
assert json.loads(result)["Capital"] == "Paris"
assert json.loads(result)


def test_model_load_and_inference_text_to_text_no_json():
Expand All @@ -37,19 +37,6 @@ def test_model_load_and_inference_text_to_text_no_json():
assert result.startswith("The capital of France is Paris")


def test_model_load_and_inference_text_to_text_stream():
model = load_llama_cpp_model(
"HuggingFaceTB/smollm-135M-instruct-v0.2-Q8_0-GGUF/smollm-135m-instruct-add-basics-q8_0.gguf"
)
result = text_to_text_stream(
"What is the capital of France?",
model=model,
system_prompt="",
)
assert isinstance(result, Iterator)
assert json.loads("".join(result))["Capital"] == "Paris"


def test_model_load_and_inference_text_to_text_stream_no_json():
model = load_llama_cpp_model(
"HuggingFaceTB/smollm-135M-instruct-v0.2-Q8_0-GGUF/smollm-135m-instruct-add-basics-q8_0.gguf"
Expand Down

0 comments on commit 9ff8e23

Please sign in to comment.