- requirements: openpyxl==3.1.5, pyxlsb==1.0.10, xlrd==2.0.2, et_xmlfile==2.0.0 (транзитивная) - tests/fixtures_helpers.py, conftest: фикстура fixtures_dir, параметризация osv_file/synthetic_file, skip маркера fixtures - pyproject: mypy ignore_missing_imports для openpyxl/xlrd/pyxlsb, disallow_untyped_defs для src.parser.* Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vJkmBGKKqMoEMzvsXG3y2
46 lines
1.9 KiB
Python
46 lines
1.9 KiB
Python
"""Доступ к реальным данным из `../fixtures` (отдельный репозиторий, внутренний доступ)."""
|
||
|
||
import os
|
||
from pathlib import Path
|
||
|
||
FIXTURES_ENV = "ARM_KA_FIXTURES"
|
||
OSV_EXTENSIONS = frozenset({".xls", ".xlsx", ".xlsb"})
|
||
_SYNTHETIC = "synthetic"
|
||
|
||
|
||
def resolve_fixtures_dir() -> Path:
|
||
"""Каталог фикстур: `ARM_KA_FIXTURES` или соседний с репозиторием `fixtures/` (workspace)."""
|
||
override = os.environ.get(FIXTURES_ENV)
|
||
if override:
|
||
return Path(override)
|
||
return Path(__file__).resolve().parents[3] / "fixtures"
|
||
|
||
|
||
def fixtures_skip_reason() -> str | None:
|
||
"""Причина пропуска тестов на фикстурах (None — каталог доступен). Текст называет переменную и путь (OQ-81)."""
|
||
root = resolve_fixtures_dir()
|
||
if (root / "osv").is_dir():
|
||
return None
|
||
return f"каталог фикстур не найден: {root} (задайте {FIXTURES_ENV}=<путь к репозиторию fixtures>)"
|
||
|
||
|
||
def osv_fixture_files(root: Path) -> list[Path]:
|
||
"""Все `*.xls/*.xlsx/*.xlsb` под `root/osv`, кроме каталога synthetic; отсортированы."""
|
||
osv = root / "osv"
|
||
if not osv.is_dir():
|
||
return []
|
||
synthetic = osv / _SYNTHETIC
|
||
return sorted(
|
||
path
|
||
for path in osv.rglob("*")
|
||
if path.is_file() and path.suffix.lower() in OSV_EXTENSIONS and synthetic not in path.parents
|
||
)
|
||
|
||
|
||
def synthetic_files(root: Path) -> list[Path]:
|
||
"""Файлы `root/osv/synthetic/*` (скрытые, вроде `.gitkeep`, не считаются); отсортированы."""
|
||
directory = root / "osv" / _SYNTHETIC
|
||
if not directory.is_dir():
|
||
return []
|
||
return sorted(path for path in directory.iterdir() if path.is_file() and not path.name.startswith("."))
|