From c0f8b9026be3d781e487e443ecf01a3c9435b40f Mon Sep 17 00:00:00 2001 From: dettlaff Date: Mon, 16 Oct 2023 20:39:58 +0400 Subject: [PATCH] fix: corrected from comment from pr --- selfprivacy_api/jobs/nix_collect_garbage.py | 12 ++++++------ tests/test_graphql/test_nix_collect_garbage.py | 7 ++----- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/selfprivacy_api/jobs/nix_collect_garbage.py b/selfprivacy_api/jobs/nix_collect_garbage.py index a623f9f..259af96 100644 --- a/selfprivacy_api/jobs/nix_collect_garbage.py +++ b/selfprivacy_api/jobs/nix_collect_garbage.py @@ -1,6 +1,7 @@ import re import subprocess from subprocess import Popen, PIPE +from typing import Tuple, Iterable, IO, Any, Optional from selfprivacy_api.utils.huey import huey @@ -14,7 +15,7 @@ RESULT_WAS_NOT_FOUND_ERROR = "We are sorry, garbage collection result was not fo CLEAR_COMPLETED = "Cleaning completed." -def run_nix_store_print_dead() -> PIPE: +def run_nix_store_print_dead() -> IO[Any]: subprocess.run( ["nix-env", "-p", "/nix/var/nix/profiles/system", "--delete-generations old"], check=False, @@ -24,14 +25,13 @@ def run_nix_store_print_dead() -> PIPE: "utf-8" ) - -def run_nix_collect_garbage() -> subprocess.Popen: +def run_nix_collect_garbage() -> Optional[IO[bytes]]: return subprocess.Popen( ["nix-store", "--gc"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT ).stdout -def parse_line(line): +def parse_line(line: str): """ We parse the string for the presence of a final line, with the final amount of space cleared. @@ -58,7 +58,7 @@ def parse_line(line): ) -def process_stream(job, stream, total_dead_packages): +def process_stream(job: Job, stream: Iterable[bytes], total_dead_packages: int) -> None: completed_packages = 0 prev_progress = 0 @@ -89,7 +89,7 @@ def process_stream(job, stream, total_dead_packages): ) -def get_dead_packages(output): +def get_dead_packages(output) -> Tuple[int, int]: dead = len(re.findall("/nix/store/", output)) percent = 0 if dead != 0: diff --git a/tests/test_graphql/test_nix_collect_garbage.py b/tests/test_graphql/test_nix_collect_garbage.py index ea56d0f..e05a5dc 100644 --- a/tests/test_graphql/test_nix_collect_garbage.py +++ b/tests/test_graphql/test_nix_collect_garbage.py @@ -18,9 +18,6 @@ from selfprivacy_api.jobs.nix_collect_garbage import ( RESULT_WAS_NOT_FOUND_ERROR, ) -pytest_plugins = ("pytest_asyncio",) - - OUTPUT_PRINT_DEAD = """ finding garbage collector roots... determining live/dead paths... @@ -102,7 +99,7 @@ def test_get_dead_packages_zero(job_reset): assert get_dead_packages("") == (0, 0) -RUN_NIX_COLLECT_GARBAGE_QUERY = """ +RUN_NIX_COLLECT_GARBAGE_MUTATION = """ mutation CollectGarbage { system { nixCollectGarbage { @@ -133,7 +130,7 @@ def test_graphql_nix_collect_garbage(authorized_client): response = authorized_client.post( "/graphql", json={ - "query": RUN_NIX_COLLECT_GARBAGE_QUERY, + "query": RUN_NIX_COLLECT_GARBAGE_MUTATION, }, )