diff --git a/pkgs/clan-app/tests/helpers/cli.py b/pkgs/clan-app/tests/helpers/cli.py index f420ca3d..d5c219ac 100644 --- a/pkgs/clan-app/tests/helpers/cli.py +++ b/pkgs/clan-app/tests/helpers/cli.py @@ -8,8 +8,7 @@ from clan_app import main log = logging.getLogger(__name__) -class Cli: - def run(self, args: list[str]) -> None: - cmd = shlex.join(["clan", *args]) - log.debug(f"$ {cmd} \nCaller: {get_caller()}") - main(args) +def run(args: list[str]) -> None: + cmd = shlex.join(["clan", *args]) + log.debug(f"$ {cmd} \nCaller: {get_caller()}") + main(args) diff --git a/pkgs/clan-app/tests/test_cli.py b/pkgs/clan-app/tests/test_cli.py index 64cc8891..9a3b5cdb 100644 --- a/pkgs/clan-app/tests/test_cli.py +++ b/pkgs/clan-app/tests/test_cli.py @@ -1,8 +1,7 @@ import pytest -from helpers.cli import Cli +from helpers import cli def test_help(capfd: pytest.CaptureFixture) -> None: - cli = Cli() with pytest.raises(SystemExit): cli.run(["clan-app", "--help"]) diff --git a/pkgs/clan-cli/tests/helpers/cli.py b/pkgs/clan-cli/tests/helpers/cli.py index 2cba28ac..eb67b31e 100644 --- a/pkgs/clan-cli/tests/helpers/cli.py +++ b/pkgs/clan-cli/tests/helpers/cli.py @@ -8,12 +8,11 @@ from clan_cli.custom_logger import get_caller log = logging.getLogger(__name__) -class Cli: - def run(self, args: list[str]) -> argparse.Namespace: - parser = create_parser(prog="clan") - parsed = parser.parse_args(args) - cmd = shlex.join(["clan", *args]) - log.debug(f"$ {cmd} \nCaller: {get_caller()}") - if hasattr(parsed, "func"): - parsed.func(parsed) - return parsed +def run(args: list[str]) -> argparse.Namespace: + parser = create_parser(prog="clan") + parsed = parser.parse_args(args) + cmd = shlex.join(["clan", *args]) + log.debug(f"$ {cmd} \nCaller: {get_caller()}") + if hasattr(parsed, "func"): + parsed.func(parsed) + return parsed diff --git a/pkgs/clan-cli/tests/test_backups.py b/pkgs/clan-cli/tests/test_backups.py index 8ac99c39..dd13a0d2 100644 --- a/pkgs/clan-cli/tests/test_backups.py +++ b/pkgs/clan-cli/tests/test_backups.py @@ -1,14 +1,12 @@ import pytest from fixtures_flakes import FlakeForTest -from helpers.cli import Cli +from helpers import cli @pytest.mark.impure def test_backups( test_flake_with_core: FlakeForTest, ) -> None: - cli = Cli() - cli.run( [ "backups", diff --git a/pkgs/clan-cli/tests/test_cli.py b/pkgs/clan-cli/tests/test_cli.py index 87a6eaac..5f4762bc 100644 --- a/pkgs/clan-cli/tests/test_cli.py +++ b/pkgs/clan-cli/tests/test_cli.py @@ -1,9 +1,8 @@ import pytest -from helpers.cli import Cli +from helpers import cli def test_help(capsys: pytest.CaptureFixture) -> None: - cli = Cli() with pytest.raises(SystemExit): cli.run(["--help"]) captured = capsys.readouterr() diff --git a/pkgs/clan-cli/tests/test_config.py b/pkgs/clan-cli/tests/test_config.py index 64424d35..4cc91d5a 100644 --- a/pkgs/clan-cli/tests/test_config.py +++ b/pkgs/clan-cli/tests/test_config.py @@ -2,7 +2,7 @@ from pathlib import Path import pytest from fixtures_flakes import FlakeForTest -from helpers.cli import Cli +from helpers import cli from clan_cli import config from clan_cli.config import parsing @@ -13,12 +13,8 @@ example_options = f"{Path(config.__file__).parent}/jsonschema/options.json" def test_configure_machine( test_flake: FlakeForTest, - temporary_home: Path, capsys: pytest.CaptureFixture, - monkeypatch: pytest.MonkeyPatch, ) -> None: - cli = Cli() - # clear the output buffer capsys.readouterr() # read a option value diff --git a/pkgs/clan-cli/tests/test_create_flake.py b/pkgs/clan-cli/tests/test_create_flake.py index 2db3dae4..ae09e79a 100644 --- a/pkgs/clan-cli/tests/test_create_flake.py +++ b/pkgs/clan-cli/tests/test_create_flake.py @@ -3,12 +3,7 @@ import subprocess from pathlib import Path import pytest -from helpers.cli import Cli - - -@pytest.fixture -def cli() -> Cli: - return Cli() +from helpers import cli @pytest.mark.impure @@ -16,7 +11,6 @@ def test_create_flake( monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture, temporary_home: Path, - cli: Cli, clan_core: Path, ) -> None: flake_dir = temporary_home / "test-flake" @@ -56,7 +50,6 @@ def test_ui_template( monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture, temporary_home: Path, - cli: Cli, clan_core: Path, ) -> None: flake_dir = temporary_home / "test-flake" diff --git a/pkgs/clan-cli/tests/test_flakes_cli.py b/pkgs/clan-cli/tests/test_flakes_cli.py index e6c6a442..6bb57fc8 100644 --- a/pkgs/clan-cli/tests/test_flakes_cli.py +++ b/pkgs/clan-cli/tests/test_flakes_cli.py @@ -2,7 +2,7 @@ from typing import TYPE_CHECKING import pytest from fixtures_flakes import FlakeForTest -from helpers.cli import Cli +from helpers import cli if TYPE_CHECKING: pass @@ -12,7 +12,6 @@ if TYPE_CHECKING: def test_flakes_inspect( test_flake_with_core: FlakeForTest, capsys: pytest.CaptureFixture ) -> None: - cli = Cli() cli.run( [ "flakes", diff --git a/pkgs/clan-cli/tests/test_history_cli.py b/pkgs/clan-cli/tests/test_history_cli.py index 284c302e..d08b1bb6 100644 --- a/pkgs/clan-cli/tests/test_history_cli.py +++ b/pkgs/clan-cli/tests/test_history_cli.py @@ -3,7 +3,7 @@ from typing import TYPE_CHECKING import pytest from fixtures_flakes import FlakeForTest -from helpers.cli import Cli +from helpers import cli from pytest import CaptureFixture from clan_cli.dirs import user_history_file @@ -17,7 +17,6 @@ if TYPE_CHECKING: def test_history_add( test_flake_with_core: FlakeForTest, ) -> None: - cli = Cli() cmd = [ "history", "add", @@ -36,7 +35,6 @@ def test_history_list( capsys: CaptureFixture, test_flake_with_core: FlakeForTest, ) -> None: - cli = Cli() cmd = [ "history", "list", diff --git a/pkgs/clan-cli/tests/test_import_sops_cli.py b/pkgs/clan-cli/tests/test_import_sops_cli.py index 52770dfb..1147a5e7 100644 --- a/pkgs/clan-cli/tests/test_import_sops_cli.py +++ b/pkgs/clan-cli/tests/test_import_sops_cli.py @@ -3,7 +3,7 @@ from typing import TYPE_CHECKING import pytest from fixtures_flakes import FlakeForTest -from helpers.cli import Cli +from helpers import cli if TYPE_CHECKING: from age_keys import KeyPair @@ -16,8 +16,6 @@ def test_import_sops( monkeypatch: pytest.MonkeyPatch, age_keys: list["KeyPair"], ) -> None: - cli = Cli() - monkeypatch.setenv("SOPS_AGE_KEY", age_keys[1].privkey) cli.run( [ diff --git a/pkgs/clan-cli/tests/test_machines_cli.py b/pkgs/clan-cli/tests/test_machines_cli.py index 399f0a3a..10c8f22a 100644 --- a/pkgs/clan-cli/tests/test_machines_cli.py +++ b/pkgs/clan-cli/tests/test_machines_cli.py @@ -1,13 +1,12 @@ import pytest from fixtures_flakes import FlakeForTest -from helpers.cli import Cli +from helpers import cli @pytest.mark.impure def test_machine_subcommands( test_flake_with_core: FlakeForTest, capsys: pytest.CaptureFixture ) -> None: - cli = Cli() cli.run( ["machines", "create", "--flake", str(test_flake_with_core.path), "machine1"] ) diff --git a/pkgs/clan-cli/tests/test_modules.py b/pkgs/clan-cli/tests/test_modules.py index 7c644dd1..72d5c3bc 100644 --- a/pkgs/clan-cli/tests/test_modules.py +++ b/pkgs/clan-cli/tests/test_modules.py @@ -13,7 +13,7 @@ from clan_cli.nix import nix_eval, run_no_stdout if TYPE_CHECKING: from age_keys import KeyPair -from helpers.cli import Cli +from helpers import cli from clan_cli.machines.facts import machine_get_fact @@ -39,7 +39,6 @@ def test_add_module_to_inventory( monkeypatch.chdir(test_flake_with_core.path) monkeypatch.setenv("SOPS_AGE_KEY", age_keys[0].privkey) - cli = Cli() cli.run( [ "secrets", diff --git a/pkgs/clan-cli/tests/test_secrets_cli.py b/pkgs/clan-cli/tests/test_secrets_cli.py index c1402209..f47fe8eb 100644 --- a/pkgs/clan-cli/tests/test_secrets_cli.py +++ b/pkgs/clan-cli/tests/test_secrets_cli.py @@ -6,7 +6,7 @@ from typing import TYPE_CHECKING import pytest from fixtures_flakes import FlakeForTest -from helpers.cli import Cli +from helpers import cli from clan_cli.errors import ClanError @@ -22,7 +22,6 @@ def _test_identities( capsys: pytest.CaptureFixture, age_keys: list["KeyPair"], ) -> None: - cli = Cli() sops_folder = test_flake.path / "sops" cli.run( @@ -111,7 +110,6 @@ def test_machines( def test_groups( test_flake: FlakeForTest, capsys: pytest.CaptureFixture, age_keys: list["KeyPair"] ) -> None: - cli = Cli() capsys.readouterr() # empty the buffer cli.run(["secrets", "groups", "list", "--flake", str(test_flake.path)]) assert capsys.readouterr().out == "" @@ -249,7 +247,6 @@ def test_secrets( monkeypatch: pytest.MonkeyPatch, age_keys: list["KeyPair"], ) -> None: - cli = Cli() capsys.readouterr() # empty the buffer cli.run(["secrets", "list", "--flake", str(test_flake.path)]) assert capsys.readouterr().out == "" diff --git a/pkgs/clan-cli/tests/test_secrets_generate.py b/pkgs/clan-cli/tests/test_secrets_generate.py index 41ce3436..b301a63d 100644 --- a/pkgs/clan-cli/tests/test_secrets_generate.py +++ b/pkgs/clan-cli/tests/test_secrets_generate.py @@ -3,7 +3,7 @@ from typing import TYPE_CHECKING import pytest from fixtures_flakes import FlakeForTest -from helpers.cli import Cli +from helpers import cli from helpers.validator import is_valid_age_key, is_valid_ssh_key from clan_cli.clan_uri import FlakeId @@ -24,7 +24,6 @@ def test_generate_secret( ) -> None: monkeypatch.chdir(test_flake_with_core.path) monkeypatch.setenv("SOPS_AGE_KEY", age_keys[0].privkey) - cli = Cli() cli.run( [ "secrets", diff --git a/pkgs/clan-cli/tests/test_secrets_password_store.py b/pkgs/clan-cli/tests/test_secrets_password_store.py index 2f813b1a..80045f73 100644 --- a/pkgs/clan-cli/tests/test_secrets_password_store.py +++ b/pkgs/clan-cli/tests/test_secrets_password_store.py @@ -3,7 +3,7 @@ from pathlib import Path import pytest from fixtures_flakes import FlakeForTest -from helpers.cli import Cli +from helpers import cli from helpers.validator import is_valid_ssh_key from clan_cli.clan_uri import FlakeId @@ -37,7 +37,6 @@ def test_upload_secret( %no-protection """ ) - cli = Cli() subprocess.run( nix_shell( ["nixpkgs#gnupg"], ["gpg", "--batch", "--gen-key", str(gpg_key_spec)] diff --git a/pkgs/clan-cli/tests/test_secrets_upload.py b/pkgs/clan-cli/tests/test_secrets_upload.py index b246f35c..4bfde8ad 100644 --- a/pkgs/clan-cli/tests/test_secrets_upload.py +++ b/pkgs/clan-cli/tests/test_secrets_upload.py @@ -2,7 +2,7 @@ from typing import TYPE_CHECKING import pytest from fixtures_flakes import FlakeForTest -from helpers.cli import Cli +from helpers import cli from clan_cli.ssh import HostGroup @@ -20,7 +20,6 @@ def test_secrets_upload( monkeypatch.chdir(test_flake_with_core.path) monkeypatch.setenv("SOPS_AGE_KEY", age_keys[0].privkey) - cli = Cli() cli.run( [ "secrets", diff --git a/pkgs/clan-cli/tests/test_vars.py b/pkgs/clan-cli/tests/test_vars.py index 04a141b9..e7ccaf25 100644 --- a/pkgs/clan-cli/tests/test_vars.py +++ b/pkgs/clan-cli/tests/test_vars.py @@ -3,7 +3,7 @@ from typing import TYPE_CHECKING import pytest from fixtures_flakes import generate_flake -from helpers.cli import Cli +from helpers import cli from root import CLAN_CORE if TYPE_CHECKING: @@ -41,7 +41,6 @@ def test_generate_secret( ), ) monkeypatch.chdir(flake.path) - cli = Cli() cmd = ["vars", "generate", "--flake", str(flake.path), "my_machine"] cli.run(cmd) assert ( diff --git a/pkgs/clan-cli/tests/test_vms_cli.py b/pkgs/clan-cli/tests/test_vms_cli.py index fa654ce9..03561d41 100644 --- a/pkgs/clan-cli/tests/test_vms_cli.py +++ b/pkgs/clan-cli/tests/test_vms_cli.py @@ -8,7 +8,7 @@ from typing import TYPE_CHECKING import pytest from fixtures_flakes import FlakeForTest, generate_flake -from helpers.cli import Cli +from helpers import cli from root import CLAN_CORE from clan_cli.dirs import vm_state_dir @@ -25,7 +25,7 @@ def run_vm_in_thread(machine_name: str) -> None: # runs machine and prints exceptions def run() -> None: try: - Cli().run(["vms", "run", machine_name]) + cli.run(["vms", "run", machine_name]) except Exception: # print exception details print(traceback.format_exc(), file=sys.stderr) @@ -85,7 +85,6 @@ def qga_connect(state_dir: Path) -> QgaSession: def test_inspect( test_flake_with_core: FlakeForTest, capsys: pytest.CaptureFixture ) -> None: - cli = Cli() cli.run(["vms", "inspect", "--flake", str(test_flake_with_core.path), "vm1"]) out = capsys.readouterr() # empty the buffer assert "Cores" in out.out @@ -100,7 +99,6 @@ def test_run( ) -> None: monkeypatch.chdir(test_flake_with_core.path) monkeypatch.setenv("SOPS_AGE_KEY", age_keys[0].privkey) - cli = Cli() cli.run( [ "secrets",