Initial upload with CI/CD workflow
Some checks failed
CI / test (push) Failing after 10s

This commit is contained in:
2026-01-31 13:13:16 +00:00
parent c521471d44
commit cd254b0e83

View File

@@ -0,0 +1,67 @@
"""Tests for time analysis functionality."""
from datetime import datetime, timedelta
from io import StringIO
import pytest
from shellhist.core import HistoryEntry, HistoryStore
class TestTimeUtils:
"""Test time utility functions."""
def test_parse_time_range_hours(self):
"""Test parsing hour-based time range."""
from shellhist.cli.time_analysis import _parse_time_range
result = _parse_time_range("24h")
expected = datetime.now() - timedelta(hours=24)
assert (result - expected).total_seconds() < 5
def test_parse_time_range_days(self):
"""Test parsing day-based time range."""
from shellhist.cli.time_analysis import _parse_time_range
result = _parse_time_range("7d")
expected = datetime.now() - timedelta(days=7)
assert (result - expected).total_seconds() < 5
def test_parse_time_range_weeks(self):
"""Test parsing week-based time range."""
from shellhist.cli.time_analysis import _parse_time_range
result = _parse_time_range("2w")
expected = datetime.now() - timedelta(weeks=2)
assert (result - expected).total_seconds() < 5
class TestHourlyDistribution:
"""Test hourly distribution analysis."""
def test_hourly_analysis(self):
"""Test basic hourly distribution."""
from shellhist.cli.time_analysis import _analyze_hourly_distribution
from rich.console import Console
store = HistoryStore()
now = datetime.now()
for i in range(24):
entry = HistoryEntry(
command="test command",
timestamp=now.replace(hour=i),
)
store.add_entry(entry)
console = Console()
output = StringIO()
console.file = output
_analyze_hourly_distribution(console, list(store.entries))
result = output.getvalue()
assert "Hourly Command Distribution" in result