Skip to content

Commit 0abaa2b

Browse files
committed
Tests
1 parent cdec706 commit 0abaa2b

File tree

4 files changed

+167
-14
lines changed

4 files changed

+167
-14
lines changed

.github/workflows/python-package.yml

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,66 @@ on:
55
branches: ["main", "development"]
66
pull_request:
77
branches: ["main", "development"]
8+
workflow_dispatch: # Allow manual triggering
89

910
jobs:
10-
build:
11-
runs-on: ubuntu-latest
11+
test:
12+
name: Test Python ${{ matrix.python-version }} on ${{ matrix.os }}
13+
runs-on: ${{ matrix.os }}
1214
strategy:
13-
fail-fast: true
15+
fail-fast: false # Don't cancel other jobs if one fails
1416
matrix:
17+
os: [ubuntu-latest, windows-latest, macos-latest]
1518
python-version: ["3.10", "3.12"]
1619

1720
steps:
18-
- uses: actions/checkout@v3
21+
- uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0 # Fetch all history for proper versioning
24+
1925
- name: Set up Python ${{ matrix.python-version }}
20-
uses: actions/setup-python@v3
26+
uses: actions/setup-python@v4
2127
with:
2228
python-version: ${{ matrix.python-version }}
29+
cache: 'pip' # Cache pip dependencies
30+
2331
- name: Install poetry
32+
shell: bash
33+
run: |
34+
python -m pip install --upgrade pip
35+
pip install poetry
36+
37+
- name: Configure poetry
38+
shell: bash
2439
run: |
25-
curl -sSL https://install.python-poetry.org | python3 -
40+
poetry config virtualenvs.create true
41+
poetry config virtualenvs.in-project true
42+
43+
- name: Cache poetry dependencies
44+
uses: actions/cache@v3
45+
with:
46+
path: ./.venv
47+
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
48+
2649
- name: Install dependencies
50+
shell: bash
2751
run: |
28-
# Ensure dependencies are installed without relying on a lock file.
29-
poetry update
30-
poetry install -E server
31-
- name: Test with pytest
52+
poetry install --no-interaction --all-extras
53+
54+
- name: Run tests
55+
shell: bash
3256
run: |
33-
poetry run pytest -s -x -k test_
57+
poetry run pytest tests/ -v --color=yes
3458
env:
3559
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
60+
PYTHONUNBUFFERED: "1" # For real-time test output
61+
62+
- name: Upload test results
63+
if: always() # Run even if tests fail
64+
uses: actions/upload-artifact@v3
65+
with:
66+
name: test-results-${{ matrix.os }}-${{ matrix.python-version }}
67+
path: |
68+
.pytest_cache
69+
pytest-report.xml
70+
if-no-files-found: ignore

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ A modern command line assistant.
77
## Install
88

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

1313
## Usage
@@ -53,7 +53,11 @@ interpreter --profile 4o
5353
interpreter --tools interpreter,editor,gui
5454
```
5555

56-
## Python Usage
56+
## Python
57+
58+
```bash
59+
pip install open-interpreter
60+
```
5761

5862
```python
5963
from interpreter import Interpreter

interpreter/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
curl openinterpreter.com/cli | bash
1+
curl openinterpreter.com/cli | sh
22
interpreter

tests/test_cli.py

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import os
2+
import subprocess
3+
import sys
4+
from unittest.mock import MagicMock, patch
5+
6+
import pytest
7+
8+
from interpreter.cli import _parse_list_arg, load_interpreter, parse_args
9+
from interpreter.profiles import Profile
10+
11+
12+
def test_version_flag():
13+
# Test --version flag
14+
result = subprocess.run(
15+
["interpreter", "--version"], capture_output=True, text=True
16+
)
17+
assert result.returncode == 0
18+
assert "Open Interpreter" in result.stdout
19+
20+
21+
def test_help_flag():
22+
# Test --help flag
23+
result = subprocess.run(["interpreter", "--help"], capture_output=True, text=True)
24+
assert result.returncode == 0
25+
assert "usage:" in result.stdout.lower() or "help" in result.stdout.lower()
26+
27+
28+
def test_parse_list_arg():
29+
# Test parsing JSON list
30+
assert _parse_list_arg('["a", "b", "c"]') == ["a", "b", "c"]
31+
32+
# Test parsing comma-separated list
33+
assert _parse_list_arg("a,b,c") == ["a", "b", "c"]
34+
35+
# Test empty input
36+
assert _parse_list_arg("") == []
37+
38+
# Test whitespace handling
39+
assert _parse_list_arg("a, b, c ") == ["a", "b", "c"]
40+
41+
42+
def test_model_flag():
43+
# Test --model flag
44+
with patch.object(sys, "argv", ["interpreter", "--model", "gpt-4"]):
45+
args = parse_args()
46+
assert args["model"] == "gpt-4"
47+
48+
49+
def test_api_key_flag():
50+
# Test --api-key flag
51+
test_key = "test-key-123"
52+
with patch.object(sys, "argv", ["interpreter", "--api-key", test_key]):
53+
args = parse_args()
54+
assert args["api_key"] == test_key
55+
56+
57+
def test_temperature_flag():
58+
# Test --temperature flag
59+
with patch.object(sys, "argv", ["interpreter", "--temperature", "0.7"]):
60+
args = parse_args()
61+
assert args["temperature"] == "0.7"
62+
63+
64+
def test_auto_run_flag():
65+
# Test --auto-run flag
66+
with patch.object(sys, "argv", ["interpreter", "--auto-run"]):
67+
args = parse_args()
68+
assert args["auto_run"] is True
69+
70+
71+
def test_debug_flag():
72+
# Test --debug flag
73+
with patch.object(sys, "argv", ["interpreter", "--debug"]):
74+
args = parse_args()
75+
assert args["debug"] is True
76+
77+
78+
def test_tool_calling_flags():
79+
# Test --no-tool-calling flag
80+
with patch.object(sys, "argv", ["interpreter", "--no-tool-calling"]):
81+
args = parse_args()
82+
assert args["tool_calling"] is False
83+
84+
85+
def test_interactive_flags():
86+
# Test --interactive flag
87+
with patch.object(sys, "argv", ["interpreter", "--interactive"]):
88+
args = parse_args()
89+
assert args["interactive"] is True
90+
91+
# Test --no-interactive flag
92+
with patch.object(sys, "argv", ["interpreter", "--no-interactive"]):
93+
args = parse_args()
94+
assert args["interactive"] is False
95+
96+
97+
def test_direct_input():
98+
# Test direct input without flags
99+
test_input = "Hello interpreter"
100+
with patch.object(sys, "argv", ["interpreter", test_input]):
101+
args = parse_args()
102+
assert args["input"] == f"i {test_input}"
103+
104+
105+
@pytest.mark.asyncio
106+
async def test_load_interpreter():
107+
# Test interpreter loading with custom settings
108+
args = {"model": "gpt-4", "temperature": 0.7, "auto_run": True, "debug": True}
109+
interpreter = load_interpreter(args)
110+
111+
assert interpreter.model == "gpt-4"
112+
assert interpreter.temperature == 0.7
113+
assert interpreter.auto_run is True
114+
assert interpreter.debug is True

0 commit comments

Comments
 (0)