diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml new file mode 100644 index 0000000..34d506b --- /dev/null +++ b/.github/workflows/pytest.yml @@ -0,0 +1,30 @@ +name: Run Tests +on: + push: + paths: + - 'experiments/**' + - 'backend/**' + - 'requirements.txt' + - '.github/workflows/pytest.yml' + pull_request: + paths: + - 'experiments/**' + - 'backend/**' + - 'requirements.txt' + - '.github/workflows/pytest.yml' +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.13' + cache: 'pip' + - name: Install dependencies + run: | + python -m venv .venv + .venv/bin/pip install --upgrade pip + .venv/bin/pip install -r requirements.txt + - name: Run tests + run: .venv/bin/pytest -v diff --git a/.gitignore b/.gitignore index f4056c4..384891a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ **/.env -**/.venv \ No newline at end of file +**/.venv +**/__pycache__ +**/.ipynb_checkpoints/ +**/.virtual_documents/ \ No newline at end of file diff --git a/Makefile b/Makefile index 99c54f8..d9eaac5 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,10 @@ BUILDDIR := build TEX := main.tex JOBNAME := main PDF := paper/$(BUILDDIR)/$(JOBNAME).pdf +VENV := .venv +PYTHON := $(VENV)/bin/python +PIP := $(VENV)/bin/pip +PYTEST := $(VENV)/bin/pytest .DEFAULT_GOAL := help @@ -35,5 +39,14 @@ clean: $(LATEXMK) -C -jobname=$(JOBNAME) -outdir=../$(BUILDDIR) || true rm -rf paper/$(BUILDDIR)/* +$(VENV): + python3 -m venv $(VENV) + $(PIP) install --upgrade pip -.PHONY: all pdf clean watch run.webapp +install: $(VENV) + $(PIP) install -r requirements.txt + +test: $(VENV) + $(PYTEST) -v + +.PHONY: all pdf clean watch run.webapp install test diff --git a/experiments/agents/test.py b/experiments/agents/test.py index 6d5c769..e7cbeb2 100644 --- a/experiments/agents/test.py +++ b/experiments/agents/test.py @@ -1,6 +1,7 @@ import pytest import asyncio from experiments.agents.agent import get_agent, AgentTypes +import os def test_agent_init(): @@ -16,8 +17,10 @@ def test_invalid_agent(): @pytest.mark.asyncio +@pytest.mark.skipif("OPENAI_API_KEY" not in os.environ, reason="OPENAI_API_KEY not set") async def test_agent_execution(): agent = get_agent(AgentTypes.GENERIC_BROWSER_USE_AGENT, goal="get page title", url="https://example.com", timeout=60) + result = await agent.act() assert result assert agent.final_result() diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..2122ae5 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,7 @@ +[pytest] +testpaths = experiments +python_files = test*.py +python_classes = Test* +python_functions = test_* +asyncio_mode = auto +asyncio_default_fixture_loop_scope = function diff --git a/requirements.txt b/requirements.txt index af84760..70db3f0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,3 +8,4 @@ graphviz browser-use pytest pytest-asyncio +uv