generated from Luis/nextjs-python-web-template
write test for get_clan_flake_toplevel
This commit is contained in:
@@ -2,18 +2,19 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from .errors import ClanError
|
||||||
|
|
||||||
|
|
||||||
def get_clan_flake_toplevel() -> Path:
|
def get_clan_flake_toplevel() -> Path:
|
||||||
"""Returns the path to the toplevel of the clan flake"""
|
"""Returns the path to the toplevel of the clan flake"""
|
||||||
initial_path = Path(os.getcwd())
|
for project_file in [".clan-flake", ".git", ".hg", ".svn", "flake.nix"]:
|
||||||
path = Path(initial_path)
|
initial_path = Path(os.getcwd())
|
||||||
while path.parent == path:
|
path = Path(initial_path)
|
||||||
project_files = [".clan-flake"]
|
while path.parent == path:
|
||||||
for project_file in project_files:
|
|
||||||
if (path / project_file).exists():
|
if (path / project_file).exists():
|
||||||
return path
|
return path
|
||||||
path = path.parent
|
path = path.parent
|
||||||
return initial_path
|
raise ClanError("Could not find clan flake toplevel directory")
|
||||||
|
|
||||||
|
|
||||||
def user_data_dir() -> Path:
|
def user_data_dir() -> Path:
|
||||||
|
|||||||
@@ -1,2 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
sys.path.append(os.path.join(os.path.dirname(__file__), 'helpers'))
|
import sys
|
||||||
|
|
||||||
|
sys.path.append(os.path.join(os.path.dirname(__file__), "helpers"))
|
||||||
|
|
||||||
|
pytest_plugins = ["temporary_dir"]
|
||||||
|
|||||||
11
pkgs/clan-cli/tests/temporary_dir.py
Normal file
11
pkgs/clan-cli/tests/temporary_dir.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import tempfile
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Iterator
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def temporary_dir() -> Iterator[Path]:
|
||||||
|
with tempfile.TemporaryDirectory(prefix="pytest-") as dirpath:
|
||||||
|
yield Path(dirpath)
|
||||||
14
pkgs/clan-cli/tests/test_dirs.py
Normal file
14
pkgs/clan-cli/tests/test_dirs.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from clan_cli.dirs import get_clan_flake_toplevel
|
||||||
|
from clan_cli.errors import ClanError
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_clan_flake_toplevel(
|
||||||
|
monkeypatch: pytest.MonkeyPatch, temporary_dir: Path
|
||||||
|
) -> None:
|
||||||
|
monkeypatch.chdir(temporary_dir)
|
||||||
|
with pytest.raises(ClanError):
|
||||||
|
get_clan_flake_toplevel()
|
||||||
Reference in New Issue
Block a user