Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: ci
on: [ push, pull_request ]
jobs:
ci:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9, "3.10", 3.11, 3.12, 3.13, 3.14]
steps:
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-pip-
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- name: Install and configure Poetry
run: |
pip install -U pip poetry
poetry config virtualenvs.create false
- name: Run CI
run: make ci
11 changes: 10 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ tortoise_orm = "examples.TORTOISE_ORM"
[tool.mypy]
pretty = true
check_untyped_defs = true
ignore_missing_imports = true
warn_unused_ignores = true

[tool.ruff]
line-length = 100
Expand All @@ -60,3 +60,12 @@ extend-select = [
"UP", # https://docs.astral.sh/ruff/rules/#pyupgrade-up
"RUF100", # https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf
]

[tool.coverage.report]
show_missing = true
exclude_also = [
"pragma: no cover",
"if TYPE_CHECKING:",
"@overload",
'if __name == "__main__":',
]
31 changes: 31 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
from pathlib import Path
from unittest.mock import patch

import pytest
from asyncclick import BadOptionUsage, ClickException, Command, Context

import examples
from tortoise_cli.utils import get_tortoise_config, tortoise_orm_config

EMPTY_TORTOISE_ORM = None


def test_tortoise_orm_config():
assert tortoise_orm_config() == "examples.TORTOISE_ORM"
with patch.dict(os.environ, {"TORTOISE_ORM": "app.settings.TORTOISE_ORM"}):
assert tortoise_orm_config() == "app.settings.TORTOISE_ORM"
with patch.object(Path, "read_text", return_value=""):
assert tortoise_orm_config() == ""


def test_get_tortoise_config():
ctx = Context(Command("shell"))
assert get_tortoise_config(ctx, tortoise_orm_config()) == examples.TORTOISE_ORM
with pytest.raises(
ClickException,
match="Error while importing configuration module: No module named 'settings'",
):
assert get_tortoise_config(ctx, "settings.TORTOISE_ORM")
with pytest.raises(BadOptionUsage):
assert get_tortoise_config(ctx, "tests.test_utils.EMPTY_TORTOISE_ORM")