Merge pull request 'pkgs/cli: Move the test folder inside the python module' (#2973) from kenji/clan-core:split-testing-up into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/2973
This commit is contained in:
@@ -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 $@"
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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",
|
||||
]
|
||||
|
||||
|
||||
@@ -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:
|
||||
@@ -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(
|
||||
@@ -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
|
||||
@@ -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")
|
||||
@@ -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):
|
||||
@@ -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()
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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:
|
||||
@@ -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:
|
||||
@@ -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__)
|
||||
|
||||
@@ -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__)
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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(
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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__)
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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()
|
||||
@@ -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
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
'';
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user