Initial commit: Add shell-memory-cli project
A CLI tool that learns from terminal command patterns to automate repetitive workflows. Features: - Command recording with tags and descriptions - Pattern detection for command sequences - Session recording and replay - Natural language script generation
This commit is contained in:
128
tests/test_models.py
Normal file
128
tests/test_models.py
Normal file
@@ -0,0 +1,128 @@
|
||||
"""Tests for data models."""
|
||||
|
||||
import pytest
|
||||
from datetime import datetime
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from shell_memory.models import Command, Pattern, Session, ScriptTemplate
|
||||
|
||||
|
||||
class TestCommand:
|
||||
def test_command_creation(self):
|
||||
cmd = Command(
|
||||
command="git status",
|
||||
description="Check git status",
|
||||
tags=["git", "vcs"],
|
||||
)
|
||||
assert cmd.command == "git status"
|
||||
assert cmd.description == "Check git status"
|
||||
assert cmd.tags == ["git", "vcs"]
|
||||
assert cmd.usage_count == 0
|
||||
assert cmd.created_at is not None
|
||||
|
||||
def test_command_to_dict(self):
|
||||
cmd = Command(
|
||||
id=1,
|
||||
command="ls -la",
|
||||
description="List files",
|
||||
tags=["filesystem"],
|
||||
usage_count=5,
|
||||
)
|
||||
data = cmd.to_dict()
|
||||
assert data["id"] == 1
|
||||
assert data["command"] == "ls -la"
|
||||
assert data["tags"] == ["filesystem"]
|
||||
assert data["usage_count"] == 5
|
||||
|
||||
def test_command_from_dict(self):
|
||||
data = {
|
||||
"id": 2,
|
||||
"command": "pwd",
|
||||
"description": "Print working directory",
|
||||
"tags": [],
|
||||
"usage_count": 10,
|
||||
}
|
||||
cmd = Command.from_dict(data)
|
||||
assert cmd.id == 2
|
||||
assert cmd.command == "pwd"
|
||||
assert cmd.usage_count == 10
|
||||
|
||||
|
||||
class TestPattern:
|
||||
def test_pattern_creation(self):
|
||||
pattern = Pattern(
|
||||
name="Git workflow",
|
||||
command_ids=[1, 2, 3, 4],
|
||||
frequency=5,
|
||||
)
|
||||
assert pattern.name == "Git workflow"
|
||||
assert pattern.command_ids == [1, 2, 3, 4]
|
||||
assert pattern.frequency == 5
|
||||
|
||||
def test_pattern_sequence_hash(self):
|
||||
pattern = Pattern(command_ids=[1, 2, 3])
|
||||
hash1 = pattern.sequence_hash()
|
||||
pattern2 = Pattern(command_ids=[1, 2, 3])
|
||||
hash2 = pattern2.sequence_hash()
|
||||
assert hash1 == hash2
|
||||
|
||||
pattern3 = Pattern(command_ids=[1, 2, 4])
|
||||
hash3 = pattern3.sequence_hash()
|
||||
assert hash1 != hash3
|
||||
|
||||
def test_pattern_to_dict(self):
|
||||
pattern = Pattern(
|
||||
id=1,
|
||||
name="Test pattern",
|
||||
command_ids=[1, 2],
|
||||
frequency=3,
|
||||
)
|
||||
data = pattern.to_dict()
|
||||
assert data["id"] == 1
|
||||
assert data["name"] == "Test pattern"
|
||||
assert data["command_ids"] == [1, 2]
|
||||
|
||||
|
||||
class TestSession:
|
||||
def test_session_creation(self):
|
||||
session = Session(
|
||||
name="Test session",
|
||||
commands=[{"command": "ls", "success": True}],
|
||||
)
|
||||
assert session.name == "Test session"
|
||||
assert len(session.commands) == 1
|
||||
|
||||
def test_session_to_dict(self):
|
||||
session = Session(
|
||||
id=1,
|
||||
name="My session",
|
||||
commands=[{"command": "echo test"}],
|
||||
)
|
||||
data = session.to_dict()
|
||||
assert data["id"] == 1
|
||||
assert data["name"] == "My session"
|
||||
assert data["commands"] == [{"command": "echo test"}]
|
||||
|
||||
|
||||
class TestScriptTemplate:
|
||||
def test_template_creation(self):
|
||||
template = ScriptTemplate(
|
||||
keywords=["deploy", "app"],
|
||||
template="#!/bin/bash\necho deploy",
|
||||
description="Deploy application",
|
||||
)
|
||||
assert template.keywords == ["deploy", "app"]
|
||||
assert "deploy" in template.template
|
||||
|
||||
def test_template_to_dict(self):
|
||||
template = ScriptTemplate(
|
||||
id=1,
|
||||
keywords=["test"],
|
||||
template="pytest",
|
||||
description="Run tests",
|
||||
)
|
||||
data = template.to_dict()
|
||||
assert data["id"] == 1
|
||||
assert data["keywords"] == ["test"]
|
||||
Reference in New Issue
Block a user