Files
anti-plagiarism/services/worker-gost/tests/test_gost_7_0_5.py
jze9 ecc10a4413 test: юнит-суит L1/L2/L3 + ГОСТ (41 тест) и гейт в CI перед деплоем
Первый настоящий автоматический тест-суит проекта — раньше регрессии ловились
руками. Покрыта чистая логика детекции и форматирования (без БД/Redis/GPU/Ollama):

- worker-indexer: L1 Winnowing (точные совпадения, идемпотентность отпечатка,
  диапазон signed int64) и L2 MinHash LSH (шинглы, Jaccard, near-duplicate +
  upsert через in-memory-фолбэк).
- worker-gpu: L3 FAISS — возврат doc_id из PostgreSQL (IndexIDMap2),
  идемпотентность add_vectors (remove-before-add, без дублей), self-match ≈ 1,
  ранжирование. Прямо стережёт баги, из-за которых индекс переписывался.
- worker-gost: ГОСТ 7.1-2003 и 7.0.5-2008 — авторы (≤3 / 4+ «и др.»/et al.),
  статья/книга/web, DOI, порядок сортировки кириллица→латиница, стр. в ссылке.

Обвязка: per-service pytest.ini/conftest/requirements-test. scripts/run_tests.sh
гоняет тесты в изолированных python:3.11-slim контейнерах (не засоряя хост),
через Tsinghua-зеркало. CI: job `test` теперь гейтит `deploy` (needs: test) —
падение тестов блокирует прод-деплой. make test / make test-one SVC=...

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-11 17:11:08 +05:00

33 lines
1.1 KiB
Python
Raw Permalink 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.
"""Юнит-тесты кратких библиографических ссылок по ГОСТ Р 7.0.5-2008."""
from app.formatters.gost_7_0_5 import GOST705Formatter, format_short
def test_short_author_and_year():
assert format_short({"authors": [{"last_name": "Иванов"}], "year": 2023}) == "[Иванов, 2023]"
def test_short_without_author_uses_title():
out = format_short({"title": "Большая книга про всё сразу", "year": 2020})
assert out == "[Большая книга про..., 2020]"
def test_short_no_author_no_title():
assert format_short({"year": 2019}) == "[2019]"
def test_short_missing_year_defaults():
assert format_short({"authors": [{"last_name": "Петров"}]}) == "[Петров, б. г.]"
def test_inline_with_page():
f = GOST705Formatter()
doc = {"authors": [{"last_name": "Иванов"}], "year": 2023}
assert f.format_inline(doc, page="15") == "[Иванов, 2023, с. 15]"
def test_inline_without_page():
f = GOST705Formatter()
doc = {"authors": [{"last_name": "Иванов"}], "year": 2023}
assert f.format_inline(doc) == "[Иванов, 2023]"