From 35b7f7d7f1ef7180e29dd77a76c40ed8a39476c6 Mon Sep 17 00:00:00 2001 From: Hofer-Julian <30049909+Hofer-Julian@users.noreply.github.com> Date: Wed, 4 Dec 2024 09:59:30 +0100 Subject: [PATCH] test: reorganize `pixi build` tests (#2639) - move test data to common directory - move helper functions to fixtures --- .../rattler-build-backend/pixi/pixi.toml | 0 .../recipes/boltons/recipe.yaml | 0 .../recipes/smokey/recipe.yaml | 0 .../rattler-build-backend/smokey/pixi.toml | 0 tests/integration_python/conftest.py | 9 ++++-- .../integration_python/pixi_build/conftest.py | 18 +++++++++++ .../pixi_build/test_build.py | 31 +++++-------------- 7 files changed, 33 insertions(+), 25 deletions(-) rename tests/{integration_python/pixi_build/test-data => data/pixi_build}/rattler-build-backend/pixi/pixi.toml (100%) rename tests/{integration_python/pixi_build/test-data => data/pixi_build}/rattler-build-backend/recipes/boltons/recipe.yaml (100%) rename tests/{integration_python/pixi_build/test-data => data/pixi_build}/rattler-build-backend/recipes/smokey/recipe.yaml (100%) rename tests/{integration_python/pixi_build/test-data => data/pixi_build}/rattler-build-backend/smokey/pixi.toml (100%) diff --git a/tests/integration_python/pixi_build/test-data/rattler-build-backend/pixi/pixi.toml b/tests/data/pixi_build/rattler-build-backend/pixi/pixi.toml similarity index 100% rename from tests/integration_python/pixi_build/test-data/rattler-build-backend/pixi/pixi.toml rename to tests/data/pixi_build/rattler-build-backend/pixi/pixi.toml diff --git a/tests/integration_python/pixi_build/test-data/rattler-build-backend/recipes/boltons/recipe.yaml b/tests/data/pixi_build/rattler-build-backend/recipes/boltons/recipe.yaml similarity index 100% rename from tests/integration_python/pixi_build/test-data/rattler-build-backend/recipes/boltons/recipe.yaml rename to tests/data/pixi_build/rattler-build-backend/recipes/boltons/recipe.yaml diff --git a/tests/integration_python/pixi_build/test-data/rattler-build-backend/recipes/smokey/recipe.yaml b/tests/data/pixi_build/rattler-build-backend/recipes/smokey/recipe.yaml similarity index 100% rename from tests/integration_python/pixi_build/test-data/rattler-build-backend/recipes/smokey/recipe.yaml rename to tests/data/pixi_build/rattler-build-backend/recipes/smokey/recipe.yaml diff --git a/tests/integration_python/pixi_build/test-data/rattler-build-backend/smokey/pixi.toml b/tests/data/pixi_build/rattler-build-backend/smokey/pixi.toml similarity index 100% rename from tests/integration_python/pixi_build/test-data/rattler-build-backend/smokey/pixi.toml rename to tests/data/pixi_build/rattler-build-backend/smokey/pixi.toml diff --git a/tests/integration_python/conftest.py b/tests/integration_python/conftest.py index 607636591..9b963831b 100644 --- a/tests/integration_python/conftest.py +++ b/tests/integration_python/conftest.py @@ -29,8 +29,13 @@ def tmp_pixi_workspace(tmp_path: Path) -> Path: @pytest.fixture -def channels() -> Path: - return Path(__file__).parent.parent.joinpath("data", "channels", "channels").resolve() +def test_data() -> Path: + return Path(__file__).parents[1].joinpath("data").resolve() + + +@pytest.fixture +def channels(test_data: Path) -> Path: + return test_data.joinpath("channels", "channels") @pytest.fixture diff --git a/tests/integration_python/pixi_build/conftest.py b/tests/integration_python/pixi_build/conftest.py index e69de29bb..e284688fe 100644 --- a/tests/integration_python/pixi_build/conftest.py +++ b/tests/integration_python/pixi_build/conftest.py @@ -0,0 +1,18 @@ +from pathlib import Path +import pytest + + +@pytest.fixture +def build_data(test_data: Path) -> Path: + """ + Returns the pixi build test data + """ + return test_data.joinpath("pixi_build") + + +@pytest.fixture +def examples_dir() -> Path: + """ + Returns the path to the examples directory in the root of the repository + """ + return Path(__file__).parents[3].joinpath("examples").resolve() diff --git a/tests/integration_python/pixi_build/test_build.py b/tests/integration_python/pixi_build/test_build.py index c73311617..d2a533d6f 100644 --- a/tests/integration_python/pixi_build/test_build.py +++ b/tests/integration_python/pixi_build/test_build.py @@ -6,28 +6,11 @@ from ..common import verify_cli_command -def get_data_dir(backend: str | None = None) -> Path: - """ - Returns the path to the test-data directory next to the tests - """ - if backend is None: - return Path(__file__).parent / "test-data" - else: - return Path(__file__).parent / "test-data" / backend - - -def examples_dir() -> Path: - """ - Returns the path to the examples directory in the root of the repository - """ - return (Path(__file__).parent / "../../../examples").resolve() - - -def test_build_conda_package(pixi: Path, tmp_pixi_workspace: Path) -> None: +def test_build_conda_package(pixi: Path, examples_dir: Path, tmp_pixi_workspace: Path) -> None: """ This one tries to build the example flask hello world project """ - pyproject = examples_dir() / "flask-hello-world-pyproject" + pyproject = examples_dir / "flask-hello-world-pyproject" shutil.copytree(pyproject, tmp_pixi_workspace / "pyproject") manifest_path = tmp_pixi_workspace / "pyproject" / "pyproject.toml" @@ -53,8 +36,10 @@ def test_build_conda_package(pixi: Path, tmp_pixi_workspace: Path) -> None: assert package_to_be_built.exists() -def test_build_using_rattler_build_backend(pixi: Path, tmp_pixi_workspace: Path) -> None: - test_data = get_data_dir("rattler-build-backend") +def test_build_using_rattler_build_backend( + pixi: Path, build_data: Path, tmp_pixi_workspace: Path +) -> None: + test_data = build_data.joinpath("rattler-build-backend") shutil.copytree(test_data / "pixi", tmp_pixi_workspace / "pixi") shutil.copyfile( test_data / "recipes/smokey/recipe.yaml", tmp_pixi_workspace / "pixi/recipe.yaml" @@ -74,8 +59,8 @@ def test_build_using_rattler_build_backend(pixi: Path, tmp_pixi_workspace: Path) assert package_to_be_built.exists() -def test_smokey(pixi: Path, tmp_pixi_workspace: Path) -> None: - test_data = get_data_dir("rattler-build-backend") +def test_smokey(pixi: Path, build_data: Path, tmp_pixi_workspace: Path) -> None: + test_data = build_data.joinpath("rattler-build-backend") # copy the whole smokey project to the tmp_pixi_workspace shutil.copytree(test_data, tmp_pixi_workspace / "test_data") manifest_path = tmp_pixi_workspace / "test_data" / "smokey" / "pixi.toml"