- Remove hardcoded FRED API key from autoresearch/prepare.py and thesis_portfolio_opt/research/experiment.py; load from .env via python-dotenv at module level instead - Add .env.example at root and update MiroFish/.env.example with CORS_ORIGINS and FRED_API_KEY documentation - Replace autoresearch/pyproject.toml: remove unused LLM deps (torch, rustbpe, tiktoken), add actual deps (scikit-learn, lightgbm, xgboost, fredapi, yfinance, cvxpy) - Fix PCA backtest bug in autoresearch/train.py: propagate fitted PCA/scaler transform through model dict so run_oos_backtest replays the same transform on live rows (B10 no longer crashes) - Fix MiroFish CORS wildcard: read allowed origins from CORS_ORIGINS env var, default to localhost dev origins - Add MiroFish test suite (36 tests): config validation, file parser, text processor, task manager, API health/blueprints - Pin upper bounds on thesis_portfolio_opt/requirements.txt Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
"""Tests for TextProcessor service."""
|
|
|
|
import pytest
|
|
from app.services.text_processor import TextProcessor
|
|
|
|
|
|
class TestTextProcessor:
|
|
def test_preprocess_normalizes_newlines(self):
|
|
text = "Line one\r\nLine two\rLine three\n"
|
|
result = TextProcessor.preprocess_text(text)
|
|
assert "\r" not in result
|
|
assert "Line one\nLine two\nLine three" == result
|
|
|
|
def test_preprocess_collapses_blank_lines(self):
|
|
text = "Para one.\n\n\n\n\nPara two."
|
|
result = TextProcessor.preprocess_text(text)
|
|
assert "\n\n\n" not in result
|
|
assert "Para one.\n\nPara two." == result
|
|
|
|
def test_preprocess_strips_line_whitespace(self):
|
|
text = " indented \n also indented "
|
|
result = TextProcessor.preprocess_text(text)
|
|
lines = result.split("\n")
|
|
for line in lines:
|
|
assert line == line.strip()
|
|
|
|
def test_get_text_stats(self):
|
|
text = "Hello world.\nSecond line.\nThird line."
|
|
stats = TextProcessor.get_text_stats(text)
|
|
assert stats["total_chars"] == len(text)
|
|
assert stats["total_lines"] == 3
|
|
assert stats["total_words"] == 6
|
|
|
|
def test_split_text_delegates(self):
|
|
text = "A" * 1000
|
|
chunks = TextProcessor.split_text(text, chunk_size=300, overlap=50)
|
|
assert len(chunks) > 1
|
|
|
|
def test_extract_from_files(self, tmp_text_file):
|
|
result = TextProcessor.extract_from_files([tmp_text_file])
|
|
assert "Hello World" in result
|