From 9698e57fa6a08d11849332500c988c7c5c4e4ed5 Mon Sep 17 00:00:00 2001 From: Qubasa Date: Tue, 21 Nov 2023 16:44:38 +0100 Subject: [PATCH] Added more deal tests --- docs/contributing.md | 3 +++ pkgs/clan-cli/clan_cli/async_cmd.py | 8 ++++--- pkgs/clan-cli/clan_cli/nix.py | 11 +++++---- pkgs/clan-cli/clan_cli/task_manager.py | 5 +++- pkgs/clan-cli/tests/test_with_deal.py | 32 +++++++++++++++++++++++--- 5 files changed, 47 insertions(+), 12 deletions(-) diff --git a/docs/contributing.md b/docs/contributing.md index 8e738e47e..91e44acf1 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -78,6 +78,9 @@ Let's get your development environment up and running: ``` - Wait for the frontend to build. + NOTE: If you have the error "@clan/colors.json" you executed `npm install`, please do not do that. `direnv reload` will handle dependency management. Please delete node_modules with `rm -rf node_modules`. + + 9. **Start the Frontend**: - To start the frontend, execute: ```bash diff --git a/pkgs/clan-cli/clan_cli/async_cmd.py b/pkgs/clan-cli/clan_cli/async_cmd.py index 462b2000f..96f4b2a08 100644 --- a/pkgs/clan-cli/clan_cli/async_cmd.py +++ b/pkgs/clan-cli/clan_cli/async_cmd.py @@ -1,8 +1,9 @@ import asyncio import logging +import deal import shlex from pathlib import Path -from typing import Any, Callable, Coroutine, Dict, NamedTuple, Optional +from typing import Any, Callable, Coroutine, Dict, NamedTuple, Optional, Awaitable from .custom_logger import get_caller from .errors import ClanError @@ -15,8 +16,8 @@ class CmdOut(NamedTuple): stderr: str cwd: Optional[Path] = None - -async def run(cmd: list[str], cwd: Optional[Path] = None) -> CmdOut: +@deal.raises(ClanError) +async def run(cmd: list[str], cwd: Optional[Path] = None) -> Awaitable[CmdOut]: cwd_res = None if cwd is not None: if not cwd.exists(): @@ -51,6 +52,7 @@ stdout: return CmdOut(stdout.decode("utf-8"), stderr.decode("utf-8"), cwd=cwd) +@deal.raises(ClanError) def runforcli( func: Callable[..., Coroutine[Any, Any, Dict[str, CmdOut]]], *args: Any ) -> None: diff --git a/pkgs/clan-cli/clan_cli/nix.py b/pkgs/clan-cli/clan_cli/nix.py index e2d7c6a14..6776dd05d 100644 --- a/pkgs/clan-cli/clan_cli/nix.py +++ b/pkgs/clan-cli/clan_cli/nix.py @@ -2,12 +2,13 @@ import json import os import subprocess import tempfile +import deal from pathlib import Path from typing import Any from .dirs import nixpkgs_flake, nixpkgs_source - +@deal.raises(ClanError) def nix_command(flags: list[str]) -> list[str]: return ["nix", "--extra-experimental-features", "nix-command flakes"] + flags @@ -24,7 +25,7 @@ def nix_flake_show(flake_url: str | Path) -> list[str]: ] ) - +@deal.raises(ClanError) def nix_build( flags: list[str], ) -> list[str]: @@ -40,7 +41,7 @@ def nix_build( + flags ) - +@deal.raises(ClanError) def nix_config() -> dict[str, Any]: cmd = nix_command(["show-config", "--json"]) proc = subprocess.run(cmd, check=True, text=True, stdout=subprocess.PIPE) @@ -50,7 +51,7 @@ def nix_config() -> dict[str, Any]: config[key] = value["value"] return config - +@deal.raises(ClanError) def nix_eval(flags: list[str]) -> list[str]: default_flags = nix_command( [ @@ -77,7 +78,7 @@ def nix_eval(flags: list[str]) -> list[str]: ) return default_flags + flags - +@deal.raises(ClanError) def nix_shell(packages: list[str], cmd: list[str]) -> list[str]: # we cannot use nix-shell inside the nix sandbox # in our tests we just make sure we have all the packages diff --git a/pkgs/clan-cli/clan_cli/task_manager.py b/pkgs/clan-cli/clan_cli/task_manager.py index f0fcb3e62..edadef5cb 100644 --- a/pkgs/clan-cli/clan_cli/task_manager.py +++ b/pkgs/clan-cli/clan_cli/task_manager.py @@ -186,10 +186,13 @@ def get_task(uuid: UUID) -> BaseTask: T = TypeVar("T", bound="BaseTask") - +@deal.raises(ClanError) def create_task(task_type: Type[T], *args: Any) -> T: global POOL + # check if task_type is a callable + if not callable(task_type): + raise ClanError("task_type must be callable") uuid = uuid4() task = task_type(uuid, *args) diff --git a/pkgs/clan-cli/tests/test_with_deal.py b/pkgs/clan-cli/tests/test_with_deal.py index 705d401f6..d471e2cba 100644 --- a/pkgs/clan-cli/tests/test_with_deal.py +++ b/pkgs/clan-cli/tests/test_with_deal.py @@ -1,8 +1,34 @@ import deal -from clan_cli.task_manager import get_task +from clan_cli import task_manager +from clan_cli import async_cmd +from clan_cli import nix - -@deal.cases(get_task) +@deal.cases(task_manager.get_task) def test_get_task(case: deal.TestCase) -> None: case() + +@deal.cases(task_manager.create_task) +def test_create_task(case: deal.TestCase) -> None: + case() + + +@deal.cases(nix.nix_command) +def test_nix_command(case: deal.TestCase) -> None: + case() + +@deal.cases(nix.nix_build) +def test_nix_build(case: deal.TestCase) -> None: + case() + +@deal.cases(nix.nix_config) +def test_nix_config(case: deal.TestCase) -> None: + case() + +@deal.cases(nix.nix_eval) +def test_nix_eval(case: deal.TestCase) -> None: + case() + +@deal.cases(nix.nix_shell) +def test_nix_shell(case: deal.TestCase) -> None: + case() \ No newline at end of file