diff --git a/checks/impure/flake-module.nix b/checks/impure/flake-module.nix index 71a3446a3..d8cb4752f 100644 --- a/checks/impure/flake-module.nix +++ b/checks/impure/flake-module.nix @@ -30,7 +30,7 @@ # this disables dynamic dependency loading in clan-cli export CLAN_NO_DYNAMIC_DEPS=1 - nix develop "$ROOT#clan-cli" -c bash -c "TMPDIR=/tmp python -m pytest -m impure ./tests $@" + nix develop "$ROOT#clan-cli" -c bash -c "TMPDIR=/tmp python -m pytest -m impure ./clan_cli/tests $@" ''; }; } diff --git a/formatter.nix b/formatter.nix index 3ffe6e2fd..69571e244 100644 --- a/formatter.nix +++ b/formatter.nix @@ -51,10 +51,10 @@ "docs/site/static/asciinema-player/asciinema-player.css" "docs/site/static/asciinema-player/asciinema-player.min.js" "nixosModules/clanCore/vars/secret/sops/eval-tests/populated/vars/my_machine/my_generator/my_secret" - "pkgs/clan-cli/tests/data/gnupg.conf" - "pkgs/clan-cli/tests/data/password-store/.gpg-id" - "pkgs/clan-cli/tests/data/ssh_host_ed25519_key" - "pkgs/clan-cli/tests/data/sshd_config" + "pkgs/clan-cli/clan_cli/tests/data/gnupg.conf" + "pkgs/clan-cli/clan_cli/tests/data/password-store/.gpg-id" + "pkgs/clan-cli/clan_cli/tests/data/ssh_host_ed25519_key" + "pkgs/clan-cli/clan_cli/tests/data/sshd_config" "pkgs/clan-vm-manager/.vscode/lhebendanz.weaudit" "pkgs/clan-vm-manager/bin/clan-vm-manager" "pkgs/distro-packages/vagrant_insecure_key" diff --git a/pkgs/clan-cli/tests/conftest.py b/pkgs/clan-cli/clan_cli/conftest.py similarity index 50% rename from pkgs/clan-cli/tests/conftest.py rename to pkgs/clan-cli/clan_cli/conftest.py index 6cff106a9..12d1b89ff 100644 --- a/pkgs/clan-cli/tests/conftest.py +++ b/pkgs/clan-cli/clan_cli/conftest.py @@ -1,20 +1,23 @@ import pytest + from clan_cli.custom_logger import setup_logging +# collect_ignore = ["./nixpkgs"] + pytest_plugins = [ - "temporary_dir", - "root", - "age_keys", - "gpg_keys", - "git_repo", - "sshd", - "command", - "ports", - "hosts", - "runtime", - "fixtures_flakes", - "stdout", - "nix_config", + "clan_cli.tests.temporary_dir", + "clan_cli.tests.root", + "clan_cli.tests.age_keys", + "clan_cli.tests.gpg_keys", + "clan_cli.tests.git_repo", + "clan_cli.tests.sshd", + "clan_cli.tests.command", + "clan_cli.tests.ports", + "clan_cli.tests.hosts", + "clan_cli.tests.runtime", + "clan_cli.tests.fixtures_flakes", + "clan_cli.tests.stdout", + "clan_cli.tests.nix_config", ] diff --git a/pkgs/clan-cli/tests/age_keys.py b/pkgs/clan-cli/clan_cli/tests/age_keys.py similarity index 98% rename from pkgs/clan-cli/tests/age_keys.py rename to pkgs/clan-cli/clan_cli/tests/age_keys.py index 41162a287..2ee179e12 100644 --- a/pkgs/clan-cli/tests/age_keys.py +++ b/pkgs/clan-cli/clan_cli/tests/age_keys.py @@ -4,7 +4,7 @@ from pathlib import Path import pytest from clan_cli.secrets.folders import sops_secrets_folder -from helpers import cli +from clan_cli.tests.helpers import cli class KeyPair: diff --git a/pkgs/clan-cli/tests/command.py b/pkgs/clan-cli/clan_cli/tests/command.py similarity index 100% rename from pkgs/clan-cli/tests/command.py rename to pkgs/clan-cli/clan_cli/tests/command.py diff --git a/pkgs/clan-cli/tests/data/gnupg-home/openpgp-revocs.d/9A9B2741C8062D3D3DF1302D8B049E262A5CA255.rev b/pkgs/clan-cli/clan_cli/tests/data/gnupg-home/openpgp-revocs.d/9A9B2741C8062D3D3DF1302D8B049E262A5CA255.rev similarity index 100% rename from pkgs/clan-cli/tests/data/gnupg-home/openpgp-revocs.d/9A9B2741C8062D3D3DF1302D8B049E262A5CA255.rev rename to pkgs/clan-cli/clan_cli/tests/data/gnupg-home/openpgp-revocs.d/9A9B2741C8062D3D3DF1302D8B049E262A5CA255.rev diff --git a/pkgs/clan-cli/tests/data/gnupg-home/private-keys-v1.d/893F0D3827CC473BAEFE4A6B3E910245CD2CCFF9.key b/pkgs/clan-cli/clan_cli/tests/data/gnupg-home/private-keys-v1.d/893F0D3827CC473BAEFE4A6B3E910245CD2CCFF9.key similarity index 100% rename from pkgs/clan-cli/tests/data/gnupg-home/private-keys-v1.d/893F0D3827CC473BAEFE4A6B3E910245CD2CCFF9.key rename to pkgs/clan-cli/clan_cli/tests/data/gnupg-home/private-keys-v1.d/893F0D3827CC473BAEFE4A6B3E910245CD2CCFF9.key diff --git a/pkgs/clan-cli/tests/data/gnupg-home/pubring.kbx b/pkgs/clan-cli/clan_cli/tests/data/gnupg-home/pubring.kbx similarity index 100% rename from pkgs/clan-cli/tests/data/gnupg-home/pubring.kbx rename to pkgs/clan-cli/clan_cli/tests/data/gnupg-home/pubring.kbx diff --git a/pkgs/clan-cli/tests/data/gnupg-home/random_seed b/pkgs/clan-cli/clan_cli/tests/data/gnupg-home/random_seed similarity index 100% rename from pkgs/clan-cli/tests/data/gnupg-home/random_seed rename to pkgs/clan-cli/clan_cli/tests/data/gnupg-home/random_seed diff --git a/pkgs/clan-cli/tests/data/gnupg-home/trustdb.gpg b/pkgs/clan-cli/clan_cli/tests/data/gnupg-home/trustdb.gpg similarity index 100% rename from pkgs/clan-cli/tests/data/gnupg-home/trustdb.gpg rename to pkgs/clan-cli/clan_cli/tests/data/gnupg-home/trustdb.gpg diff --git a/pkgs/clan-cli/tests/data/gnupg.conf b/pkgs/clan-cli/clan_cli/tests/data/gnupg.conf similarity index 100% rename from pkgs/clan-cli/tests/data/gnupg.conf rename to pkgs/clan-cli/clan_cli/tests/data/gnupg.conf diff --git a/pkgs/clan-cli/tests/data/password-store/.gpg-id b/pkgs/clan-cli/clan_cli/tests/data/password-store/.gpg-id similarity index 100% rename from pkgs/clan-cli/tests/data/password-store/.gpg-id rename to pkgs/clan-cli/clan_cli/tests/data/password-store/.gpg-id diff --git a/pkgs/clan-cli/tests/data/secrets.yaml b/pkgs/clan-cli/clan_cli/tests/data/secrets.yaml similarity index 100% rename from pkgs/clan-cli/tests/data/secrets.yaml rename to pkgs/clan-cli/clan_cli/tests/data/secrets.yaml diff --git a/pkgs/clan-cli/tests/data/ssh_host_ed25519_key b/pkgs/clan-cli/clan_cli/tests/data/ssh_host_ed25519_key similarity index 100% rename from pkgs/clan-cli/tests/data/ssh_host_ed25519_key rename to pkgs/clan-cli/clan_cli/tests/data/ssh_host_ed25519_key diff --git a/pkgs/clan-cli/tests/data/ssh_host_ed25519_key.pub b/pkgs/clan-cli/clan_cli/tests/data/ssh_host_ed25519_key.pub similarity index 100% rename from pkgs/clan-cli/tests/data/ssh_host_ed25519_key.pub rename to pkgs/clan-cli/clan_cli/tests/data/ssh_host_ed25519_key.pub diff --git a/pkgs/clan-cli/tests/data/sshd_config b/pkgs/clan-cli/clan_cli/tests/data/sshd_config similarity index 100% rename from pkgs/clan-cli/tests/data/sshd_config rename to pkgs/clan-cli/clan_cli/tests/data/sshd_config diff --git a/pkgs/clan-cli/tests/fixture_error.py b/pkgs/clan-cli/clan_cli/tests/fixture_error.py similarity index 100% rename from pkgs/clan-cli/tests/fixture_error.py rename to pkgs/clan-cli/clan_cli/tests/fixture_error.py diff --git a/pkgs/clan-cli/tests/fixtures_flakes.py b/pkgs/clan-cli/clan_cli/tests/fixtures_flakes.py similarity index 97% rename from pkgs/clan-cli/tests/fixtures_flakes.py rename to pkgs/clan-cli/clan_cli/tests/fixtures_flakes.py index aba71fff0..f32566b74 100644 --- a/pkgs/clan-cli/tests/fixtures_flakes.py +++ b/pkgs/clan-cli/clan_cli/tests/fixtures_flakes.py @@ -9,14 +9,14 @@ from collections.abc import Callable, Iterator from pathlib import Path from typing import Any, NamedTuple -import age_keys import pytest from clan_cli.dirs import TemplateType, clan_templates, nixpkgs_source from clan_cli.locked_open import locked_open from clan_cli.nix import nix_test_store -from fixture_error import FixtureError -from root import CLAN_CORE -from temporary_dir import TEMPDIR +from clan_cli.tests import age_keys +from clan_cli.tests.fixture_error import FixtureError +from clan_cli.tests.root import CLAN_CORE +from clan_cli.tests.temporary_dir import TEMPDIR log = logging.getLogger(__name__) @@ -189,7 +189,8 @@ class ClanFlake: self.path / "machines" / machine_name / "configuration.nix" ) configuration_nix.parent.mkdir(parents=True, exist_ok=True) - configuration_nix.write_text(f""" + configuration_nix.write_text( + f""" {{clan-core, ...}}: {{ imports = [ @@ -197,7 +198,8 @@ class ClanFlake: {imports} ]; }} - """) + """ + ) set_machine_settings(self.path, machine_name, machine_config) sp.run(["git", "add", "."], cwd=self.path, check=True) sp.run( diff --git a/pkgs/clan-cli/tests/getpwnam-preload.c b/pkgs/clan-cli/clan_cli/tests/getpwnam-preload.c similarity index 100% rename from pkgs/clan-cli/tests/getpwnam-preload.c rename to pkgs/clan-cli/clan_cli/tests/getpwnam-preload.c diff --git a/pkgs/clan-cli/tests/git_repo.py b/pkgs/clan-cli/clan_cli/tests/git_repo.py similarity index 100% rename from pkgs/clan-cli/tests/git_repo.py rename to pkgs/clan-cli/clan_cli/tests/git_repo.py diff --git a/pkgs/clan-cli/tests/gpg_keys.py b/pkgs/clan-cli/clan_cli/tests/gpg_keys.py similarity index 100% rename from pkgs/clan-cli/tests/gpg_keys.py rename to pkgs/clan-cli/clan_cli/tests/gpg_keys.py diff --git a/pkgs/clan-cli/tests/helpers/__init__.py b/pkgs/clan-cli/clan_cli/tests/helpers/__init__.py similarity index 100% rename from pkgs/clan-cli/tests/helpers/__init__.py rename to pkgs/clan-cli/clan_cli/tests/helpers/__init__.py diff --git a/pkgs/clan-cli/tests/helpers/cli.py b/pkgs/clan-cli/clan_cli/tests/helpers/cli.py similarity index 100% rename from pkgs/clan-cli/tests/helpers/cli.py rename to pkgs/clan-cli/clan_cli/tests/helpers/cli.py diff --git a/pkgs/clan-cli/tests/helpers/nixos_config.py b/pkgs/clan-cli/clan_cli/tests/helpers/nixos_config.py similarity index 100% rename from pkgs/clan-cli/tests/helpers/nixos_config.py rename to pkgs/clan-cli/clan_cli/tests/helpers/nixos_config.py diff --git a/pkgs/clan-cli/tests/helpers/validator.py b/pkgs/clan-cli/clan_cli/tests/helpers/validator.py similarity index 100% rename from pkgs/clan-cli/tests/helpers/validator.py rename to pkgs/clan-cli/clan_cli/tests/helpers/validator.py diff --git a/pkgs/clan-cli/tests/hosts.py b/pkgs/clan-cli/clan_cli/tests/hosts.py similarity index 92% rename from pkgs/clan-cli/tests/hosts.py rename to pkgs/clan-cli/clan_cli/tests/hosts.py index 5f0b8cf60..7d08b9d59 100644 --- a/pkgs/clan-cli/tests/hosts.py +++ b/pkgs/clan-cli/clan_cli/tests/hosts.py @@ -4,7 +4,7 @@ import pwd import pytest from clan_cli.ssh.host import Host from clan_cli.ssh.host_key import HostKeyCheck -from sshd import Sshd +from clan_cli.tests.sshd import Sshd @pytest.fixture diff --git a/pkgs/clan-cli/tests/machines/vm1/default.nix b/pkgs/clan-cli/clan_cli/tests/machines/vm1/default.nix similarity index 100% rename from pkgs/clan-cli/tests/machines/vm1/default.nix rename to pkgs/clan-cli/clan_cli/tests/machines/vm1/default.nix diff --git a/pkgs/clan-cli/tests/machines/vm_with_secrets/default.nix b/pkgs/clan-cli/clan_cli/tests/machines/vm_with_secrets/default.nix similarity index 100% rename from pkgs/clan-cli/tests/machines/vm_with_secrets/default.nix rename to pkgs/clan-cli/clan_cli/tests/machines/vm_with_secrets/default.nix diff --git a/pkgs/clan-cli/tests/machines/vm_without_secrets/default.nix b/pkgs/clan-cli/clan_cli/tests/machines/vm_without_secrets/default.nix similarity index 100% rename from pkgs/clan-cli/tests/machines/vm_without_secrets/default.nix rename to pkgs/clan-cli/clan_cli/tests/machines/vm_without_secrets/default.nix diff --git a/pkgs/clan-cli/tests/nix_config.py b/pkgs/clan-cli/clan_cli/tests/nix_config.py similarity index 100% rename from pkgs/clan-cli/tests/nix_config.py rename to pkgs/clan-cli/clan_cli/tests/nix_config.py diff --git a/pkgs/clan-cli/tests/ports.py b/pkgs/clan-cli/clan_cli/tests/ports.py similarity index 100% rename from pkgs/clan-cli/tests/ports.py rename to pkgs/clan-cli/clan_cli/tests/ports.py diff --git a/pkgs/clan-cli/tests/root.py b/pkgs/clan-cli/clan_cli/tests/root.py similarity index 92% rename from pkgs/clan-cli/tests/root.py rename to pkgs/clan-cli/clan_cli/tests/root.py index 8593bd5e6..8caada40f 100644 --- a/pkgs/clan-cli/tests/root.py +++ b/pkgs/clan-cli/clan_cli/tests/root.py @@ -8,7 +8,7 @@ PROJECT_ROOT = TEST_ROOT.parent if CLAN_CORE_ := os.environ.get("CLAN_CORE_PATH"): CLAN_CORE = Path(CLAN_CORE_) else: - CLAN_CORE = PROJECT_ROOT.parent.parent + CLAN_CORE = PROJECT_ROOT.parent.parent.parent @pytest.fixture(scope="session") diff --git a/pkgs/clan-cli/tests/runtime.py b/pkgs/clan-cli/clan_cli/tests/runtime.py similarity index 100% rename from pkgs/clan-cli/tests/runtime.py rename to pkgs/clan-cli/clan_cli/tests/runtime.py diff --git a/pkgs/clan-cli/tests/sshd.py b/pkgs/clan-cli/clan_cli/tests/sshd.py similarity index 98% rename from pkgs/clan-cli/tests/sshd.py rename to pkgs/clan-cli/clan_cli/tests/sshd.py index 9245dd96b..caf6414f5 100644 --- a/pkgs/clan-cli/tests/sshd.py +++ b/pkgs/clan-cli/clan_cli/tests/sshd.py @@ -12,8 +12,8 @@ from typing import TYPE_CHECKING import pytest if TYPE_CHECKING: - from command import Command - from ports import PortFunction + from .command import Command + from .ports import PortFunction class SshdError(Exception): diff --git a/pkgs/clan-cli/tests/stdout.py b/pkgs/clan-cli/clan_cli/tests/stdout.py similarity index 100% rename from pkgs/clan-cli/tests/stdout.py rename to pkgs/clan-cli/clan_cli/tests/stdout.py diff --git a/pkgs/clan-cli/tests/temporary_dir.py b/pkgs/clan-cli/clan_cli/tests/temporary_dir.py similarity index 100% rename from pkgs/clan-cli/tests/temporary_dir.py rename to pkgs/clan-cli/clan_cli/tests/temporary_dir.py diff --git a/pkgs/clan-cli/tests/test_api_dataclass_compat.py b/pkgs/clan-cli/clan_cli/tests/test_api_dataclass_compat.py similarity index 92% rename from pkgs/clan-cli/tests/test_api_dataclass_compat.py rename to pkgs/clan-cli/clan_cli/tests/test_api_dataclass_compat.py index 8f63b9722..9f3c88dff 100644 --- a/pkgs/clan-cli/tests/test_api_dataclass_compat.py +++ b/pkgs/clan-cli/clan_cli/tests/test_api_dataclass_compat.py @@ -10,6 +10,15 @@ from clan_cli.api.util import JSchemaTypeError, type_to_dict from clan_cli.errors import ClanError +def should_skip(file_path: Path, excludes: list[Path]) -> bool: + file_path = file_path.resolve() # Ensure absolute path + for exclude in excludes: + exclude = exclude.resolve() + if exclude in file_path.parents or exclude == file_path: + return True # Skip this file + return False + + def find_dataclasses_in_directory( directory: Path, exclude_paths: list[str] | None = None ) -> list[tuple[Path, str]]: @@ -34,8 +43,7 @@ def find_dataclasses_in_directory( continue file_path = Path(root) / file - - if file_path in excludes: + if should_skip(file_path, excludes): print(f"Skipping dataclass check for file: {file_path}") continue @@ -78,11 +86,13 @@ def load_dataclass_from_file( try: sys.path.insert(0, root_dir) spec = importlib.util.spec_from_file_location(module_name, file_path) + print(spec) if not spec: msg = f"Could not load spec from file: {file_path}" raise ClanError(msg) module = importlib.util.module_from_spec(spec) + print(module) if not module: msg = f"Could not create module: {file_path}" raise ClanError(msg) @@ -121,6 +131,7 @@ def test_all_dataclasses() -> None: "api/__init__.py", "cmd.py", # We don't want the UI to have access to the cmd module anyway "async_run.py", # We don't want the UI to have access to the async_run module anyway + "tests", ] cli_path = Path("clan_cli").resolve() diff --git a/pkgs/clan-cli/tests/test_backups.py b/pkgs/clan-cli/clan_cli/tests/test_backups.py similarity index 74% rename from pkgs/clan-cli/tests/test_backups.py rename to pkgs/clan-cli/clan_cli/tests/test_backups.py index dd13a0d20..d0c15ff66 100644 --- a/pkgs/clan-cli/tests/test_backups.py +++ b/pkgs/clan-cli/clan_cli/tests/test_backups.py @@ -1,6 +1,6 @@ import pytest -from fixtures_flakes import FlakeForTest -from helpers import cli +from clan_cli.tests.fixtures_flakes import FlakeForTest +from clan_cli.tests.helpers import cli @pytest.mark.impure diff --git a/pkgs/clan-cli/tests/test_clan_nix_attrset.py b/pkgs/clan-cli/clan_cli/tests/test_clan_nix_attrset.py similarity index 99% rename from pkgs/clan-cli/tests/test_clan_nix_attrset.py rename to pkgs/clan-cli/clan_cli/tests/test_clan_nix_attrset.py index 00af21171..eae2a11e0 100644 --- a/pkgs/clan-cli/tests/test_clan_nix_attrset.py +++ b/pkgs/clan-cli/clan_cli/tests/test_clan_nix_attrset.py @@ -19,7 +19,7 @@ from clan_cli.templates import ( get_template, list_templates, ) -from fixtures_flakes import FlakeForTest +from clan_cli.tests.fixtures_flakes import FlakeForTest # Function to write clan attributes to a file diff --git a/pkgs/clan-cli/tests/test_clan_uri.py b/pkgs/clan-cli/clan_cli/tests/test_clan_uri.py similarity index 98% rename from pkgs/clan-cli/tests/test_clan_uri.py rename to pkgs/clan-cli/clan_cli/tests/test_clan_uri.py index d85b61680..34049e0b0 100644 --- a/pkgs/clan-cli/tests/test_clan_uri.py +++ b/pkgs/clan-cli/clan_cli/tests/test_clan_uri.py @@ -3,7 +3,7 @@ from pathlib import Path import pytest from clan_cli.clan_uri import ClanURI from clan_cli.flake import Flake -from fixtures_flakes import ClanFlake +from clan_cli.tests.fixtures_flakes import ClanFlake def test_get_url() -> None: diff --git a/pkgs/clan-cli/tests/test_cli.py b/pkgs/clan-cli/clan_cli/tests/test_cli.py similarity index 70% rename from pkgs/clan-cli/tests/test_cli.py rename to pkgs/clan-cli/clan_cli/tests/test_cli.py index 03b0c5ae1..8e6ee6a9f 100644 --- a/pkgs/clan-cli/tests/test_cli.py +++ b/pkgs/clan-cli/clan_cli/tests/test_cli.py @@ -1,6 +1,6 @@ import pytest -from helpers import cli -from stdout import CaptureOutput +from clan_cli.tests.helpers import cli +from clan_cli.tests.stdout import CaptureOutput def test_help(capture_output: CaptureOutput) -> None: diff --git a/pkgs/clan-cli/tests/test_create_flake.py b/pkgs/clan-cli/clan_cli/tests/test_create_flake.py similarity index 96% rename from pkgs/clan-cli/tests/test_create_flake.py rename to pkgs/clan-cli/clan_cli/tests/test_create_flake.py index ea50c1308..07f673858 100644 --- a/pkgs/clan-cli/tests/test_create_flake.py +++ b/pkgs/clan-cli/clan_cli/tests/test_create_flake.py @@ -5,9 +5,9 @@ from pathlib import Path import pytest from clan_cli.cmd import run from clan_cli.nix import nix_flake_show -from fixtures_flakes import FlakeForTest, substitute -from helpers import cli -from stdout import CaptureOutput +from clan_cli.tests.fixtures_flakes import FlakeForTest, substitute +from clan_cli.tests.helpers import cli +from clan_cli.tests.stdout import CaptureOutput log = logging.getLogger(__name__) diff --git a/pkgs/clan-cli/tests/test_deserializers.py b/pkgs/clan-cli/clan_cli/tests/test_deserializers.py similarity index 100% rename from pkgs/clan-cli/tests/test_deserializers.py rename to pkgs/clan-cli/clan_cli/tests/test_deserializers.py diff --git a/pkgs/clan-cli/tests/test_dirs.py b/pkgs/clan-cli/clan_cli/tests/test_dirs.py similarity index 100% rename from pkgs/clan-cli/tests/test_dirs.py rename to pkgs/clan-cli/clan_cli/tests/test_dirs.py diff --git a/pkgs/clan-cli/tests/test_flake/.clan-flake b/pkgs/clan-cli/clan_cli/tests/test_flake/.clan-flake similarity index 100% rename from pkgs/clan-cli/tests/test_flake/.clan-flake rename to pkgs/clan-cli/clan_cli/tests/test_flake/.clan-flake diff --git a/pkgs/clan-cli/tests/test_flake/fake-module.nix b/pkgs/clan-cli/clan_cli/tests/test_flake/fake-module.nix similarity index 100% rename from pkgs/clan-cli/tests/test_flake/fake-module.nix rename to pkgs/clan-cli/clan_cli/tests/test_flake/fake-module.nix diff --git a/pkgs/clan-cli/tests/test_flake/flake.nix b/pkgs/clan-cli/clan_cli/tests/test_flake/flake.nix similarity index 100% rename from pkgs/clan-cli/tests/test_flake/flake.nix rename to pkgs/clan-cli/clan_cli/tests/test_flake/flake.nix diff --git a/pkgs/clan-cli/tests/test_flake/nixosModules/machine1.nix b/pkgs/clan-cli/clan_cli/tests/test_flake/nixosModules/machine1.nix similarity index 100% rename from pkgs/clan-cli/tests/test_flake/nixosModules/machine1.nix rename to pkgs/clan-cli/clan_cli/tests/test_flake/nixosModules/machine1.nix diff --git a/pkgs/clan-cli/tests/test_flake_caching.py b/pkgs/clan-cli/clan_cli/tests/test_flake_caching.py similarity index 98% rename from pkgs/clan-cli/tests/test_flake_caching.py rename to pkgs/clan-cli/clan_cli/tests/test_flake_caching.py index 858bcedc3..d31a49dca 100644 --- a/pkgs/clan-cli/tests/test_flake_caching.py +++ b/pkgs/clan-cli/clan_cli/tests/test_flake_caching.py @@ -2,7 +2,7 @@ import logging import pytest from clan_cli.flake import Flake, FlakeCache, FlakeCacheEntry -from fixtures_flakes import ClanFlake +from clan_cli.tests.fixtures_flakes import ClanFlake log = logging.getLogger(__name__) diff --git a/pkgs/clan-cli/tests/test_flake_with_core/.clan-flake b/pkgs/clan-cli/clan_cli/tests/test_flake_with_core/.clan-flake similarity index 100% rename from pkgs/clan-cli/tests/test_flake_with_core/.clan-flake rename to pkgs/clan-cli/clan_cli/tests/test_flake_with_core/.clan-flake diff --git a/pkgs/clan-cli/tests/test_flake_with_core/flake.nix b/pkgs/clan-cli/clan_cli/tests/test_flake_with_core/flake.nix similarity index 100% rename from pkgs/clan-cli/tests/test_flake_with_core/flake.nix rename to pkgs/clan-cli/clan_cli/tests/test_flake_with_core/flake.nix diff --git a/pkgs/clan-cli/tests/test_flake_with_core_and_pass/.clan-flake b/pkgs/clan-cli/clan_cli/tests/test_flake_with_core_and_pass/.clan-flake similarity index 100% rename from pkgs/clan-cli/tests/test_flake_with_core_and_pass/.clan-flake rename to pkgs/clan-cli/clan_cli/tests/test_flake_with_core_and_pass/.clan-flake diff --git a/pkgs/clan-cli/tests/test_flake_with_core_and_pass/flake.nix b/pkgs/clan-cli/clan_cli/tests/test_flake_with_core_and_pass/flake.nix similarity index 100% rename from pkgs/clan-cli/tests/test_flake_with_core_and_pass/flake.nix rename to pkgs/clan-cli/clan_cli/tests/test_flake_with_core_and_pass/flake.nix diff --git a/pkgs/clan-cli/tests/test_flake_with_core_dynamic_machines/.clan-flake b/pkgs/clan-cli/clan_cli/tests/test_flake_with_core_dynamic_machines/.clan-flake similarity index 100% rename from pkgs/clan-cli/tests/test_flake_with_core_dynamic_machines/.clan-flake rename to pkgs/clan-cli/clan_cli/tests/test_flake_with_core_dynamic_machines/.clan-flake diff --git a/pkgs/clan-cli/tests/test_flake_with_core_dynamic_machines/flake.nix b/pkgs/clan-cli/clan_cli/tests/test_flake_with_core_dynamic_machines/flake.nix similarity index 100% rename from pkgs/clan-cli/tests/test_flake_with_core_dynamic_machines/flake.nix rename to pkgs/clan-cli/clan_cli/tests/test_flake_with_core_dynamic_machines/flake.nix diff --git a/pkgs/clan-cli/tests/test_flakes_cli.py b/pkgs/clan-cli/clan_cli/tests/test_flakes_cli.py similarity index 77% rename from pkgs/clan-cli/tests/test_flakes_cli.py rename to pkgs/clan-cli/clan_cli/tests/test_flakes_cli.py index 5ff74a2ef..7aad19526 100644 --- a/pkgs/clan-cli/tests/test_flakes_cli.py +++ b/pkgs/clan-cli/clan_cli/tests/test_flakes_cli.py @@ -1,9 +1,9 @@ from typing import TYPE_CHECKING import pytest -from fixtures_flakes import FlakeForTest -from helpers import cli -from stdout import CaptureOutput +from clan_cli.tests.fixtures_flakes import FlakeForTest +from clan_cli.tests.helpers import cli +from clan_cli.tests.stdout import CaptureOutput if TYPE_CHECKING: pass diff --git a/pkgs/clan-cli/tests/test_git.py b/pkgs/clan-cli/clan_cli/tests/test_git.py similarity index 100% rename from pkgs/clan-cli/tests/test_git.py rename to pkgs/clan-cli/clan_cli/tests/test_git.py diff --git a/pkgs/clan-cli/tests/test_history_cli.py b/pkgs/clan-cli/clan_cli/tests/test_history_cli.py similarity index 88% rename from pkgs/clan-cli/tests/test_history_cli.py rename to pkgs/clan-cli/clan_cli/tests/test_history_cli.py index 76cb57fda..2377fd70d 100644 --- a/pkgs/clan-cli/tests/test_history_cli.py +++ b/pkgs/clan-cli/clan_cli/tests/test_history_cli.py @@ -4,9 +4,9 @@ from typing import TYPE_CHECKING import pytest from clan_cli.dirs import user_history_file from clan_cli.history.add import HistoryEntry -from fixtures_flakes import FlakeForTest -from helpers import cli -from stdout import CaptureOutput +from clan_cli.tests.fixtures_flakes import FlakeForTest +from clan_cli.tests.helpers import cli +from clan_cli.tests.stdout import CaptureOutput if TYPE_CHECKING: pass diff --git a/pkgs/clan-cli/tests/test_import_sops_cli.py b/pkgs/clan-cli/clan_cli/tests/test_import_sops_cli.py similarity index 92% rename from pkgs/clan-cli/tests/test_import_sops_cli.py rename to pkgs/clan-cli/clan_cli/tests/test_import_sops_cli.py index ec0230877..09ca39cd5 100644 --- a/pkgs/clan-cli/tests/test_import_sops_cli.py +++ b/pkgs/clan-cli/clan_cli/tests/test_import_sops_cli.py @@ -2,12 +2,12 @@ from pathlib import Path from typing import TYPE_CHECKING import pytest -from fixtures_flakes import FlakeForTest -from helpers import cli -from stdout import CaptureOutput +from clan_cli.tests.fixtures_flakes import FlakeForTest +from clan_cli.tests.helpers import cli +from clan_cli.tests.stdout import CaptureOutput if TYPE_CHECKING: - from age_keys import KeyPair + from .age_keys import KeyPair def test_import_sops( diff --git a/pkgs/clan-cli/tests/test_inventory.py b/pkgs/clan-cli/clan_cli/tests/test_inventory.py similarity index 100% rename from pkgs/clan-cli/tests/test_inventory.py rename to pkgs/clan-cli/clan_cli/tests/test_inventory.py diff --git a/pkgs/clan-cli/tests/test_machines_cli.py b/pkgs/clan-cli/clan_cli/tests/test_machines_cli.py similarity index 95% rename from pkgs/clan-cli/tests/test_machines_cli.py rename to pkgs/clan-cli/clan_cli/tests/test_machines_cli.py index 4c4db7173..e6678a26b 100644 --- a/pkgs/clan-cli/tests/test_machines_cli.py +++ b/pkgs/clan-cli/clan_cli/tests/test_machines_cli.py @@ -1,10 +1,10 @@ -import fixtures_flakes import pytest -from age_keys import SopsSetup, assert_secrets_file_recipients from clan_cli.inventory import load_inventory_json from clan_cli.secrets.folders import sops_machines_folder -from helpers import cli -from stdout import CaptureOutput +from clan_cli.tests import fixtures_flakes +from clan_cli.tests.age_keys import SopsSetup, assert_secrets_file_recipients +from clan_cli.tests.helpers import cli +from clan_cli.tests.stdout import CaptureOutput @pytest.mark.impure diff --git a/pkgs/clan-cli/tests/test_modules.py b/pkgs/clan-cli/clan_cli/tests/test_modules.py similarity index 96% rename from pkgs/clan-cli/tests/test_modules.py rename to pkgs/clan-cli/clan_cli/tests/test_modules.py index fac5ade4b..a1261d276 100644 --- a/pkgs/clan-cli/tests/test_modules.py +++ b/pkgs/clan-cli/clan_cli/tests/test_modules.py @@ -13,14 +13,14 @@ from clan_cli.inventory import ( ) from clan_cli.machines.create import CreateOptions, create_machine from clan_cli.nix import nix_eval, run_no_stdout -from fixtures_flakes import FlakeForTest +from clan_cli.tests.fixtures_flakes import FlakeForTest if TYPE_CHECKING: - from age_keys import KeyPair + from .age_keys import KeyPair # from clan_cli.vars.var import machine_get_fact from clan_cli.machines.machines import Machine as MachineMachine -from helpers import cli +from clan_cli.tests.helpers import cli @pytest.mark.with_core diff --git a/pkgs/clan-cli/tests/test_patch_inventory.py b/pkgs/clan-cli/clan_cli/tests/test_patch_inventory.py similarity index 100% rename from pkgs/clan-cli/tests/test_patch_inventory.py rename to pkgs/clan-cli/clan_cli/tests/test_patch_inventory.py diff --git a/pkgs/clan-cli/tests/test_secrets_cli.py b/pkgs/clan-cli/clan_cli/tests/test_secrets_cli.py similarity index 98% rename from pkgs/clan-cli/tests/test_secrets_cli.py rename to pkgs/clan-cli/clan_cli/tests/test_secrets_cli.py index ec2229b5c..3789fe901 100644 --- a/pkgs/clan-cli/tests/test_secrets_cli.py +++ b/pkgs/clan-cli/clan_cli/tests/test_secrets_cli.py @@ -7,15 +7,15 @@ from contextlib import contextmanager from typing import TYPE_CHECKING import pytest -from age_keys import assert_secrets_file_recipients from clan_cli.errors import ClanError -from fixtures_flakes import FlakeForTest -from gpg_keys import GpgKey -from helpers import cli -from stdout import CaptureOutput +from clan_cli.tests.age_keys import assert_secrets_file_recipients +from clan_cli.tests.fixtures_flakes import FlakeForTest +from clan_cli.tests.gpg_keys import GpgKey +from clan_cli.tests.helpers import cli +from clan_cli.tests.stdout import CaptureOutput if TYPE_CHECKING: - from age_keys import KeyPair + from .age_keys import KeyPair log = logging.getLogger(__name__) diff --git a/pkgs/clan-cli/tests/test_secrets_generate.py b/pkgs/clan-cli/clan_cli/tests/test_secrets_generate.py similarity index 94% rename from pkgs/clan-cli/tests/test_secrets_generate.py rename to pkgs/clan-cli/clan_cli/tests/test_secrets_generate.py index e6556f25d..a49aa2d71 100644 --- a/pkgs/clan-cli/tests/test_secrets_generate.py +++ b/pkgs/clan-cli/clan_cli/tests/test_secrets_generate.py @@ -7,12 +7,12 @@ from clan_cli.flake import Flake from clan_cli.machines.facts import machine_get_fact from clan_cli.machines.machines import Machine from clan_cli.secrets.folders import sops_secrets_folder -from fixtures_flakes import FlakeForTest -from helpers import cli -from helpers.validator import is_valid_age_key +from clan_cli.tests.fixtures_flakes import FlakeForTest +from clan_cli.tests.helpers import cli +from clan_cli.tests.helpers.validator import is_valid_age_key if TYPE_CHECKING: - from age_keys import KeyPair + from .age_keys import KeyPair @pytest.mark.impure diff --git a/pkgs/clan-cli/tests/test_secrets_password_store.py b/pkgs/clan-cli/clan_cli/tests/test_secrets_password_store.py similarity index 97% rename from pkgs/clan-cli/tests/test_secrets_password_store.py rename to pkgs/clan-cli/clan_cli/tests/test_secrets_password_store.py index 76642fc53..ade387fc1 100644 --- a/pkgs/clan-cli/tests/test_secrets_password_store.py +++ b/pkgs/clan-cli/clan_cli/tests/test_secrets_password_store.py @@ -8,8 +8,8 @@ from clan_cli.machines.facts import machine_get_fact from clan_cli.machines.machines import Machine from clan_cli.nix import nix_shell from clan_cli.ssh.host import Host -from fixtures_flakes import ClanFlake -from helpers import cli +from clan_cli.tests.fixtures_flakes import ClanFlake +from clan_cli.tests.helpers import cli @pytest.mark.impure diff --git a/pkgs/clan-cli/tests/test_secrets_upload.py b/pkgs/clan-cli/clan_cli/tests/test_secrets_upload.py similarity index 93% rename from pkgs/clan-cli/tests/test_secrets_upload.py rename to pkgs/clan-cli/clan_cli/tests/test_secrets_upload.py index 8b3ed7930..4a25c30d0 100644 --- a/pkgs/clan-cli/tests/test_secrets_upload.py +++ b/pkgs/clan-cli/clan_cli/tests/test_secrets_upload.py @@ -2,11 +2,11 @@ from typing import TYPE_CHECKING import pytest from clan_cli.ssh.host import Host -from fixtures_flakes import ClanFlake -from helpers import cli +from clan_cli.tests.fixtures_flakes import ClanFlake +from clan_cli.tests.helpers import cli if TYPE_CHECKING: - from age_keys import KeyPair + from .age_keys import KeyPair @pytest.mark.with_core diff --git a/pkgs/clan-cli/tests/test_serializers.py b/pkgs/clan-cli/clan_cli/tests/test_serializers.py similarity index 100% rename from pkgs/clan-cli/tests/test_serializers.py rename to pkgs/clan-cli/clan_cli/tests/test_serializers.py diff --git a/pkgs/clan-cli/tests/test_ssh_local.py b/pkgs/clan-cli/clan_cli/tests/test_ssh_local.py similarity index 100% rename from pkgs/clan-cli/tests/test_ssh_local.py rename to pkgs/clan-cli/clan_cli/tests/test_ssh_local.py diff --git a/pkgs/clan-cli/tests/test_ssh_remote.py b/pkgs/clan-cli/clan_cli/tests/test_ssh_remote.py similarity index 100% rename from pkgs/clan-cli/tests/test_ssh_remote.py rename to pkgs/clan-cli/clan_cli/tests/test_ssh_remote.py diff --git a/pkgs/clan-cli/tests/test_vars.py b/pkgs/clan-cli/clan_cli/tests/test_vars.py similarity index 99% rename from pkgs/clan-cli/tests/test_vars.py rename to pkgs/clan-cli/clan_cli/tests/test_vars.py index f084b7af6..b8a306d8d 100644 --- a/pkgs/clan-cli/tests/test_vars.py +++ b/pkgs/clan-cli/clan_cli/tests/test_vars.py @@ -4,11 +4,13 @@ import shutil from pathlib import Path import pytest -from age_keys import SopsSetup from clan_cli.errors import ClanError from clan_cli.flake import Flake from clan_cli.machines.machines import Machine from clan_cli.nix import nix_eval, run +from clan_cli.tests.age_keys import SopsSetup +from clan_cli.tests.fixtures_flakes import ClanFlake +from clan_cli.tests.helpers import cli from clan_cli.vars.check import check_vars from clan_cli.vars.generate import Generator, generate_vars_for_machine from clan_cli.vars.get import get_var @@ -17,8 +19,6 @@ from clan_cli.vars.list import stringify_all_vars from clan_cli.vars.public_modules import in_repo from clan_cli.vars.secret_modules import password_store, sops from clan_cli.vars.set import set_var -from fixtures_flakes import ClanFlake -from helpers import cli def test_dependencies_as_files(temp_dir: Path) -> None: @@ -948,13 +948,15 @@ def test_dynamic_invalidation( # this is an abuse custom_nix = flake.path / "machines" / machine.name / "hardware-configuration.nix" - custom_nix.write_text(""" + custom_nix.write_text( + """ { config, ... }: let p = config.clan.core.vars.generators.my_generator.files.my_value.path; in { clan.core.vars.generators.dependent_generator.validation = if builtins.pathExists p then builtins.readFile p else null; } - """) + """ + ) flake.refresh() machine.flush_caches() diff --git a/pkgs/clan-cli/tests/test_vars_deployment.py b/pkgs/clan-cli/clan_cli/tests/test_vars_deployment.py similarity index 96% rename from pkgs/clan-cli/tests/test_vars_deployment.py rename to pkgs/clan-cli/clan_cli/tests/test_vars_deployment.py index f6923c59a..216062037 100644 --- a/pkgs/clan-cli/tests/test_vars_deployment.py +++ b/pkgs/clan-cli/clan_cli/tests/test_vars_deployment.py @@ -3,15 +3,15 @@ import subprocess from contextlib import ExitStack import pytest -from age_keys import SopsSetup from clan_cli import cmd from clan_cli.flake import Flake from clan_cli.machines.machines import Machine from clan_cli.nix import nix_eval, run +from clan_cli.tests.age_keys import SopsSetup +from clan_cli.tests.fixtures_flakes import ClanFlake +from clan_cli.tests.helpers import cli +from clan_cli.tests.nix_config import ConfigItem from clan_cli.vms.run import inspect_vm, spawn_vm -from fixtures_flakes import ClanFlake -from helpers import cli -from nix_config import ConfigItem @pytest.mark.impure diff --git a/pkgs/clan-cli/tests/test_vms_cli.py b/pkgs/clan-cli/clan_cli/tests/test_vms_cli.py similarity index 95% rename from pkgs/clan-cli/tests/test_vms_cli.py rename to pkgs/clan-cli/clan_cli/tests/test_vms_cli.py index 65fd4bb50..e3a7eb99b 100644 --- a/pkgs/clan-cli/tests/test_vms_cli.py +++ b/pkgs/clan-cli/clan_cli/tests/test_vms_cli.py @@ -4,13 +4,13 @@ from typing import TYPE_CHECKING import pytest from clan_cli.flake import Flake from clan_cli.machines.machines import Machine +from clan_cli.tests.fixtures_flakes import ClanFlake, FlakeForTest +from clan_cli.tests.helpers import cli +from clan_cli.tests.stdout import CaptureOutput from clan_cli.vms.run import inspect_vm, spawn_vm -from fixtures_flakes import ClanFlake, FlakeForTest -from helpers import cli -from stdout import CaptureOutput if TYPE_CHECKING: - from age_keys import KeyPair + from .age_keys import KeyPair no_kvm = not Path("/dev/kvm").exists() diff --git a/pkgs/clan-cli/default.nix b/pkgs/clan-cli/default.nix index d58a0cce5..0fd0f47cc 100644 --- a/pkgs/clan-cli/default.nix +++ b/pkgs/clan-cli/default.nix @@ -156,7 +156,7 @@ pythonRuntime.pkgs.buildPythonApplication { # limit build cores to 16 jobs="$((NIX_BUILD_CORES>16 ? 16 : NIX_BUILD_CORES))" - python -m pytest -m "not impure and not with_core" -n $jobs ./tests + python -m pytest -m "not impure and not with_core" -n $jobs ./clan_cli/tests touch $out ''; } @@ -209,7 +209,7 @@ pythonRuntime.pkgs.buildPythonApplication { # limit build cores to 16 jobs="$((NIX_BUILD_CORES>16 ? 16 : NIX_BUILD_CORES))" - python -m pytest -m "not impure and with_core" ./tests -n $jobs + python -m pytest -m "not impure and with_core" ./clan_cli/tests -n $jobs touch $out ''; };