- pyproject:hatchling + src 布局,核心依赖 psycopg/pydantic/pyyaml/cel-python - FastAPI 归入 [api] 可选依赖,开发依赖走 PEP 735 dependency-groups - 建立分层目录:ontology/compiler/storage/repository/graph/timeseries/expr/rules/api - errors.py 统一异常基类;py.typed 标记类型完整 - ruff(100) + pytest 配置;冒烟测试校验核心包不引入 fastapi/uvicorn
39 lines
1.0 KiB
Python
39 lines
1.0 KiB
Python
"""骨架冒烟测试:包能导入,且核心包不拉起 web 依赖(AGENTS.md §5 硬规则)。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import subprocess
|
|
import sys
|
|
|
|
|
|
def test_package_imports() -> None:
|
|
import adapter_python_pg
|
|
|
|
assert adapter_python_pg.__version__ == "0.1.0"
|
|
|
|
|
|
def test_core_import_does_not_pull_fastapi() -> None:
|
|
"""在干净的解释器里 import 核心包,sys.modules 不应出现 fastapi / uvicorn。"""
|
|
code = (
|
|
"import sys, adapter_python_pg;"
|
|
"assert 'fastapi' not in sys.modules, 'core imported fastapi';"
|
|
"assert 'uvicorn' not in sys.modules, 'core imported uvicorn';"
|
|
"print('ok')"
|
|
)
|
|
result = subprocess.run(
|
|
[sys.executable, "-c", code],
|
|
capture_output=True,
|
|
text=True,
|
|
)
|
|
assert result.returncode == 0, result.stderr
|
|
assert result.stdout.strip() == "ok"
|
|
|
|
|
|
def test_unknown_attribute_raises() -> None:
|
|
import pytest
|
|
|
|
import adapter_python_pg
|
|
|
|
with pytest.raises(AttributeError):
|
|
_ = adapter_python_pg.nonexistent_attribute
|