Skip to content

Commit

Permalink
Added unit tests for new model factory
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Engel <mengel@redhat.com>
  • Loading branch information
engelmi committed Feb 24, 2025
1 parent 4680398 commit 6626eaf
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 6 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ jobs:
run: |
make lint
unit-test:
name: Unit Tests
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Install dependencies
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y bash codespell python3-argcomplete pipx
make install-requirements
- name: Run unit tests
run: |
make unit-tests
bats:
runs-on: ubuntu-24.04
steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
run: ./container_build.sh build ramalama

- name: Run a one-line script
run: make test
run: make end-to-end-tests

macos:
runs-on: macos-14
Expand All @@ -63,7 +63,7 @@ jobs:
run: brew install go
- name: Run a one-line script
shell: bash
run: make test
run: make end-to-end-tests

build:
runs-on: ubuntu-24.04
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
run: ./container_build.sh build ramalama

- name: Run a one-line script
run: make test
run: make end-to-end-tests

macos:
runs-on: macos-14
Expand All @@ -58,7 +58,7 @@ jobs:
run: brew install go
- name: Run a one-line script
shell: bash
run: make test
run: make end-to-end-tests

build:
runs-on: ubuntu-24.04
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ venv/
*.container
*.image
*.volume
__pycache__/
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ install-requirements:
flake8~=7.0 \
huggingface_hub~=0.28.0 \
isort~=6.0 \
pytest~=8.3 \
wheel~=0.45.0 \

.PHONY: install-completions
Expand Down Expand Up @@ -164,11 +165,18 @@ bats-docker:
ci:
test/ci.sh

.PHONY: test
test: validate bats bats-nocontainer ci
.PHONY: unit-tests
unit-tests:
PYTHONPATH=. pytest test/unit/

.PHONY: end-to-end-tests
end-to-end-tests: validate bats bats-nocontainer ci
make clean
hack/tree_status.sh

.PHONY: tests
tests: unit-tests end-to-end-tests

.PHONY: clean
clean:
@find . -name \*~ -delete
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ line_length = 120
max-line-length = 120

[tool.pytest.ini_options]
testpaths = ["."]
log_cli = true
log_cli_level = "DEBUG"
log_cli_format = "%(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)"
Expand Down
45 changes: 45 additions & 0 deletions test/unit/test_model_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import pytest
from ramalama.model_factory import ModelFactory
from ramalama.huggingface import Huggingface
from ramalama.oci import OCI
from ramalama.ollama import Ollama
from ramalama.url import URL

from dataclasses import dataclass

@dataclass
class Input():
Model: str
Transport: str
Engine: str

@pytest.mark.parametrize(
"input,expected,error",
[
(Input("", "", ""), None, KeyError),
(Input("huggingface://granite-code", "", ""), Huggingface, None),
(Input("hf://granite-code", "", ""), Huggingface, None),
(Input("hf.co/granite-code", "", ""), Huggingface, None),
(Input("ollama://granite-code", "", ""), Ollama, None),
(Input("ollama.com/library/granite-code", "", ""), Ollama, None),
(Input("oci://granite-code", "", "podman"), OCI, None),
(Input("docker://granite-code", "", "podman"), OCI, None),
(Input("http://huggingface.co/ibm-granite/granite-3b-code-base-2k-GGUF/blob/main/granite-3b-code-base.Q4_K_M.gguf", "", ""), URL, None),
(Input("https://huggingface.co/ibm-granite/granite-3b-code-base-2k-GGUF/blob/main/granite-3b-code-base.Q4_K_M.gguf", "", ""), URL, None),
(Input("file:///tmp/models/granite-3b-code-base.Q4_K_M.gguf", "", ""), URL, None),
(Input("granite-code", "huggingface", ""), Huggingface, None),
(Input("granite-code", "ollama", ""), Ollama, None),
(Input("granite-code", "oci", ""), OCI, None),
]
)
def test_model_factory_create(input: Input, expected, error):
if error is not None:
with pytest.raises(error):
ModelFactory(input.Model, input.Transport, input.Engine).create()
else:
model = ModelFactory(input.Model, input.Transport, input.Engine).create()
assert isinstance(model, expected)

0 comments on commit 6626eaf

Please sign in to comment.