cli-prep #41
@ -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"""
|
||||||
|
for project_file in [".clan-flake", ".git", ".hg", ".svn", "flake.nix"]:
|
||||||
initial_path = Path(os.getcwd())
|
initial_path = Path(os.getcwd())
|
||||||
path = Path(initial_path)
|
path = Path(initial_path)
|
||||||
while path.parent == path:
|
while path.parent == path:
|
||||||
project_files = [".clan-flake"]
|
|
||||||
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:
|
||||||
|
@ -8,8 +8,13 @@ description = "cLAN CLI tool"
|
|||||||
dynamic = [ "version" ]
|
dynamic = [ "version" ]
|
||||||
scripts = { clan = "clan_cli:main" }
|
scripts = { clan = "clan_cli:main" }
|
||||||
|
|
||||||
|
[tool.setuptools]
|
||||||
|
packages = [ "clan_cli" ]
|
||||||
|
|
||||||
[tool.pytest.ini_options]
|
[tool.pytest.ini_options]
|
||||||
addopts = "--cov . --cov-report term --cov-report html:.reports/html --no-cov-on-fail"
|
addopts = "--cov . --cov-report term --cov-report html:.reports/html --no-cov-on-fail"
|
||||||
|
norecursedirs = "tests/helpers"
|
||||||
|
|
||||||
|
|
||||||
[tool.mypy]
|
[tool.mypy]
|
||||||
python_version = "3.10"
|
python_version = "3.10"
|
||||||
@ -38,8 +43,8 @@ ignore = [ "E501" ]
|
|||||||
|
|
||||||
[tool.black]
|
[tool.black]
|
||||||
line-length = 88
|
line-length = 88
|
||||||
target-version = ['py310']
|
target-version = [ "py310" ]
|
||||||
include = '\.pyi?$'
|
include = "\\.pyi?$"
|
||||||
exclude = '''
|
exclude = '''
|
||||||
/(
|
/(
|
||||||
\.git
|
\.git
|
||||||
|
6
pkgs/clan-cli/tests/conftest.py
Normal file
6
pkgs/clan-cli/tests/conftest.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import os
|
||||||
|
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)
|
@ -3,12 +3,11 @@ from typing import Union
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import pytest_subprocess.fake_process
|
import pytest_subprocess.fake_process
|
||||||
|
from environment import mock_env
|
||||||
from pytest_subprocess import utils
|
from pytest_subprocess import utils
|
||||||
|
|
||||||
import clan_cli.ssh
|
import clan_cli.ssh
|
||||||
|
|
||||||
from .environment import mock_env
|
|
||||||
|
|
||||||
|
|
||||||
def test_no_args(
|
def test_no_args(
|
||||||
capsys: pytest.CaptureFixture, monkeypatch: pytest.MonkeyPatch
|
capsys: pytest.CaptureFixture, monkeypatch: pytest.MonkeyPatch
|
||||||
|
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()
|
Loading…
Reference in New Issue
Block a user