From adbedf7d5704bad61e1bddb85b15fa1946322de8 Mon Sep 17 00:00:00 2001 From: Microchip Date: Sun, 27 Sep 2026 15:02:35 -0400 Subject: [PATCH] torrent.py and platform_ops.py unit tests are now all passing , moving on to integration testing --- src/tests/test_torrent.py | 18 ++++++++++++++++-- src/torrent.py | 8 ++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/tests/test_torrent.py b/src/tests/test_torrent.py index a86d5d6..9214fb8 100644 --- a/src/tests/test_torrent.py +++ b/src/tests/test_torrent.py @@ -34,8 +34,10 @@ def test_ensure_aria2c_returns_existing_executable(monkeypatch): installer.assert_not_called() -def test_ensure_aria2c_returns_windows_path(monkeypatch): +def test_ensure_aria2c_windows_returns_installed_binary(monkeypatch): + # Arrange expected = r"C:\aria2\aria2c.exe" + monkeypatch.setattr(torrent.sys, "platform", "win32") monkeypatch.setattr( torrent, @@ -45,7 +47,8 @@ def test_ensure_aria2c_returns_windows_path(monkeypatch): assert torrent.ensure_aria2c() == expected -def test_ensure_aria2c_installs_when_not_found(monkeypatch): +def test_ensure_aria2c_windows_installs_when_binary_is_missing(monkeypatch): + # Arrange monkeypatch.setattr( torrent, "find_aria2c", @@ -79,6 +82,7 @@ def test_ensure_aria2c_installs_when_not_found(monkeypatch): ) def test_ensure_aria2c_linux_returns_installed_binary(monkeypatch): + # Arrange monkeypatch.setattr( torrent.sys, "platform", @@ -105,6 +109,7 @@ def test_ensure_aria2c_linux_returns_installed_binary(monkeypatch): installer.assert_not_called() def test_ensure_aria2c_linux_raises_when_not_installed(monkeypatch): + # Arrange monkeypatch.setattr( torrent.sys, "platform", @@ -134,6 +139,9 @@ def test_ensure_aria2c_linux_raises_when_not_installed(monkeypatch): installer.assert_not_called() def test_ensure_aria2c_passes_custom_logger(monkeypatch): + # Arrange + monkeypatch.setattr(torrent.sys, "platform", "win32") + monkeypatch.setattr( torrent, "find_aria2c", @@ -162,6 +170,9 @@ def test_ensure_aria2c_passes_custom_logger(monkeypatch): def test_ensure_aria2c_empty_path_triggers_install(monkeypatch): + # Arrange + monkeypatch.setattr(torrent.sys, "platform", "win32") + monkeypatch.setattr( torrent, "find_aria2c", @@ -185,6 +196,9 @@ def test_ensure_aria2c_empty_path_triggers_install(monkeypatch): def test_ensure_aria2c_propagates_installer_failure(monkeypatch): + # Arrange + monkeypatch.setattr(torrent.sys, "platform", "win32") + monkeypatch.setattr( torrent, "find_aria2c", diff --git a/src/torrent.py b/src/torrent.py index 1e119ab..950b666 100644 --- a/src/torrent.py +++ b/src/torrent.py @@ -29,18 +29,18 @@ _NO_WINDOW = getattr(subprocess, "CREATE_NO_WINDOW", 0) def ensure_aria2c(log_fn=log) -> str: """Return the path to aria2c.exe, downloading + checksum-verifying it into APP_DATA_DIR on first use. Raises on failure.""" - ARIA2C_PATH = find_aria2c() + ARIA2C_PATH = find_aria2c() # NOTE: Returns a path to a aria2c executable , otherwise this var is None - if ARIA2C_PATH: + if ARIA2C_PATH: # NOTE: If result from find_aria2c() isn't None , returns path return ARIA2C_PATH - if sys.platform.startswith == "win": + if sys.platform.startswith("win"): # NOTE: Checks if platform is windows 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") + raise RuntimeError("aria2c required but not installed") # NOTE: If neither windows or linux path is returned , throws runtime error def _bdecode(buf: bytes, pos: int = 0):