From 9ff8e2367b316da3fae07ec048e0aa30db661573 Mon Sep 17 00:00:00 2001 From: David de la Iglesia Castro Date: Thu, 28 Nov 2024 18:24:50 +0100 Subject: [PATCH] Add tests workflow (#18) * Add new `tests` workflow * Use pip cache * Unify env setup. Drop UV in favor of setup-python * Update tests --- .github/workflows/docs.yaml | 2 +- .github/workflows/lint.yaml | 20 ++++++------- .github/workflows/tests.yaml | 28 +++++++++++++++++++ .../test_model_load_and_inference.py | 17 ++--------- 4 files changed, 40 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/tests.yaml diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index 31b3304..4e953e3 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -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]' diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 16beccd..be086f3 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -12,16 +12,16 @@ 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: @@ -29,6 +29,4 @@ jobs: 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 diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..a78085e --- /dev/null +++ b/.github/workflows/tests.yaml @@ -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 diff --git a/tests/integration/test_model_load_and_inference.py b/tests/integration/test_model_load_and_inference.py index 7a248e7..ecdba1e 100644 --- a/tests/integration/test_model_load_and_inference.py +++ b/tests/integration/test_model_load_and_inference.py @@ -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(): @@ -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"