move machine_flake fixture to its own file
This commit is contained in:
@@ -1,12 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import Generator
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from clan_cli.dirs import nixpkgs_source
|
|
||||||
|
|
||||||
sys.path.append(os.path.join(os.path.dirname(__file__), "helpers"))
|
sys.path.append(os.path.join(os.path.dirname(__file__), "helpers"))
|
||||||
|
|
||||||
@@ -20,32 +13,5 @@ pytest_plugins = [
|
|||||||
"command",
|
"command",
|
||||||
"ports",
|
"ports",
|
||||||
"host_group",
|
"host_group",
|
||||||
|
"machine_flake",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
|
||||||
def monkeymodule() -> Generator[pytest.MonkeyPatch, None, None]:
|
|
||||||
with pytest.MonkeyPatch.context() as mp:
|
|
||||||
yield mp
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
|
||||||
def machine_flake(monkeymodule: pytest.MonkeyPatch) -> Generator[Path, None, None]:
|
|
||||||
template = Path(__file__).parent / "machine_flake"
|
|
||||||
# copy the template to a new temporary location
|
|
||||||
with tempfile.TemporaryDirectory() as tmpdir_:
|
|
||||||
flake = Path(tmpdir_)
|
|
||||||
for path in template.glob("**/*"):
|
|
||||||
if path.is_dir():
|
|
||||||
(flake / path.relative_to(template)).mkdir()
|
|
||||||
else:
|
|
||||||
(flake / path.relative_to(template)).write_text(path.read_text())
|
|
||||||
# in the flake.nix file replace the string __CLAN_URL__ with the the clan flake
|
|
||||||
# provided by get_clan_flake_toplevel
|
|
||||||
flake_nix = flake / "flake.nix"
|
|
||||||
flake_nix.write_text(
|
|
||||||
flake_nix.read_text().replace("__NIXPKGS__", str(nixpkgs_source()))
|
|
||||||
)
|
|
||||||
# check that an empty config is returned if no json file exists
|
|
||||||
monkeymodule.chdir(flake)
|
|
||||||
yield flake
|
|
||||||
|
|||||||
34
pkgs/clan-cli/tests/machine_flake.py
Normal file
34
pkgs/clan-cli/tests/machine_flake.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Generator
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from clan_cli.dirs import nixpkgs_source
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="module")
|
||||||
|
def monkeymodule() -> Generator[pytest.MonkeyPatch, None, None]:
|
||||||
|
with pytest.MonkeyPatch.context() as mp:
|
||||||
|
yield mp
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="module")
|
||||||
|
def machine_flake(monkeymodule: pytest.MonkeyPatch) -> Generator[Path, None, None]:
|
||||||
|
template = Path(__file__).parent / "machine_flake"
|
||||||
|
# copy the template to a new temporary location
|
||||||
|
with tempfile.TemporaryDirectory() as tmpdir_:
|
||||||
|
home = Path(tmpdir_)
|
||||||
|
flake = home / "machine_flake"
|
||||||
|
shutil.copytree(template, flake)
|
||||||
|
# in the flake.nix file replace the string __CLAN_URL__ with the the clan flake
|
||||||
|
# provided by get_clan_flake_toplevel
|
||||||
|
flake_nix = flake / "flake.nix"
|
||||||
|
flake_nix.write_text(
|
||||||
|
flake_nix.read_text().replace("__NIXPKGS__", str(nixpkgs_source()))
|
||||||
|
)
|
||||||
|
# check that an empty config is returned if no json file exists
|
||||||
|
monkeymodule.chdir(flake)
|
||||||
|
monkeymodule.setenv("HOME", str(home))
|
||||||
|
yield flake
|
||||||
Reference in New Issue
Block a user