test(log_patterns): add test for log parsing patterns
- Test loot patterns against real user log formats - Test skill patterns - Helps catch pattern mismatches early
This commit is contained in:
parent
510deb04e7
commit
9f03b3c610
|
|
@ -0,0 +1,93 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test log patterns against real log examples.
|
||||
Run: python tests/test_log_patterns.py
|
||||
"""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
||||
from core.log_watcher import LogWatcher
|
||||
|
||||
def test_loot_patterns():
|
||||
"""Test loot patterns against real log lines."""
|
||||
test_cases = [
|
||||
# User's format (English with brackets)
|
||||
("2026-02-08 22:17:30 [System]: You received [Shrapnel] x (67) Value: 0.0067 PED", "loot"),
|
||||
("2026-02-08 22:17:30 [System]: You received [Animal Oil Residue] x (2) Value: 0.0200 PED", "loot"),
|
||||
# Standard format
|
||||
("2026-02-08 22:17:30 [System] You received Shrapnel x (67) Value: 0.0067 PED", "loot"),
|
||||
# Swedish format
|
||||
("2026-02-08 22:17:30 [System] Du fick Shrapnel x (67) Värde: 0.0067 PED", "loot"),
|
||||
]
|
||||
|
||||
watcher = LogWatcher.__new__(LogWatcher) # Create without __init__
|
||||
|
||||
passed = 0
|
||||
failed = 0
|
||||
|
||||
print("Testing loot patterns...")
|
||||
for line, expected_type in test_cases:
|
||||
# Try English pattern
|
||||
match = watcher.PATTERN_LOOT_EN.match(line)
|
||||
if match:
|
||||
print(f" ✅ EN matched: {line[:60]}...")
|
||||
passed += 1
|
||||
continue
|
||||
|
||||
# Try Swedish pattern
|
||||
match = watcher.PATTERN_LOOT_SV.match(line)
|
||||
if match:
|
||||
print(f" ✅ SV matched: {line[:60]}...")
|
||||
passed += 1
|
||||
continue
|
||||
|
||||
print(f" ❌ FAILED: {line[:60]}...")
|
||||
failed += 1
|
||||
|
||||
return passed, failed
|
||||
|
||||
def test_skill_patterns():
|
||||
"""Test skill patterns."""
|
||||
test_cases = [
|
||||
("2026-02-08 22:18:26 [System] You gained 0.7639 experience in your Whip skill", "skill"),
|
||||
("2026-02-08 22:19:30 [System] You gained 3.4372 experience in your Whip skill", "skill"),
|
||||
]
|
||||
|
||||
watcher = LogWatcher.__new__(LogWatcher)
|
||||
|
||||
passed = 0
|
||||
failed = 0
|
||||
|
||||
print("\nTesting skill patterns...")
|
||||
for line, expected_type in test_cases:
|
||||
match = watcher.PATTERN_SKILL_EN.match(line)
|
||||
if match:
|
||||
print(f" ✅ EN matched: {line[:60]}...")
|
||||
passed += 1
|
||||
else:
|
||||
print(f" ❌ FAILED: {line[:60]}...")
|
||||
failed += 1
|
||||
|
||||
return passed, failed
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("="*60)
|
||||
print("LOG PATTERN TESTS")
|
||||
print("="*60)
|
||||
print()
|
||||
|
||||
loot_passed, loot_failed = test_loot_patterns()
|
||||
skill_passed, skill_failed = test_skill_patterns()
|
||||
|
||||
total_passed = loot_passed + skill_passed
|
||||
total_failed = loot_failed + skill_failed
|
||||
|
||||
print()
|
||||
print("="*60)
|
||||
print(f"RESULTS: {total_passed} passed, {total_failed} failed")
|
||||
print("="*60)
|
||||
|
||||
sys.exit(0 if total_failed == 0 else 1)
|
||||
Loading…
Reference in New Issue