This commit is contained in:
77
.tests/test_patterns.py
Normal file
77
.tests/test_patterns.py
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
"""Tests for CLI Command Memory pattern detection."""
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
from cli_memory.patterns import PatternDetector
|
||||||
|
from cli_memory.config import Config
|
||||||
|
from cli_memory.models import Command, CommandType, Pattern
|
||||||
|
|
||||||
|
|
||||||
|
class MockCommand:
|
||||||
|
def __init__(self, id, command, timestamp=None, project_id=None):
|
||||||
|
self.id = id
|
||||||
|
self.command = command
|
||||||
|
self.timestamp = timestamp or datetime.utcnow()
|
||||||
|
self.project_id = project_id
|
||||||
|
|
||||||
|
|
||||||
|
def test_pattern_detector_init():
|
||||||
|
"""Test PatternDetector initialization."""
|
||||||
|
detector = PatternDetector()
|
||||||
|
assert detector is not None
|
||||||
|
|
||||||
|
|
||||||
|
def test_calculate_confidence():
|
||||||
|
"""Test confidence calculation."""
|
||||||
|
detector = PatternDetector()
|
||||||
|
|
||||||
|
confidence = detector._calculate_confidence(occurrences=1, length=3)
|
||||||
|
assert 0 < confidence <= 1.0
|
||||||
|
|
||||||
|
confidence = detector._calculate_confidence(occurrences=5, length=7)
|
||||||
|
assert confidence > 0.5
|
||||||
|
|
||||||
|
|
||||||
|
def test_sequence_similarity():
|
||||||
|
"""Test sequence similarity calculation."""
|
||||||
|
detector = PatternDetector()
|
||||||
|
|
||||||
|
seq1 = ["git status", "git add .", "git commit"]
|
||||||
|
seq2 = ["git status", "git add .", "git commit"]
|
||||||
|
|
||||||
|
similarity = detector._calculate_similarity(
|
||||||
|
Pattern(command_sequence=seq1),
|
||||||
|
Pattern(command_sequence=seq2)
|
||||||
|
)
|
||||||
|
assert similarity == 1.0
|
||||||
|
|
||||||
|
|
||||||
|
def test_detect_patterns_empty():
|
||||||
|
"""Test pattern detection with no commands."""
|
||||||
|
detector = PatternDetector()
|
||||||
|
|
||||||
|
patterns = detector.detect_patterns([])
|
||||||
|
assert patterns == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_detect_patterns_with_commands():
|
||||||
|
"""Test pattern detection with commands."""
|
||||||
|
detector = PatternDetector()
|
||||||
|
now = datetime.utcnow()
|
||||||
|
|
||||||
|
commands = [
|
||||||
|
MockCommand(1, "git status", timestamp=now),
|
||||||
|
MockCommand(2, "git add .", timestamp=now),
|
||||||
|
MockCommand(3, "git commit", timestamp=now),
|
||||||
|
]
|
||||||
|
|
||||||
|
patterns = detector.detect_patterns(commands, min_occurrences=2, min_length=2)
|
||||||
|
assert isinstance(patterns, list)
|
||||||
|
|
||||||
|
|
||||||
|
def test_analyze_workflow_patterns():
|
||||||
|
"""Test workflow pattern analysis."""
|
||||||
|
detector = PatternDetector()
|
||||||
|
|
||||||
|
result = detector.analyze_workflow_patterns()
|
||||||
|
assert "total_patterns" in result
|
||||||
|
assert "high_confidence_patterns" in result
|
||||||
Reference in New Issue
Block a user