Update unit tests for testing linux behavior

This commit is contained in:
Microchip
2026-09-26 14:45:46 -04:00
parent 919145569a
commit bf938b838e
3 changed files with 67 additions and 5 deletions
+1 -1
View File
@@ -64,7 +64,7 @@ def open_directory(path: str) -> None:
raise RuntimeError("xdg-open is required to open directories")
subprocess.Popen([opener, path])
# NOTE: Creates link to windows junction for torrent ?
# NOTE: If windows, creates ntfs junction , else , creates symlink
def create_directory_link(link: str, target: str) -> None:
if sys.platform == "win32":
flags = getattr(subprocess, "CREATE_NO_WINDOW", 0)
+60 -1
View File
@@ -45,7 +45,6 @@ def test_ensure_aria2c_returns_windows_path(monkeypatch):
assert torrent.ensure_aria2c() == expected
def test_ensure_aria2c_installs_when_not_found(monkeypatch):
monkeypatch.setattr(
torrent,
@@ -53,6 +52,12 @@ def test_ensure_aria2c_installs_when_not_found(monkeypatch):
Mock(return_value=None),
)
monkeypatch.setattr(
torrent.sys,
"platform",
"win32",
)
installer = Mock(
return_value="/fake/aria2c.exe"
)
@@ -73,6 +78,60 @@ def test_ensure_aria2c_installs_when_not_found(monkeypatch):
log_fn=torrent.log,
)
def test_ensure_aria2c_linux_returns_installed_binary(monkeypatch):
monkeypatch.setattr(
torrent.sys,
"platform",
"linux",
)
monkeypatch.setattr(
torrent,
"find_aria2c",
Mock(return_value="/usr/bin/aria2c"),
)
installer = Mock()
monkeypatch.setattr(
torrent,
"install_aria2c_windows",
installer,
)
result = torrent.ensure_aria2c()
assert result == "/usr/bin/aria2c"
installer.assert_not_called()
def test_ensure_aria2c_linux_raises_when_not_installed(monkeypatch):
monkeypatch.setattr(
torrent.sys,
"platform",
"linux",
)
monkeypatch.setattr(
torrent,
"find_aria2c",
Mock(return_value=None),
)
installer = Mock()
monkeypatch.setattr(
torrent,
"install_aria2c_windows",
installer,
)
with pytest.raises(
RuntimeError,
match="aria2c required but not installed",
):
torrent.ensure_aria2c()
installer.assert_not_called()
def test_ensure_aria2c_passes_custom_logger(monkeypatch):
monkeypatch.setattr(
+6 -3
View File
@@ -6,6 +6,7 @@ import re
import subprocess
import threading
import urllib.request
import sys
from functools import cache
from .app_log import log
@@ -33,12 +34,14 @@ def ensure_aria2c(log_fn=log) -> str:
if ARIA2C_PATH:
return ARIA2C_PATH
return install_aria2c_windows( APP_DATA_DIR=APP_DATA_DIR,
if sys.platform.startswith == "win":
return install_aria2c_windows( APP_DATA_DIR=APP_DATA_DIR,
ALLOWED_DOWNLOAD_HOSTS=ALLOWED_DOWNLOAD_HOSTS,
log_fn=log_fn)
raise RuntimeError("aria2c required but not installed")
def _bdecode(buf: bytes, pos: int = 0):
"""Minimal bencode decoder → (value, next_pos). Strings stay bytes."""