Skip to content

Commit

Permalink
tests: Fix CLI tests, auto-clean temp files
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Jun 8, 2024
1 parent 7c655a8 commit 4b3a9d6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import subprocess
import sys
import time
from contextlib import suppress
from pathlib import Path
from typing import Iterator

Expand Down Expand Up @@ -231,21 +232,22 @@ def destroy(self, *, force: bool = False) -> None:


ports_file = Path(".ports.json")
lock_dir = Path(".lockdir")


def get_lock() -> None:
lockdir = Path(".lockdir")
while True:
try:
lockdir.mkdir(exist_ok=False)
lock_dir.mkdir(exist_ok=False)
except FileExistsError:
time.sleep(0.025)
else:
break


def release_lock() -> None:
Path(".lockdir").rmdir()
with suppress(FileNotFoundError):
lock_dir.rmdir()


def get_random_port() -> int:
Expand Down Expand Up @@ -296,3 +298,9 @@ def port() -> Iterator[int]:
def server(tmp_path: Path, port: int) -> Iterator[Aria2Server]:
with Aria2Server(tmp_path, port) as server:
yield server


@pytest.fixture(scope="session", autouse=True)
def _setup() -> None:
ports_file.unlink(missing_ok=True)
release_lock()
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,4 @@ def test_show_debug_info(capsys: pytest.CaptureFixture) -> None:
@pytest.mark.parametrize("command", ["autoclear", "autopurge", "autoremove"])
def test_cli_autoclear_commands(command: str, tmp_path: Path, port: int) -> None:
with Aria2Server(tmp_path, port, session="very-small-download.txt"):
assert main([command]) == 0
assert main([f"-p{port}", command]) == 0

0 comments on commit 4b3a9d6

Please sign in to comment.