arm-tabular-parser/api/tests/unit/test_fixtures_helpers.py
Andrey Epifancev e1559c9770 test: генератор синтетики и сценарии спеки на синтетических файлах
api/tests/synthetic: детерминированный генератор s01…s13 (openpyxl, метки времени книги и zip зафиксированы),
минимальный писатель BIFF12 для s13.xlsb (ruling R-9, читается pyxlsb), тесты сценариев спеки osv-parsing на файлах
из fixtures/osv/synthetic/ (таблица «файл → ожидания», s13 равен s02 кроме предупреждения xlsb), тест побайтовой
воспроизводимости генерации. synthetic_files() учитывает только файлы Excel (README.md каталога не файл набора).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vJkmBGKKqMoEMzvsXG3y2
2026-10-05 15:04:50 +04:00

60 lines
2.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Хелперы доступа к ../fixtures: каталог из ARM_KA_FIXTURES, список файлов ОСВ без синтетики, причина skip."""
from pathlib import Path
import pytest
from fixtures_helpers import (
FIXTURES_ENV,
fixtures_skip_reason,
osv_fixture_files,
resolve_fixtures_dir,
synthetic_files,
)
def test_env_overrides_fixtures_dir(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv(FIXTURES_ENV, str(tmp_path))
assert resolve_fixtures_dir() == tmp_path
def test_default_fixtures_dir_is_sibling_of_repository(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.delenv(FIXTURES_ENV, raising=False)
assert resolve_fixtures_dir() == Path(__file__).resolve().parents[4] / "fixtures"
def test_no_osv_directory_gives_no_files(tmp_path: Path) -> None:
assert osv_fixture_files(tmp_path) == []
assert synthetic_files(tmp_path) == []
def test_synthetic_excluded_and_foreign_files_ignored(tmp_path: Path) -> None:
osv = tmp_path / "osv"
(osv / "rb").mkdir(parents=True)
(osv / "synthetic").mkdir()
(osv / "rb" / "b.xlsx").write_bytes(b"")
(osv / "a.xls").write_bytes(b"")
(osv / "c.xlsb").write_bytes(b"")
(osv / ".DS_Store").write_bytes(b"")
(osv / "notes.txt").write_bytes(b"")
(osv / "synthetic" / "s.xlsx").write_bytes(b"")
(osv / "synthetic" / ".gitkeep").write_bytes(b"")
(osv / "synthetic" / "README.md").write_bytes(b"")
assert osv_fixture_files(tmp_path) == [osv / "a.xls", osv / "c.xlsb", osv / "rb" / "b.xlsx"]
assert synthetic_files(tmp_path) == [osv / "synthetic" / "s.xlsx"]
def test_skip_reason_mentions_env_and_path(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
missing = tmp_path / "нет-такого"
monkeypatch.setenv(FIXTURES_ENV, str(missing))
reason = fixtures_skip_reason()
assert reason is not None
assert FIXTURES_ENV in reason
assert str(missing) in reason
def test_skip_reason_none_when_available(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
(tmp_path / "osv").mkdir()
monkeypatch.setenv(FIXTURES_ENV, str(tmp_path))
assert fixtures_skip_reason() is None