From 0f2b6b2c063e8271bab5e6268695109844f67372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 28 Jul 2023 10:52:13 +0200 Subject: [PATCH 1/3] cli: explicitly list clan_cli package --- pkgs/clan-cli/pyproject.toml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pkgs/clan-cli/pyproject.toml b/pkgs/clan-cli/pyproject.toml index ae423ee7..4a1342cf 100644 --- a/pkgs/clan-cli/pyproject.toml +++ b/pkgs/clan-cli/pyproject.toml @@ -1,12 +1,15 @@ [build-system] -requires = ["setuptools"] +requires = [ "setuptools" ] build-backend = "setuptools.build_meta" [project] name = "clan" description = "cLAN CLI tool" -dynamic = ["version"] -scripts = {clan = "clan_cli:main"} +dynamic = [ "version" ] +scripts = { clan = "clan_cli:main" } + +[tool.setuptools] +packages = [ "clan_cli" ] [tool.pytest.ini_options] addopts = "--cov . --cov-report term --cov-report html:.reports/html --no-cov-on-fail" @@ -33,13 +36,13 @@ ignore_missing_imports = true [tool.ruff] line-length = 88 -select = ["E", "F", "I"] +select = [ "E", "F", "I" ] ignore = [ "E501" ] [tool.black] line-length = 88 -target-version = ['py310'] -include = '\.pyi?$' +target-version = [ "py310" ] +include = "\\.pyi?$" exclude = ''' /( \.git -- 2.45.2 From f3a451f85cc61a78b806367e93d1ceed9b615296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 28 Jul 2023 12:10:07 +0200 Subject: [PATCH 2/3] move environment to helpers module This fixes registering pytest plugins --- pkgs/clan-cli/pyproject.toml | 2 ++ pkgs/clan-cli/tests/__init__.py | 0 pkgs/clan-cli/tests/conftest.py | 2 ++ pkgs/clan-cli/tests/{ => helpers}/environment.py | 0 pkgs/clan-cli/tests/test_clan_ssh.py | 3 +-- 5 files changed, 5 insertions(+), 2 deletions(-) delete mode 100644 pkgs/clan-cli/tests/__init__.py create mode 100644 pkgs/clan-cli/tests/conftest.py rename pkgs/clan-cli/tests/{ => helpers}/environment.py (100%) diff --git a/pkgs/clan-cli/pyproject.toml b/pkgs/clan-cli/pyproject.toml index 4a1342cf..58067e66 100644 --- a/pkgs/clan-cli/pyproject.toml +++ b/pkgs/clan-cli/pyproject.toml @@ -13,6 +13,8 @@ packages = [ "clan_cli" ] [tool.pytest.ini_options] addopts = "--cov . --cov-report term --cov-report html:.reports/html --no-cov-on-fail" +norecursedirs = "tests/helpers" + [tool.mypy] python_version = "3.10" diff --git a/pkgs/clan-cli/tests/__init__.py b/pkgs/clan-cli/tests/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/pkgs/clan-cli/tests/conftest.py b/pkgs/clan-cli/tests/conftest.py new file mode 100644 index 00000000..b389b367 --- /dev/null +++ b/pkgs/clan-cli/tests/conftest.py @@ -0,0 +1,2 @@ +import os +sys.path.append(os.path.join(os.path.dirname(__file__), 'helpers')) diff --git a/pkgs/clan-cli/tests/environment.py b/pkgs/clan-cli/tests/helpers/environment.py similarity index 100% rename from pkgs/clan-cli/tests/environment.py rename to pkgs/clan-cli/tests/helpers/environment.py diff --git a/pkgs/clan-cli/tests/test_clan_ssh.py b/pkgs/clan-cli/tests/test_clan_ssh.py index 628bc0ec..ed1d366e 100644 --- a/pkgs/clan-cli/tests/test_clan_ssh.py +++ b/pkgs/clan-cli/tests/test_clan_ssh.py @@ -3,12 +3,11 @@ from typing import Union import pytest import pytest_subprocess.fake_process +from environment import mock_env from pytest_subprocess import utils import clan_cli.ssh -from .environment import mock_env - def test_no_args( capsys: pytest.CaptureFixture, monkeypatch: pytest.MonkeyPatch -- 2.45.2 From f7da3fc735dcb12a80737449fa733b3d7dd13088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 28 Jul 2023 12:12:37 +0200 Subject: [PATCH 3/3] write test for get_clan_flake_toplevel --- pkgs/clan-cli/clan_cli/dirs.py | 15 ++++++++------- pkgs/clan-cli/tests/conftest.py | 6 +++++- pkgs/clan-cli/tests/temporary_dir.py | 11 +++++++++++ pkgs/clan-cli/tests/test_dirs.py | 14 ++++++++++++++ 4 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 pkgs/clan-cli/tests/temporary_dir.py create mode 100644 pkgs/clan-cli/tests/test_dirs.py diff --git a/pkgs/clan-cli/clan_cli/dirs.py b/pkgs/clan-cli/clan_cli/dirs.py index e895df02..514bbe12 100644 --- a/pkgs/clan-cli/clan_cli/dirs.py +++ b/pkgs/clan-cli/clan_cli/dirs.py @@ -2,18 +2,19 @@ import os import sys from pathlib import Path +from .errors import ClanError + def get_clan_flake_toplevel() -> Path: """Returns the path to the toplevel of the clan flake""" - initial_path = Path(os.getcwd()) - path = Path(initial_path) - while path.parent == path: - project_files = [".clan-flake"] - for project_file in project_files: + for project_file in [".clan-flake", ".git", ".hg", ".svn", "flake.nix"]: + initial_path = Path(os.getcwd()) + path = Path(initial_path) + while path.parent == path: if (path / project_file).exists(): return path - path = path.parent - return initial_path + path = path.parent + raise ClanError("Could not find clan flake toplevel directory") def user_data_dir() -> Path: diff --git a/pkgs/clan-cli/tests/conftest.py b/pkgs/clan-cli/tests/conftest.py index b389b367..f9b5b00d 100644 --- a/pkgs/clan-cli/tests/conftest.py +++ b/pkgs/clan-cli/tests/conftest.py @@ -1,2 +1,6 @@ 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"] diff --git a/pkgs/clan-cli/tests/temporary_dir.py b/pkgs/clan-cli/tests/temporary_dir.py new file mode 100644 index 00000000..91310f90 --- /dev/null +++ b/pkgs/clan-cli/tests/temporary_dir.py @@ -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) diff --git a/pkgs/clan-cli/tests/test_dirs.py b/pkgs/clan-cli/tests/test_dirs.py new file mode 100644 index 00000000..e3794906 --- /dev/null +++ b/pkgs/clan-cli/tests/test_dirs.py @@ -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() -- 2.45.2