/
IvanMysin
/
Topics
Обзор
Документация
Войти
/
IvanMysin
/
Topics
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
common_agents_notes
tests/conftest.py
156 строк
5 KB
ivan
Working on load scripts
04 мар 2026, 13:58
04 мар 2026, 13:58
add6bbf
Код
Авторство
О чём код?
""" Pytest configuration and shared fixtures for Topics project tests. """ import sys import os import pytest import numpy as np import pandas as pd from pathlib import Path from unittest.mock import Mock, MagicMock # Add src to path sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src')) sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src', 'clustering')) @pytest.fixture def sample_documents(): """Fixture providing sample documents for testing.""" return [ "Memory encoding in hippocampus involves neural circuits and synaptic plasticity", "Spatial navigation requires place cell activation in the hippocampus", "Gene expression patterns in CA1 and subiculum regions of hippocampus", "Working memory processes engage prefrontal cortex and hippocampus", "Thalamo-hippocampal interactions coordinate memory retrieval processes", "Long-term potentiation in synaptic transmission and plasticity mechanisms", "Neural oscillations and theta rhythm in spatial memory encoding", "Dopamine modulation of hippocampal synaptic plasticity and learning", "Molecular mechanisms of memory consolidation in hippocampal circuits", "Entorhinal cortex projections to hippocampus and spatial navigation" ] @pytest.fixture def sample_embeddings(): """Fixture providing sample embeddings for testing.""" np.random.seed(42) # Create 10 documents with 50-dimensional embeddings return np.random.randn(10, 50).astype(np.float32) @pytest.fixture def sample_df(): """Fixture providing sample DataFrame for testing.""" return pd.DataFrame({ 'id': range(1, 11), 'title': [ 'Memory encoding in hippocampus', 'Spatial navigation and place cells', 'Gene expression in CA1', 'Working memory and prefrontal cortex', 'Thalamo-hippocampal interactions', 'Long-term potentiation mechanisms', 'Neural oscillations in memory', 'Dopamine and synaptic plasticity', 'Memory consolidation mechanisms', 'Entorhinal-hippocampal projections' ], 'abstract': [ 'Memory encoding involves neural circuits', 'Spatial navigation requires place cells', 'Gene expression patterns in CA1', 'Working memory processes engage cortex', 'Thalamic interactions coordinate retrieval', 'LTP in synaptic transmission', 'Theta rhythm in memory encoding', 'Dopamine modulation of plasticity', 'Molecular mechanisms of consolidation', 'EC projections to hippocampus' ], 'doi': [f'10.1234/test{i}' for i in range(1, 11)], 'date': ['2023-01-01'] * 10, 'journal': ['Neuroscience'] * 10 }) @pytest.fixture def mock_stopwords_manager(): """Fixture providing mocked StopwordsManager.""" mock = Mock() mock.get_stop_words.return_value = {'the', 'and', 'in', 'of', 'to', 'a', 'is'} mock.custom_stopwords = {'study', 'research', 'paper'} return mock @pytest.fixture def temp_results_dir(tmp_path): """Fixture providing temporary results directory.""" results_dir = tmp_path / "results" results_dir.mkdir() return results_dir @pytest.fixture def temp_data_dir(tmp_path): """Fixture providing temporary data directory.""" data_dir = tmp_path / "data" data_dir.mkdir() return data_dir @pytest.fixture def sample_clustering_labels(): """Fixture providing sample clustering labels.""" return np.array([0, 0, 1, 1, 0, 1, 2, 2, 1, 0]) @pytest.fixture def sample_topic_words(): """Fixture providing sample topic words.""" return { 0: [('hippocampus', 15), ('memory', 12), ('spatial', 8)], 1: [('synaptic', 10), ('plasticity', 9), ('potentiation', 7)], 2: [('dopamine', 8), ('modulation', 6), ('circuits', 5)] } @pytest.fixture def sample_similarities(): """Fixture providing sample similarity scores.""" return { 0: np.array([0.85, 0.78, 0.92]), 1: np.array([0.88, 0.75, 0.81, 0.79]), 2: np.array([0.90, 0.83]) } @pytest.fixture def mock_config(): """Fixture providing mocked configuration.""" return { "min_clusters": 5, "max_clusters": 20, "default_clusters": 10, "kmeans": { "random_state": 42, "n_init": 10, "max_iter": 300 }, "hierarchical": { "metric": "euclidean", "linkage": "ward", "compute_full_tree": True }, "dbscan": { "min_samples": 5, "eps_auto": True, "k_for_eps": 4 }, "xmeans": { "kmax": 50, "max_iter": 100, "random_state": 42 } }