From 7b8e20b7b607dd817b126a04d718a795e488ed3d Mon Sep 17 00:00:00 2001 From: Hadrien Mary Date: Thu, 14 Nov 2024 16:33:08 -0500 Subject: [PATCH] add tests --- .../recipes/test_strategy/recipe-noarch.yaml | 6 ++ test-data/recipes/test_strategy/recipe.yaml | 3 + test/end-to-end/helpers.py | 16 ++++ test/end-to-end/test_simple.py | 85 ++++++++++++++++++- 4 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 test-data/recipes/test_strategy/recipe-noarch.yaml create mode 100644 test-data/recipes/test_strategy/recipe.yaml diff --git a/test-data/recipes/test_strategy/recipe-noarch.yaml b/test-data/recipes/test_strategy/recipe-noarch.yaml new file mode 100644 index 000000000..4cf1d306f --- /dev/null +++ b/test-data/recipes/test_strategy/recipe-noarch.yaml @@ -0,0 +1,6 @@ +package: + name: testing-test-strategy + version: 0.0.1 + +build: + noarch: generic diff --git a/test-data/recipes/test_strategy/recipe.yaml b/test-data/recipes/test_strategy/recipe.yaml new file mode 100644 index 000000000..4a19cbd9e --- /dev/null +++ b/test-data/recipes/test_strategy/recipe.yaml @@ -0,0 +1,3 @@ +package: + name: testing-test-strategy + version: 0.0.1 diff --git a/test/end-to-end/helpers.py b/test/end-to-end/helpers.py index d6e8eeebb..eee2efc0d 100644 --- a/test/end-to-end/helpers.py +++ b/test/end-to-end/helpers.py @@ -89,3 +89,19 @@ def get_extracted_package(folder: Path, glob="*.tar.bz2"): extract_path = folder / "extract" / package_without_extension extract(str(package_path), dest_dir=str(extract_path)) return extract_path + + +def check_build_output( + rattler_build: RattlerBuild, + capfd, + recipe_path, + output_path, + extra_args: list, + string_to_check: str, +): + """Run a build and check the output for a specific string.""" + + rattler_build.build(recipe_path, output_path, extra_args=extra_args) + _, err = capfd.readouterr() + print(err) # to debug in case it fails + assert string_to_check in err diff --git a/test/end-to-end/test_simple.py b/test/end-to-end/test_simple.py index 99f3771c2..de08f24ac 100644 --- a/test/end-to-end/test_simple.py +++ b/test/end-to-end/test_simple.py @@ -8,7 +8,8 @@ import pytest import requests import yaml -from helpers import RattlerBuild, get_extracted_package, get_package +from helpers import (RattlerBuild, check_build_output, get_extracted_package, + get_package) def test_functionality(rattler_build: RattlerBuild): @@ -111,7 +112,7 @@ def variant_hash(variant): def test_pkg_hash(rattler_build: RattlerBuild, recipes: Path, tmp_path: Path): - rattler_build.build(recipes / "pkg_hash", tmp_path, extra_args=["--no-test"]) + rattler_build.build(recipes / "pkg_hash", tmp_path, extra_args=["--test=skip"]) pkg = get_package(tmp_path, "pkg_hash") expected_hash = variant_hash({"target_platform": host_subdir()}) assert pkg.name.endswith(f"pkg_hash-1.0.0-{expected_hash}_my_pkg.tar.bz2") @@ -1009,3 +1010,83 @@ def test_pin_subpackage( ) pkg = get_extracted_package(tmp_path, "my.package-a") assert (pkg / "info/index.json").exists() + + +def test_testing_strategy( + rattler_build: RattlerBuild, + recipes: Path, + tmp_path: Path, + capfd, +): + # --test=skip + check_build_output( + rattler_build, + capfd, + recipe_path=recipes / "test_strategy" / "recipe.yaml", + output_path=tmp_path, + extra_args=["--test=skip"], + string_to_check="Skipping tests because the argument --test=skip was set", + ) + + # --test=native + check_build_output( + rattler_build, + capfd, + recipe_path=recipes / "test_strategy" / "recipe.yaml", + output_path=tmp_path, + extra_args=["--test=native"], + string_to_check="all tests passed!", + ) + + # --test=native and cross-compiling + check_build_output( + rattler_build, + capfd, + recipe_path=recipes / "test_strategy" / "recipe.yaml", + output_path=tmp_path, + extra_args=[ + "--test=native", + "--target-platform=linux-64", + "--build-platform=osx-64", + ], + string_to_check="Skipping tests because the argument " + "--test=native was set and the build is a cross-compilation", + ) + + # --test=native-and-emulated + check_build_output( + rattler_build, + capfd, + recipe_path=recipes / "test_strategy" / "recipe.yaml", + output_path=tmp_path, + extra_args=["--test=native-and-emulated"], + string_to_check="all tests passed!", + ) + + # --test=native-and-emulated and cross-compiling + check_build_output( + rattler_build, + capfd, + recipe_path=recipes / "test_strategy" / "recipe.yaml", + output_path=tmp_path, + extra_args=[ + "--test=native-and-emulated", + "--target-platform=linux-64", + "--build-platform=osx-64", + ], + string_to_check="all tests passed!", + ) + + # --test=native and cross-compiling adn noarch + check_build_output( + rattler_build, + capfd, + recipe_path=recipes / "test_strategy" / "recipe-noarch.yaml", + output_path=tmp_path, + extra_args=[ + "--test=native", + "--target-platform=linux-64", + "--build-platform=osx-64", + ], + string_to_check="all tests passed!", + )