test(generator): добавлен pytest и реорганизованы тесты

- Зачем:
  - были только standalone скрипты без системы запуска
  - нужна стандартная система тестирования для CI/CD
- Что:
  - добавлен pytest и pytest-asyncio в requirements.txt
  - создана директория tests/ с conftest.py (fixtures)
  - разделены тесты по модулям: test_config, test_generation, test_history
  - добавлены команды в Makefile: generator-test, generator-test-build, generator-test-cov
  - удалены устаревшие test_local.py и test_comprehensive.py
  - обновлена документация в README.md
- Проверка:
  - make generator-test — 23/23 тестов пройдено
This commit is contained in:
2026-06-09 17:27:16 +03:00
committed by Dmitry Dementiev
parent 04541677ff
commit 36ecbc62b1
9 changed files with 469 additions and 631 deletions
+59
View File
@@ -0,0 +1,59 @@
"""
Pytest fixtures для тестирования генератора.
"""
import sys
from pathlib import Path
# Добавляем родительскую директорию в путь
sys.path.insert(0, str(Path(__file__).parent.parent))
import pytest
from generator import Config, EventDictionary
@pytest.fixture
def data_dir():
"""Путь к директории с тестовыми данными."""
return Path(__file__).parent.parent.parent / "data"
@pytest.fixture
def event_dictionary(data_dir):
"""Загруженный словарь событий."""
return EventDictionary.load(data_dir)
@pytest.fixture
def base_config(data_dir):
"""Базовая конфигурация для тестов."""
return Config(
kafka_bootstrap_servers="localhost:9092",
tick_seconds=5,
lambda_base_per_min=200,
jitter_pct=20,
min_events_per_tick=5,
max_events_per_tick=50,
data_dir=data_dir,
seed=42,
enabled=True,
metrics_port=9109,
clickhouse_host="localhost",
clickhouse_port=9000,
)
@pytest.fixture
def config_no_jitter(base_config):
"""Конфигурация без jitter."""
from dataclasses import replace
return replace(base_config, jitter_pct=0)
@pytest.fixture
def empty_temp_dir(tmp_path):
"""Временная директория с пустыми JSONL файлами."""
for fname in ["browser_events.jsonl", "location_events.jsonl",
"device_events.jsonl", "geo_events.jsonl"]:
(tmp_path / fname).touch()
return tmp_path