Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hadim committed Nov 14, 2024
1 parent 9b96dc7 commit 7b8e20b
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 2 deletions.
6 changes: 6 additions & 0 deletions test-data/recipes/test_strategy/recipe-noarch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package:
name: testing-test-strategy
version: 0.0.1

build:
noarch: generic
3 changes: 3 additions & 0 deletions test-data/recipes/test_strategy/recipe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package:
name: testing-test-strategy
version: 0.0.1
16 changes: 16 additions & 0 deletions test/end-to-end/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
85 changes: 83 additions & 2 deletions test/end-to-end/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 warning on line 1080 in test/end-to-end/test_simple.py

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"adn" should be "and".
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!",
)

0 comments on commit 7b8e20b

Please sign in to comment.