test: add -> None return type annotations to all test methods
Some checks failed
CI / test (push) Has been cancelled
Shellhist CI / test (push) Has been cancelled
Shellhist CI / build (push) Has been cancelled

This commit is contained in:
2026-01-31 14:21:27 +00:00
parent 4fb0b6ff88
commit 7b3ceb1439

View File

@@ -12,7 +12,7 @@ from shellhist.core import HistoryEntry, HistoryStore, HistoryLoader
class TestHistoryEntry: class TestHistoryEntry:
"""Test HistoryEntry dataclass.""" """Test HistoryEntry dataclass."""
def test_create_entry(self): def test_create_entry(self) -> None:
"""Test creating a basic history entry.""" """Test creating a basic history entry."""
entry = HistoryEntry(command="git status") entry = HistoryEntry(command="git status")
assert entry.command == "git status" assert entry.command == "git status"
@@ -20,13 +20,13 @@ class TestHistoryEntry:
assert entry.line_number == 0 assert entry.line_number == 0
assert entry.shell_type == "unknown" assert entry.shell_type == "unknown"
def test_entry_with_timestamp(self): def test_entry_with_timestamp(self) -> None:
"""Test creating an entry with timestamp.""" """Test creating an entry with timestamp."""
ts = datetime.now() ts = datetime.now()
entry = HistoryEntry(command="ls -la", timestamp=ts) entry = HistoryEntry(command="ls -la", timestamp=ts)
assert entry.timestamp == ts assert entry.timestamp == ts
def test_entry_equality(self): def test_entry_equality(self) -> None:
"""Test entry equality based on command.""" """Test entry equality based on command."""
entry1 = HistoryEntry(command="git status") entry1 = HistoryEntry(command="git status")
entry2 = HistoryEntry(command="git status") entry2 = HistoryEntry(command="git status")
@@ -35,7 +35,7 @@ class TestHistoryEntry:
assert entry1 == entry2 assert entry1 == entry2
assert entry1 != entry3 assert entry1 != entry3
def test_entry_hash(self): def test_entry_hash(self) -> None:
"""Test entry hash for use in sets/dicts.""" """Test entry hash for use in sets/dicts."""
entry1 = HistoryEntry(command="git status") entry1 = HistoryEntry(command="git status")
entry2 = HistoryEntry(command="git status") entry2 = HistoryEntry(command="git status")
@@ -47,13 +47,13 @@ class TestHistoryEntry:
class TestHistoryStore: class TestHistoryStore:
"""Test HistoryStore class.""" """Test HistoryStore class."""
def test_empty_store(self): def test_empty_store(self) -> None:
"""Test creating an empty store.""" """Test creating an empty store."""
store = HistoryStore() store = HistoryStore()
assert len(store.entries) == 0 assert len(store.entries) == 0
assert len(store.command_frequency) == 0 assert len(store.command_frequency) == 0
def test_add_entry(self): def test_add_entry(self) -> None:
"""Test adding entries to the store.""" """Test adding entries to the store."""
store = HistoryStore() store = HistoryStore()
entry = HistoryEntry(command="git status") entry = HistoryEntry(command="git status")
@@ -63,7 +63,7 @@ class TestHistoryStore:
assert len(store.entries) == 1 assert len(store.entries) == 1
assert store.get_frequency("git status") == 1 assert store.get_frequency("git status") == 1
def test_frequency_tracking(self): def test_frequency_tracking(self) -> None:
"""Test command frequency tracking.""" """Test command frequency tracking."""
store = HistoryStore() store = HistoryStore()
@@ -76,7 +76,7 @@ class TestHistoryStore:
assert store.get_frequency("git log") == 1 assert store.get_frequency("git log") == 1
assert store.get_frequency("unknown") == 0 assert store.get_frequency("unknown") == 0
def test_most_frequent(self): def test_most_frequent(self) -> None:
"""Test getting most frequent commands.""" """Test getting most frequent commands."""
store = HistoryStore() store = HistoryStore()
@@ -91,7 +91,7 @@ class TestHistoryStore:
assert most_frequent[0] == ("git status", 3) assert most_frequent[0] == ("git status", 3)
assert most_frequent[1] == ("git log", 1) assert most_frequent[1] == ("git log", 1)
def test_get_unique_commands(self): def test_get_unique_commands(self) -> None:
"""Test getting unique commands.""" """Test getting unique commands."""
store = HistoryStore() store = HistoryStore()
@@ -109,7 +109,7 @@ class TestHistoryStore:
class TestHistoryLoader: class TestHistoryLoader:
"""Test HistoryLoader class.""" """Test HistoryLoader class."""
def test_load_bash_history(self): def test_load_bash_history(self) -> None:
"""Test parsing bash history format.""" """Test parsing bash history format."""
with tempfile.NamedTemporaryFile(mode='w', suffix='_bash_history', delete=False) as f: with tempfile.NamedTemporaryFile(mode='w', suffix='_bash_history', delete=False) as f:
f.write("git status\n") f.write("git status\n")
@@ -132,7 +132,7 @@ class TestHistoryLoader:
finally: finally:
os.unlink(temp_path) os.unlink(temp_path)
def test_load_bash_history_with_timestamps(self): def test_load_bash_history_with_timestamps(self) -> None:
"""Test parsing bash history with timestamps.""" """Test parsing bash history with timestamps."""
with tempfile.NamedTemporaryFile(mode='w', suffix='_bash_history', delete=False) as f: with tempfile.NamedTemporaryFile(mode='w', suffix='_bash_history', delete=False) as f:
f.write("#1700000000\n") f.write("#1700000000\n")
@@ -150,7 +150,7 @@ class TestHistoryLoader:
finally: finally:
os.unlink(temp_path) os.unlink(temp_path)
def test_load_zsh_history(self): def test_load_zsh_history(self) -> None:
"""Test parsing zsh history format.""" """Test parsing zsh history format."""
import os import os
with tempfile.NamedTemporaryFile(mode='w', suffix='_zsh_history', delete=False) as f: with tempfile.NamedTemporaryFile(mode='w', suffix='_zsh_history', delete=False) as f:
@@ -170,14 +170,14 @@ class TestHistoryLoader:
finally: finally:
os.unlink(temp_path) os.unlink(temp_path)
def test_file_not_found(self): def test_file_not_found(self) -> None:
"""Test error handling for missing file.""" """Test error handling for missing file."""
loader = HistoryLoader(history_path="/nonexistent/path") loader = HistoryLoader(history_path="/nonexistent/path")
with pytest.raises(FileNotFoundError): with pytest.raises(FileNotFoundError):
loader.load() loader.load()
def test_from_file_convenience_method(self): def test_from_file_convenience_method(self) -> None:
"""Test the from_file class method.""" """Test the from_file class method."""
with tempfile.NamedTemporaryFile(mode='w', suffix='_history', delete=False) as f: with tempfile.NamedTemporaryFile(mode='w', suffix='_history', delete=False) as f:
f.write("echo test\n") f.write("echo test\n")