Skip to content

Commit

Permalink
Fix types and lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinika committed Apr 22, 2024
1 parent 400aabd commit 1335ec9
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 15 deletions.
8 changes: 5 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.3
rev: v0.4.1
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.9.0"
hooks:
- id: mypy
args: [--strict, --ignore-missing-imports]
args: [--strict]
additional_dependencies:
- "pydantic"
- "fastapi"
- "sqlalchemy"
- "pytest"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ poetry run pytest -s --pdb # helpful for debugging tests

```sh
sudo docker compose -f docker-compose.yml -p expenses_server down --remove-orphans --volumes
```
```
2 changes: 1 addition & 1 deletion expenses_server/db_models/expense.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from uuid import uuid4, UUID
from sqlalchemy import TIMESTAMP, ForeignKey, Text, func, types, text
from sqlalchemy import TIMESTAMP, ForeignKey, Text, func, types
from sqlalchemy.orm import relationship, Mapped, mapped_column
from .core import Base
from typing import TYPE_CHECKING
Expand Down
3 changes: 1 addition & 2 deletions expenses_server/dtos/expenses.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from datetime import datetime
from typing import Annotated
from pydantic import UUID4, BaseModel, Field, computed_field, field_serializer
from pydantic import UUID4, BaseModel, field_serializer
from .categories import Category
from .accounts import Account
from .currencies import CurrencyEnum
Expand Down
1 change: 0 additions & 1 deletion expenses_server/routes/expenses.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from curses.panel import update_panels
from http import HTTPStatus
from typing import cast
from fastapi import APIRouter, Depends, HTTPException
Expand Down
4 changes: 2 additions & 2 deletions expenses_server/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from http import HTTPStatus
from typing import Generator
from typing import Any, Generator
from fastapi.testclient import TestClient
import pytest
from expenses_server.main import app
Expand All @@ -15,7 +15,7 @@ def test_client() -> Generator[TestClient, None, None]:
@pytest.fixture()
def test_expenses(
test_client: TestClient,
) -> Generator[tuple[TestClient, list[dict]], None, None]:
) -> Generator[tuple[TestClient, list[dict[str, Any]]], None, None]:
expense1 = create_mock_expense(test_client)
print("EXPENSE1", expense1)
expense2 = create_mock_expense(test_client, extra={"account_id": 2})
Expand Down
5 changes: 4 additions & 1 deletion expenses_server/tests/test_delete_expense.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from http import HTTPStatus
from typing import Any
from fastapi.testclient import TestClient


def test_delete_expenses(test_expenses: tuple[TestClient, list[dict]]) -> None:
def test_delete_expenses(
test_expenses: tuple[TestClient, list[dict[str, Any]]],
) -> None:
client, mock_expenses = test_expenses
expense_id = mock_expenses[0]["id"]
response = client.delete(f"/api/expenses/{expense_id}")
Expand Down
3 changes: 2 additions & 1 deletion expenses_server/tests/test_get_expense.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import Any
from fastapi.testclient import TestClient


def test_get_expense(test_expenses: tuple[TestClient, list[dict]]) -> None:
def test_get_expense(test_expenses: tuple[TestClient, list[dict[str, Any]]]) -> None:
client, mock_expenses = test_expenses
expense_id = mock_expenses[0]["id"]
response = client.get(f"/api/expenses/{expense_id}")
Expand Down
3 changes: 2 additions & 1 deletion expenses_server/tests/test_update_expense.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from typing import Any
from fastapi.testclient import TestClient
import copy


def test_update_expense(test_expenses: tuple[TestClient, list[dict]]) -> None:
def test_update_expense(test_expenses: tuple[TestClient, list[dict[str, Any]]]) -> None:
client, mock_expenses = test_expenses
expense_before_update = mock_expenses[0]

Expand Down
4 changes: 2 additions & 2 deletions expenses_server/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

def create_mock_expense(
client: TestClient, extra: dict[str, Any] | None = None
) -> dict:
) -> dict[str, Any]:
payload = (
{
"amount": 10,
Expand All @@ -25,4 +25,4 @@ def create_mock_expense(
)
response = client.post("/api/expenses", json=payload)
assert response.status_code == 200
return cast(dict, response.json())
return cast(dict[str, Any], response.json())

0 comments on commit 1335ec9

Please sign in to comment.