mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
[ed9c5b59] fix(tests): resolve 3 mypy arg-type errors in test_conventions_resolve using typing.cast (#244) (#245) (#246)
Use cast("ProjectTable", project) at the 3 _resolve() call sites where
SimpleNamespace was passed as a ProjectTable argument, satisfying mypy
without any # type: ignore suppressions. ProjectTable import is kept
under TYPE_CHECKING since the quoted cast form requires no runtime
symbol; cast is imported from typing for the runtime call.
Co-authored-by: Backend Developer 1 <be-dev-1@agents.roboco.dev>
This commit is contained in:
co-authored by
Backend Developer 1
parent
fe029fe34b
commit
a8e5fa6467
@@ -4,13 +4,15 @@ from __future__ import annotations
|
||||
|
||||
import subprocess
|
||||
from types import SimpleNamespace
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, cast
|
||||
|
||||
from roboco.services.conventions import ConventionsService
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pathlib import Path
|
||||
|
||||
from roboco.db.tables import ProjectTable
|
||||
|
||||
|
||||
def _git_repo(root: Path) -> str:
|
||||
(root / "roboco" / "services").mkdir(parents=True)
|
||||
@@ -37,7 +39,7 @@ def _svc() -> ConventionsService:
|
||||
def test_resolve_reads_clone_head_and_backfills(tmp_path: Path) -> None:
|
||||
sha = _git_repo(tmp_path)
|
||||
project = SimpleNamespace(workspace_path=None, head_commit=None, slug="p")
|
||||
root, head = _svc()._resolve(project, tmp_path)
|
||||
root, head = _svc()._resolve(cast("ProjectTable", project), tmp_path)
|
||||
assert root == tmp_path
|
||||
assert head == sha
|
||||
# The backfill: the resolved path + real HEAD are persisted on the project.
|
||||
@@ -49,7 +51,7 @@ def test_resolve_non_git_path_keeps_persisted_head(tmp_path: Path) -> None:
|
||||
project = SimpleNamespace(
|
||||
workspace_path=str(tmp_path), head_commit="deadbeef", slug="p"
|
||||
)
|
||||
_root, head = _svc()._resolve(project, None)
|
||||
_root, head = _svc()._resolve(cast("ProjectTable", project), None)
|
||||
# A non-git legacy path must not clobber the persisted head_commit.
|
||||
assert head == "deadbeef"
|
||||
assert project.head_commit == "deadbeef"
|
||||
@@ -57,7 +59,7 @@ def test_resolve_non_git_path_keeps_persisted_head(tmp_path: Path) -> None:
|
||||
|
||||
def test_resolve_no_workspace_returns_none_root() -> None:
|
||||
project = SimpleNamespace(workspace_path=None, head_commit=None, slug="p")
|
||||
root, head = _svc()._resolve(project, None)
|
||||
root, head = _svc()._resolve(cast("ProjectTable", project), None)
|
||||
assert root is None
|
||||
assert head == "HEAD"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user