"""Pytest configuration and fixtures for LogLens tests.""" import sys from pathlib import Path import pytest sys.path.insert(0, str(Path(__file__).parent.parent.parent)) @pytest.fixture def sample_json_logs(): """Sample JSON log lines.""" return [ '{"timestamp": "2024-01-15T10:30:00Z", "level": "INFO", "message": "Application started successfully", "logger": "main"}', '{"timestamp": "2024-01-15T10:30:01Z", "level": "ERROR", "message": "Connection refused to database", "logger": "db"}', '{"timestamp": "2024-01-15T10:30:02Z", "level": "WARNING", "message": "Deprecated API call detected", "logger": "api"}', ] @pytest.fixture def sample_syslog_logs(): """Sample syslog lines.""" return [ "Jan 15 10:30:00 server-01 systemd[1]: Started LogLens Application.", "Jan 15 10:30:01 server-01 app[1234]: ERROR: Connection refused to database:5432", "Jan 15 10:30:02 server-01 app[1234]: WARNING: Using deprecated API endpoint", "Jan 15 10:30:03 server-02 kernel: [1234.567] Connection timeout", "Jan 15 10:30:04 server-01 app[1234]: INFO: Request processed successfully", ] @pytest.fixture def sample_apache_logs(): """Sample Apache log lines.""" return [ '192.168.1.1 - - [15/Jan/2024:10:30:00 +0000] "GET /api/users HTTP/1.1" 200 1234 "-" "Mozilla/5.0"', '192.168.1.2 - - [15/Jan/2024:10:30:01 +0000] "POST /api/login HTTP/1.1" 401 567 "-" "Mozilla/5.0"', '192.168.1.3 - - [15/Jan/2024:10:30:02 +0000] "GET /api/orders HTTP/1.1" 500 4321 "-" "Mozilla/5.0"', '192.168.1.1 - - [15/Jan/2024:10:30:03 +0000] "GET /static/main.css HTTP/1.1" 304 0 "https://example.com/" "Mozilla/5.0"', ] @pytest.fixture def error_logs(): """Sample error log lines.""" return [ "Jan 15 10:30:00 server-01 app[1234]: Traceback (most recent call last):", 'Jan 15 10:30:01 server-01 app[1234]: File "main.py", line 42, in ', "Jan 15 10:30:02 server-01 app[1234]: result = process_data(data)", 'Jan 15 10:30:03 server-01 app[1234]: File "main.py", line 100, in process_data', "Jan 15 10:30:04 server-01 app[1234]: KeyError: \"Missing required key 'id'\"", '{"level": "ERROR", "message": "NullPointerException: Cannot call method on null object"}', '{"level": "ERROR", "message": "HTTP Error 500: Internal Server Error"}', "Jan 15 10:30:05 server-01 kernel: [1234.567] Out of memory: Kill process 1234 (app)", ] @pytest.fixture def analyzer(): """Log analyzer instance.""" from loglens.analyzers.analyzer import LogAnalyzer return LogAnalyzer()