mirror of
https://github.com/containers/ramalama.git
synced 2026-02-05 15:47:26 +01:00
- Migrate to e2e pytest the `test/system/050-pull.bats` bat test. - Ollama fixture has been added to test on a insolated ollama instance - The tests cover a wide range of functionalities, including: - Pulling models from different transports like Ollama, Hugging Face, OCI, and local files. - Verifying the use of local caches from Ollama and Hugging Face to speed up subsequent pulls. - Testing error handling for non-existent models and endianness mismatches. - Ensuring proper interaction with authenticated OCI registries for pulling private models. - Validating the handling of models with multiple layers and references. Signed-off-by: Roberto Majadas <rmajadas@redhat.com>
116 lines
3.9 KiB
Python
116 lines
3.9 KiB
Python
import os
|
|
import platform
|
|
import shutil
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
ramalama_container = True
|
|
ramalama_container_engine = "podman"
|
|
|
|
|
|
def pytest_addoption(parser):
|
|
container_group = parser.getgroup("container")
|
|
container_group.addoption(
|
|
"--container",
|
|
action="store_true",
|
|
dest="container",
|
|
default=True,
|
|
help="Enable container mode",
|
|
)
|
|
container_group.addoption(
|
|
"--no-container",
|
|
action="store_false",
|
|
dest="container",
|
|
help="Disable container mode",
|
|
)
|
|
container_group.addoption(
|
|
"--container-engine",
|
|
action="store",
|
|
choices=["podman", "docker"],
|
|
default="podman",
|
|
help="Container engine to use",
|
|
)
|
|
|
|
|
|
def pytest_configure(config):
|
|
global ramalama_container
|
|
global ramalama_container_engine
|
|
ramalama_container = config.option.container
|
|
ramalama_container_engine = config.option.container_engine
|
|
|
|
|
|
@pytest.fixture()
|
|
def is_container(request):
|
|
return ramalama_container
|
|
|
|
|
|
@pytest.fixture()
|
|
def container_engine(request):
|
|
return ramalama_container_engine
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def test_model():
|
|
# Use different models for little-endian (e.g. x86_64, aarch64) and
|
|
# big-endian (e.g. s390x) architectures.
|
|
return "smollm:135m" if sys.byteorder == "little" else "stories-be:260k"
|
|
|
|
|
|
def get_podman_version():
|
|
"""Get podman version as a tuple of integers (major, minor, patch)."""
|
|
try:
|
|
import subprocess
|
|
|
|
result = subprocess.run(
|
|
["podman", "version", "--format", "{{.Client.Version}}"], capture_output=True, text=True, check=True
|
|
)
|
|
version_str = result.stdout.strip()
|
|
# Handle versions like "5.7.0-dev" by taking only the numeric part
|
|
version_parts = version_str.split('-')[0].split('.')
|
|
return tuple(int(x) for x in version_parts[:3])
|
|
except (subprocess.CalledProcessError, FileNotFoundError, ValueError):
|
|
return (0, 0, 0)
|
|
|
|
|
|
def is_podman_version_at_least(major, minor, patch=0):
|
|
"""Check if podman version is at least the specified version."""
|
|
current = get_podman_version()
|
|
required = (major, minor, patch)
|
|
return current >= required
|
|
|
|
|
|
skip_if_no_container = pytest.mark.skipif("not config.option.container", reason="no container mode is enabled")
|
|
skip_if_container = pytest.mark.skipif("config.option.container", reason="container mode is enabled")
|
|
skip_if_docker = pytest.mark.skipif(
|
|
"config.option.container_engine == 'docker'", reason="docker is the container engine"
|
|
)
|
|
|
|
skip_if_darwin = pytest.mark.skipif(platform.system() == "Darwin", reason="Darwin operating system")
|
|
skip_if_not_darwin = pytest.mark.skipif(platform.system() != "Darwin", reason="not Darwin operating system")
|
|
skip_if_gh_actions_darwin = pytest.mark.skipif(
|
|
platform.system() == "Darwin" and os.getenv("GITHUB_ACTIONS") == "true",
|
|
reason="GitHub Actions Darwin has not container support",
|
|
)
|
|
|
|
skip_if_windows = pytest.mark.skipif(platform.system() == "Windows", reason="Windows operating system")
|
|
skip_if_not_windows = pytest.mark.skipif(platform.system() != "Windows", reason="not Windows operating system")
|
|
|
|
skip_if_no_huggingface_cli = pytest.mark.skipif(shutil.which("hf") is None, reason="hf cli not installed")
|
|
|
|
skip_if_no_llama_bench = pytest.mark.skipif(shutil.which("llama-bench") is None, reason="llama-bench not installed")
|
|
|
|
xfail_if_windows = pytest.mark.xfail(
|
|
platform.system() == "Windows",
|
|
reason="Known failure on Windows",
|
|
)
|
|
|
|
skip_if_no_ollama = pytest.mark.skipif(shutil.which("ollama") is None, reason="ollama not installed")
|
|
|
|
skip_if_big_endian_machine = pytest.mark.skipif(sys.byteorder == "big", reason="skip big-endian architecture")
|
|
skip_if_little_endian_machine = pytest.mark.skipif(sys.byteorder == "little", reason="skip little-endian architecture")
|
|
|
|
skip_if_podman_too_old = pytest.mark.skipif(
|
|
not is_podman_version_at_least(5, 7, 0), reason="requires podman >= 5.7.0 for artifact support"
|
|
)
|