Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ricopinazo committed May 21, 2024
1 parent 64b69a2 commit 2ea2d91
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 35 deletions.
18 changes: 8 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
name: Release new version

on:
on:
workflow_dispatch:
inputs:
type:
description: 'Release type'
description: "Release type"
required: true
default: 'preview'
default: "preview"
type: choice
options:
- major
- minor
- fix
- preview
- release
- major
- minor
- fix
- preview
- release

jobs:
test:
uses: ./.github/workflows/tests.yml
secrets:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
release:
needs: test
runs-on: ubuntu-latest
Expand Down
23 changes: 3 additions & 20 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ name: tests
on:
push:
workflow_call:
secrets:
OPENAI_API_KEY:
required: true

jobs:
test:
Expand All @@ -22,24 +19,10 @@ jobs:
with:
python-version: "3.x"
- name: Install dependencies
run: python -m pip install -e .[test]
- name: Set environment variable using secret
run: echo "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" >> $GITHUB_ENV
- name: Run test suite
run: pytest -v
code-checks:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install black and mypy
run: python -m pip install black=="24.*" mypy=="1.*"
run: python -m pip install -e .[dev]
- name: Check style
run: black --check --diff .
- name: chek types
run: mypy .
- name: Run test suite
run: pytest -v
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ dist
.env
.DS_Store
.ipynb_checkpoints
experiments
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ issues = "https://github.com/ricopinazo/comai/issues"
comai = "comai.cli:app"

[project.optional-dependencies]
test = [
dev = [
"pytest",
"hatchling",
"types-requests==2.31.0.20240406",
Expand Down
4 changes: 2 additions & 2 deletions src/comai/animations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from contextlib import contextmanager
from typing import Generator, Iterator
from rich import print
from prompt_toolkit import prompt
import prompt_toolkit
from prompt_toolkit.styles import Style

from comai.prompt import prompt_str
Expand Down Expand Up @@ -68,7 +68,7 @@ def print_command_prompt(command: str):
message = [
("class:mark", ANSWER_PROMPT),
]
return prompt(message, default="%s" % command, style=style) # type: ignore
return prompt_toolkit.prompt(message, default="%s" % command, style=style) # type: ignore


def hide_cursor() -> None:
Expand Down
4 changes: 2 additions & 2 deletions src/comai/prompt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Literal
from simple_term_menu import TerminalMenu
from rich import print
from prompt_toolkit import prompt
import prompt_toolkit
from prompt_toolkit.styles import Style


Expand All @@ -18,7 +18,7 @@ def prompt_str(question: str, default: str) -> str:
("class:mark", "? "),
("class:question", f"{question.strip()} "),
]
return prompt(message, default="%s" % default, style=style) # type: ignore
return prompt_toolkit.prompt(message, default="%s" % default, style=style) # type: ignore


def prompt_options(question: str, options: list[str], default: str) -> str:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_comai.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import prompt_toolkit
from typing import Any
from typer.testing import CliRunner

from langchain_core.messages import AIMessageChunk
Expand All @@ -13,7 +15,11 @@ def mock_stream(*args, **kwargs):
for token in ["COMMAND", " ls", " END"]:
yield AIMessageChunk(content=token)

def mock_prompt(message: str, default: str, style: Any = None):
return default

monkeypatch.setattr(ChatOllama, "stream", mock_stream)
monkeypatch.setattr(prompt_toolkit, "prompt", mock_prompt)

result = runner.invoke(cli.app, ["show", "files"])
assert result.exit_code == 0
Expand Down

0 comments on commit 2ea2d91

Please sign in to comment.