Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A pytest flow. #80

Merged
merged 14 commits into from
Dec 19, 2023
43 changes: 43 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Python package

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
pytest:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Install taskweaver
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -e .
- name: Test with pytest
run: |
pip install pytest pytest-cov
pytest tests/unit_tests --collect-only
pytest tests/unit_tests -v --junitxml=junit/test-results-${{ matrix.python-version }}.xml --cov=com --cov-report=xml --cov-report=html
- name: Upload pytest test results
uses: actions/upload-artifact@v3
with:
name: pytest-results-${{ matrix.python-version }}
path: junit/test-results-${{ matrix.python-version }}.xml
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}

3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ pyyaml>=6.0
scikit-learn>=1.2.2
click>=8.0.1
urllib3>=1.26.17
jsonschema==4.17.3
jsonschema==4.20.0
injector>=0.21.0
ijson>=3.2.3
requests>=2.31.0

# Code Execution related
ipykernel==6.26.0
Expand Down
11 changes: 8 additions & 3 deletions tests/unit_tests/test_embedding.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

import pytest
from injector import Injector

Expand All @@ -7,7 +9,10 @@
from taskweaver.llm.openai import OpenAIService
from taskweaver.llm.sentence_transformer import SentenceTransformerService

IN_GITHUB_ACTIONS = os.getenv("GITHUB_ACTIONS") == "true"


@pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="Test doesn't work in Github Actions.")
def test_sentence_transformer_embedding():
app_injector = Injector([])
app_config = AppConfigSource(
Expand All @@ -29,7 +34,7 @@ def test_sentence_transformer_embedding():
assert len(embedding1[1]) == 768


@pytest.mark.skip(reason="missing api key")
@pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="Test doesn't work in Github Actions.")
def test_openai_embedding():
app_injector = Injector()
app_config = AppConfigSource(
Expand All @@ -51,7 +56,7 @@ def test_openai_embedding():
assert len(embedding1[1]) == 1536


@pytest.mark.skip(reason="missing api key")
@pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="Test doesn't work in Github Actions.")
def test_ollama_embedding():
app_injector = Injector()
app_config = AppConfigSource(
Expand All @@ -71,7 +76,7 @@ def test_ollama_embedding():
assert len(embedding1[1]) == 4096


@pytest.mark.skip(reason="missing api key")
@pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="Test doesn't work in Github Actions.")
def test_qwen_embedding():
app_injector = Injector()
app_config = AppConfigSource(
Expand Down
4 changes: 4 additions & 0 deletions tests/unit_tests/test_plugin_selector.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import os

import pytest
from injector import Injector

from taskweaver.code_interpreter.code_generator.plugin_selection import PluginSelector
from taskweaver.config.config_mgt import AppConfigSource
from taskweaver.memory.plugin import PluginModule

IN_GITHUB_ACTIONS = os.getenv("GITHUB_ACTIONS") == "true"


@pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="Test doesn't work in Github Actions.")
def test_plugin_selector():
app_injector = Injector([PluginModule])
app_config = AppConfigSource(
Expand Down