Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
535 changes: 277 additions & 258 deletions plugins/7-zip/src/plugin.py

Large diffs are not rendered by default.

507 changes: 258 additions & 249 deletions plugins/7-zip/test/test_7zip.py

Large diffs are not rendered by default.

512 changes: 258 additions & 254 deletions plugins/alacritty/src/plugin.py

Large diffs are not rendered by default.

368 changes: 184 additions & 184 deletions plugins/alacritty/test/test_alacritty.py
Original file line number Diff line number Diff line change
@@ -1,184 +1,184 @@
import json
import os
import sys
import tempfile
from unittest.mock import patch

import pytest

src_path = os.path.join(os.path.dirname(__file__), "..", "src")
sys.path.append(src_path)
try:
import plugin
finally:
sys.path.remove(src_path)


@pytest.fixture
def mock_context():
return {
"os": "windows",
"arch": "x64",
"dryRun": False,
}


@patch("plugin.shutil.which")
def test_check_installed_true(mock_which):
mock_which.return_value = "/usr/local/bin/alacritty"
result = plugin.handle({"requestId": "req-1", "command": "check_installed", "args": {}})

assert result["success"] is True
assert result["data"] is True


@patch("plugin.shutil.which")
def test_check_installed_false(mock_which):
mock_which.return_value = None
result = plugin.handle({"requestId": "req-1", "command": "check_installed", "args": {}})

assert result["success"] is True
assert result["data"] is False


@patch("plugin.get_config_path")
def test_apply_config_creates_new(mock_get_config_path, mock_context):
with tempfile.TemporaryDirectory() as temp_dir:
config_path = os.path.join(temp_dir, "alacritty.toml")
mock_get_config_path.return_value = config_path

settings = {"window": {"opacity": 0.95}, "font": {"size": 11.5}}

result = plugin.handle(
{
"requestId": "req-2",
"command": "apply",
"args": {"settings": settings},
"context": mock_context,
}
)

assert result["success"] is True
assert result["changed"] is True
assert os.path.exists(config_path)

with open(config_path, "r") as f:
content = f.read()
assert "[window]" in content
assert "opacity = 0.95" in content
assert "[font]" in content
assert "size = 11.5" in content


@patch("plugin.get_config_path")
def test_apply_config_dry_run(mock_get_config_path):
with tempfile.TemporaryDirectory() as temp_dir:
config_path = os.path.join(temp_dir, "alacritty.toml")
mock_get_config_path.return_value = config_path

settings = {"window": {"opacity": 1.0}}

result = plugin.handle(
{
"requestId": "req-3",
"command": "apply",
"args": {"settings": settings},
"context": {"dryRun": True},
}
)

assert result["success"] is True
assert result["changed"] is True
assert not os.path.exists(config_path)


@patch("plugin.get_config_path")
def test_apply_config_invalid_toml_backup(mock_get_config_path, mock_context):
with tempfile.TemporaryDirectory() as temp_dir:
config_path = os.path.join(temp_dir, "alacritty.toml")
mock_get_config_path.return_value = config_path

with open(config_path, "w") as f:
f.write("invalid_toml = [")

settings = {"font": {"size": 12}}

result = plugin.handle(
{
"requestId": "req-4",
"command": "apply",
"args": {"settings": settings},
"context": mock_context,
}
)

assert result["success"] is True
assert result["changed"] is True

backups = [f for f in os.listdir(temp_dir) if f.endswith(".bak")]
assert len(backups) == 1

with open(os.path.join(temp_dir, backups[0]), "r") as f:
assert f.read() == "invalid_toml = ["


def test_empty_stdin():
with patch("sys.stdin.read", return_value=""):
with patch("sys.stdout.write") as mock_stdout:
plugin.main()
written = mock_stdout.call_args[0][0]
result = json.loads(written)
assert result["success"] is False
assert "Empty input" in result["error"]


def test_apply_config_invalid_args():
result = plugin.handle(
{
"requestId": "req-invalid-args",
"command": "apply",
"args": "not-a-dict",
"context": {},
}
)
assert result["success"] is False
assert "args must be an object" in result["error"]


def test_apply_config_invalid_context():
result = plugin.handle(
{
"requestId": "req-invalid-context",
"command": "apply",
"args": {},
"context": "not-a-dict",
}
)
assert result["success"] is False
assert "context must be an object" in result["error"]


def test_apply_config_invalid_settings():
result = plugin.handle(
{
"requestId": "req-invalid-settings",
"command": "apply",
"args": {"settings": "not-a-dict"},
"context": {},
}
)
assert result["success"] is False
assert "settings must be an object" in result["error"]


def test_unknown_command():
result = plugin.handle(
{
"requestId": "req-unknown",
"command": "some_unknown_cmd",
"args": {},
"context": {},
}
)
assert result["success"] is False
assert "Unknown command: some_unknown_cmd" in result["error"]
import json
import os
import sys
import tempfile
from unittest.mock import patch
import pytest
src_path = os.path.join(os.path.dirname(__file__), "..", "src")
sys.path.append(src_path)
try:
import plugin
finally:
sys.path.remove(src_path)
@pytest.fixture
def mock_context():
return {
"os": "windows",
"arch": "x64",
"dryRun": False,
}
@patch("plugin.shutil.which")
def test_check_installed_true(mock_which):
mock_which.return_value = "/usr/local/bin/alacritty"
result = plugin.handle({"requestId": "req-1", "command": "check_installed", "args": {}})
assert result["success"] is True
assert result["data"] is True
@patch("plugin.shutil.which")
def test_check_installed_false(mock_which):
mock_which.return_value = None
result = plugin.handle({"requestId": "req-1", "command": "check_installed", "args": {}})
assert result["success"] is True
assert result["data"] is False
@patch("plugin.get_config_path")
def test_apply_config_creates_new(mock_get_config_path, mock_context):
with tempfile.TemporaryDirectory() as temp_dir:
config_path = os.path.join(temp_dir, "alacritty.toml")
mock_get_config_path.return_value = config_path
settings = {"window": {"opacity": 0.95}, "font": {"size": 11.5}}
result = plugin.handle(
{
"requestId": "req-2",
"command": "apply",
"args": {"settings": settings},
"context": mock_context,
}
)
assert result["success"] is True
assert result["changed"] is True
assert os.path.exists(config_path)
with open(config_path, "r") as f:
content = f.read()
assert "[window]" in content
assert "opacity = 0.95" in content
assert "[font]" in content
assert "size = 11.5" in content
@patch("plugin.get_config_path")
def test_apply_config_dry_run(mock_get_config_path):
with tempfile.TemporaryDirectory() as temp_dir:
config_path = os.path.join(temp_dir, "alacritty.toml")
mock_get_config_path.return_value = config_path
settings = {"window": {"opacity": 1.0}}
result = plugin.handle(
{
"requestId": "req-3",
"command": "apply",
"args": {"settings": settings},
"context": {"dryRun": True},
}
)
assert result["success"] is True
assert result["changed"] is True
assert not os.path.exists(config_path)
@patch("plugin.get_config_path")
def test_apply_config_invalid_toml_backup(mock_get_config_path, mock_context):
with tempfile.TemporaryDirectory() as temp_dir:
config_path = os.path.join(temp_dir, "alacritty.toml")
mock_get_config_path.return_value = config_path
with open(config_path, "w") as f:
f.write("invalid_toml = [")
settings = {"font": {"size": 12}}
result = plugin.handle(
{
"requestId": "req-4",
"command": "apply",
"args": {"settings": settings},
"context": mock_context,
}
)
assert result["success"] is True
assert result["changed"] is True
backups = [f for f in os.listdir(temp_dir) if f.endswith(".bak")]
assert len(backups) == 1
with open(os.path.join(temp_dir, backups[0]), "r") as f:
assert f.read() == "invalid_toml = ["
def test_empty_stdin():
with patch("sys.stdin.read", return_value=""):
with patch("sys.stdout.write") as mock_stdout:
plugin.main()
written = mock_stdout.call_args[0][0]
result = json.loads(written)
assert result["success"] is False
assert "Empty input" in result["error"]
def test_apply_config_invalid_args():
result = plugin.handle(
{
"requestId": "req-invalid-args",
"command": "apply",
"args": "not-a-dict",
"context": {},
}
)
assert result["success"] is False
assert "args must be an object" in result["error"]
def test_apply_config_invalid_context():
result = plugin.handle(
{
"requestId": "req-invalid-context",
"command": "apply",
"args": {},
"context": "not-a-dict",
}
)
assert result["success"] is False
assert "context must be an object" in result["error"]
def test_apply_config_invalid_settings():
result = plugin.handle(
{
"requestId": "req-invalid-settings",
"command": "apply",
"args": {"settings": "not-a-dict"},
"context": {},
}
)
assert result["success"] is False
assert "settings must be an object" in result["error"]
def test_unknown_command():
result = plugin.handle(
{
"requestId": "req-unknown",
"command": "some_unknown_cmd",
"args": {},
"context": {},
}
)
assert result["success"] is False
assert "Unknown command: some_unknown_cmd" in result["error"]
Loading