Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KillianLucas committed Dec 4, 2024
1 parent cdec706 commit 0abaa2b
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 14 deletions.
57 changes: 46 additions & 11 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,66 @@ on:
branches: ["main", "development"]
pull_request:
branches: ["main", "development"]
workflow_dispatch: # Allow manual triggering

jobs:
build:
runs-on: ubuntu-latest
test:
name: Test Python ${{ matrix.python-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
fail-fast: false # Don't cancel other jobs if one fails
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.10", "3.12"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for proper versioning

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip' # Cache pip dependencies

- name: Install poetry
shell: bash
run: |
python -m pip install --upgrade pip
pip install poetry
- name: Configure poetry
shell: bash
run: |
curl -sSL https://install.python-poetry.org | python3 -
poetry config virtualenvs.create true
poetry config virtualenvs.in-project true
- name: Cache poetry dependencies
uses: actions/cache@v3
with:
path: ./.venv
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}

- name: Install dependencies
shell: bash
run: |
# Ensure dependencies are installed without relying on a lock file.
poetry update
poetry install -E server
- name: Test with pytest
poetry install --no-interaction --all-extras
- name: Run tests
shell: bash
run: |
poetry run pytest -s -x -k test_
poetry run pytest tests/ -v --color=yes
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
PYTHONUNBUFFERED: "1" # For real-time test output

- name: Upload test results
if: always() # Run even if tests fail
uses: actions/upload-artifact@v3
with:
name: test-results-${{ matrix.os }}-${{ matrix.python-version }}
path: |
.pytest_cache
pytest-report.xml
if-no-files-found: ignore
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A modern command line assistant.
## Install

```bash
pip install open-interpreter
curl https://raw.githubusercontent.com/OpenInterpreter/open-interpreter/refs/heads/development/installers/new-installer.sh | sh
```

## Usage
Expand Down Expand Up @@ -53,7 +53,11 @@ interpreter --profile 4o
interpreter --tools interpreter,editor,gui
```

## Python Usage
## Python

```bash
pip install open-interpreter
```

```python
from interpreter import Interpreter
Expand Down
2 changes: 1 addition & 1 deletion interpreter/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
curl openinterpreter.com/cli | bash
curl openinterpreter.com/cli | sh
interpreter
114 changes: 114 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import os
import subprocess
import sys
from unittest.mock import MagicMock, patch

import pytest

from interpreter.cli import _parse_list_arg, load_interpreter, parse_args
from interpreter.profiles import Profile


def test_version_flag():
# Test --version flag
result = subprocess.run(
["interpreter", "--version"], capture_output=True, text=True
)
assert result.returncode == 0
assert "Open Interpreter" in result.stdout


def test_help_flag():
# Test --help flag
result = subprocess.run(["interpreter", "--help"], capture_output=True, text=True)
assert result.returncode == 0
assert "usage:" in result.stdout.lower() or "help" in result.stdout.lower()


def test_parse_list_arg():
# Test parsing JSON list
assert _parse_list_arg('["a", "b", "c"]') == ["a", "b", "c"]

# Test parsing comma-separated list
assert _parse_list_arg("a,b,c") == ["a", "b", "c"]

# Test empty input
assert _parse_list_arg("") == []

# Test whitespace handling
assert _parse_list_arg("a, b, c ") == ["a", "b", "c"]


def test_model_flag():
# Test --model flag
with patch.object(sys, "argv", ["interpreter", "--model", "gpt-4"]):
args = parse_args()
assert args["model"] == "gpt-4"


def test_api_key_flag():
# Test --api-key flag
test_key = "test-key-123"
with patch.object(sys, "argv", ["interpreter", "--api-key", test_key]):
args = parse_args()
assert args["api_key"] == test_key


def test_temperature_flag():
# Test --temperature flag
with patch.object(sys, "argv", ["interpreter", "--temperature", "0.7"]):
args = parse_args()
assert args["temperature"] == "0.7"


def test_auto_run_flag():
# Test --auto-run flag
with patch.object(sys, "argv", ["interpreter", "--auto-run"]):
args = parse_args()
assert args["auto_run"] is True


def test_debug_flag():
# Test --debug flag
with patch.object(sys, "argv", ["interpreter", "--debug"]):
args = parse_args()
assert args["debug"] is True


def test_tool_calling_flags():
# Test --no-tool-calling flag
with patch.object(sys, "argv", ["interpreter", "--no-tool-calling"]):
args = parse_args()
assert args["tool_calling"] is False


def test_interactive_flags():
# Test --interactive flag
with patch.object(sys, "argv", ["interpreter", "--interactive"]):
args = parse_args()
assert args["interactive"] is True

# Test --no-interactive flag
with patch.object(sys, "argv", ["interpreter", "--no-interactive"]):
args = parse_args()
assert args["interactive"] is False


def test_direct_input():
# Test direct input without flags
test_input = "Hello interpreter"
with patch.object(sys, "argv", ["interpreter", test_input]):
args = parse_args()
assert args["input"] == f"i {test_input}"


@pytest.mark.asyncio
async def test_load_interpreter():
# Test interpreter loading with custom settings
args = {"model": "gpt-4", "temperature": 0.7, "auto_run": True, "debug": True}
interpreter = load_interpreter(args)

assert interpreter.model == "gpt-4"
assert interpreter.temperature == 0.7
assert interpreter.auto_run is True
assert interpreter.debug is True

0 comments on commit 0abaa2b

Please sign in to comment.