torrent.py and platform_ops.py unit tests are now all passing , moving on to integration testing
This commit is contained in:
@@ -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",
|
||||
|
||||
+4
-4
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user