-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix typing, formatting and tests (#31)
* chore: fix ruff and run it in CI * chore: claudes attempt at typing * fix: use mypy instead of pyright and fix all errors * Fix types with stubs * Migrate workflow to pyright * Fix tests after type changes * Rename action to mypy * Add testing with vcr.py and a compose file * Fix tiktoken request
- Loading branch information
Showing
34 changed files
with
204,817 additions
and
1,668 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Type Checking | ||
|
||
on: | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
pyright: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.10' | ||
- name: Install uv | ||
run: pip install uv | ||
- name: Create venv | ||
run: uv venv | ||
- name: Install dependencies | ||
run: | | ||
uv sync | ||
- name: Run Pyright | ||
run: uv run pyright |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Ruff Linting and Formatting | ||
|
||
on: | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
ruff: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.10' | ||
- name: Install uv | ||
run: pip install uv | ||
- name: Create venv | ||
run: uv venv | ||
- name: Install dependencies | ||
run: | | ||
uv sync | ||
- name: Run Ruff linter | ||
run: uv run ruff check . | ||
- name: Run Ruff formatter | ||
run: uv run ruff format . --check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,30 @@ | ||
name: CI | ||
on: [workflow_dispatch, pull_request, push] | ||
name: Tests | ||
|
||
on: | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
test: | ||
if: false | ||
pytest: | ||
runs-on: ubuntu-latest | ||
steps: [uses: fastai/workflows/nbdev-ci@master] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.10' | ||
- name: Install uv | ||
run: pip install uv | ||
- name: Create venv | ||
run: uv venv | ||
- name: Install dependencies | ||
run: | | ||
uv sync | ||
- name: Start docker-compose | ||
run: docker compose up -d | ||
- name: Run Test | ||
run: uv run pytest | ||
- name: Logs | ||
run: docker compose logs | ||
- name: Stop docker-compose | ||
run: docker compose down |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
services: | ||
db: | ||
image: timescale/timescaledb-ha:pg16 | ||
ports: | ||
- "5432:5432" | ||
environment: | ||
- POSTGRES_PASSWORD=postgres | ||
- POSTGRES_USER=postgres | ||
- POSTGRES_DB=postgres | ||
- TIMESCALEDB_TELEMETRY=off | ||
volumes: | ||
- ./data:/var/lib/postgresql/data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,29 @@ | ||
import os | ||
|
||
import psycopg2 | ||
import pytest | ||
from dotenv import find_dotenv, load_dotenv | ||
|
||
# from dotenv import find_dotenv, load_dotenv | ||
|
||
@pytest.fixture | ||
def service_url() -> str: | ||
_ = load_dotenv(find_dotenv(), override=True) | ||
|
||
@pytest.fixture(scope="module") | ||
def setup_env_variables() -> None: | ||
os.environ.clear() | ||
os.environ["TIMESCALE_SERVICE_URL"] = "postgres://postgres:postgres@localhost:5432/postgres" | ||
os.environ["OPENAI_API_KEY"] = "fake key" | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def service_url(setup_env_variables: None) -> str: # noqa: ARG001 | ||
# _ = load_dotenv(find_dotenv(), override=True) | ||
return os.environ["TIMESCALE_SERVICE_URL"] | ||
|
||
|
||
@pytest.fixture(scope="module", autouse=True) | ||
def setup_db(service_url: str) -> None: | ||
conn = psycopg2.connect(service_url) | ||
with conn.cursor() as cursor: | ||
cursor.execute("CREATE EXTENSION IF NOT EXISTS ai CASCADE;") | ||
cursor.execute("CREATE SCHEMA IF NOT EXISTS temp;") | ||
conn.commit() | ||
conn.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import os | ||
from typing import Any | ||
|
||
import vcr | ||
|
||
vcr_cassette_path = os.path.join(os.path.dirname(__file__), "vcr_cassettes") | ||
|
||
|
||
def remove_set_cookie_header(response: dict[str, Any]): | ||
headers = response["headers"] | ||
headers_to_remove = ["set-cookie", "Set-Cookie"] | ||
|
||
for header in headers_to_remove: | ||
if header in headers: | ||
del headers[header] | ||
|
||
return response | ||
|
||
|
||
http_recorder = vcr.VCR( | ||
cassette_library_dir=vcr_cassette_path, | ||
record_mode="once", | ||
filter_headers=["authorization", "cookie"], | ||
before_record_response=remove_set_cookie_header, | ||
) |
Oops, something went wrong.