Some checks failed
CI / test (push) Has been cancelled
- Created models.py with HistoryEntry and SearchResult classes - Created database.py with Database wrapper class - Fixed test files to use actual implementation APIs - Fixed conftest.py SearchResult fixture field names
60 lines
1.9 KiB
Python
60 lines
1.9 KiB
Python
import pytest
|
|
|
|
from shell_history_search.parsers.bash import BashHistoryParser
|
|
from shell_history_search.parsers.zsh import ZshHistoryParser
|
|
from shell_history_search.parsers.fish import FishHistoryParser
|
|
from shell_history_search.parsers.factory import get_all_parsers
|
|
|
|
|
|
class TestBashParser:
|
|
@pytest.fixture
|
|
def parser(self):
|
|
return BashHistoryParser()
|
|
|
|
def test_parse_single_entry(self, parser, tmp_path):
|
|
history_file = tmp_path / ".bash_history"
|
|
history_file.write_text("ls -la\n")
|
|
entries = list(parser.parse(history_file))
|
|
assert len(entries) == 1
|
|
assert entries[0].command == "ls -la"
|
|
|
|
def test_parse_empty_file(self, parser, tmp_path):
|
|
history_file = tmp_path / ".bash_history"
|
|
history_file.write_text("")
|
|
entries = list(parser.parse(history_file))
|
|
assert len(entries) == 0
|
|
|
|
|
|
class TestZshParser:
|
|
@pytest.fixture
|
|
def parser(self):
|
|
return ZshHistoryParser()
|
|
|
|
def test_parse_zsh_entry(self, parser, tmp_path):
|
|
history_file = tmp_path / ".zsh_history"
|
|
history_file.write_text(": 1234567890:0;ls -la\n")
|
|
entries = list(parser.parse(history_file))
|
|
assert len(entries) == 1
|
|
assert entries[0].command == "ls -la"
|
|
|
|
|
|
class TestFishParser:
|
|
@pytest.fixture
|
|
def parser(self):
|
|
return FishHistoryParser()
|
|
|
|
def test_parse_fish_entry(self, parser, tmp_path):
|
|
history_file = tmp_path / "fish_history"
|
|
history_file.write_text("cmd ls -la\n")
|
|
entries = list(parser.parse(history_file))
|
|
assert len(entries) >= 1
|
|
assert entries[0].command == "ls -la"
|
|
|
|
|
|
class TestParserFactory:
|
|
def test_get_all_parsers(self):
|
|
parsers = get_all_parsers()
|
|
assert len(parsers) == 3
|
|
shell_types = {p.shell_type for p in parsers}
|
|
assert shell_types == {"bash", "zsh", "fish"}
|