From cdfef7186603bbcad0e211ea482879b0730ff74a Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Mon, 2 Feb 2026 08:06:58 +0000 Subject: [PATCH] Add test configuration and fixtures --- tests/conftest.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tests/conftest.py diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..efe9afd --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,63 @@ +"""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()