Skip to content

Commit

Permalink
update multi-output matrix test to cover script vars
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk committed Sep 18, 2024
1 parent 3306275 commit df502f9
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 69 deletions.
2 changes: 2 additions & 0 deletions tests/recipes/multiple_outputs/build-output1.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
echo %script_all%
echo %script_bat%
2 changes: 1 addition & 1 deletion tests/recipes/multiple_outputs/build-output1.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
echo "${script_only}"
echo "${script_all}"
2 changes: 2 additions & 0 deletions tests/recipes/multiple_outputs/build-output2.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
echo %script_all%
echo %script_bat%
2 changes: 1 addition & 1 deletion tests/recipes/multiple_outputs/build-output2.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
echo "${script_only}"
echo "${script_all}"
echo "${script_only_2}"
10 changes: 7 additions & 3 deletions tests/recipes/multiple_outputs/conda_build_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ unused:
- a
- b
# used in all output scripts
script_only:
# single value
script_all:
- a
- b
# used in output2 script
# used in output2 sh script
script_only_2:
- a2
- b2
# used in both outputs, only windows
script_bat:
- a2
- b2
# zip these just for testing purposes
zip_keys:
-
Expand Down
6 changes: 4 additions & 2 deletions tests/recipes/multiple_outputs/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ requirements:

outputs:
- name: test_output_1
script: build-output1.sh
script: build-output1.sh # [not win]
script: build-output1.bat # [win]
requirements:
- bzip2
test:
commands:
- test -e $PREFIX/lib/libz.so # [linux]
- test -e $PREFIX/lib/libz.dylib # [osx]
- name: test_output_2
script: build-output2.sh
script: build-output2.sh # [not win]
script: build-output2.bat # [win]
requirements:
host:
- jpeg
Expand Down
37 changes: 34 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import shutil
import subprocess
from pathlib import Path
from textwrap import dedent

import pytest
Expand Down Expand Up @@ -114,19 +115,23 @@ def test_init_multiple_output_matrix(testing_workdir):
temporary_directory=os.path.join(recipe, "temp"),
)
regen_obj(args)
matrix_dir = os.path.join(feedstock_dir, ".ci_support")
# the matrix should be consolidated among all outputs, as well as the top-level
# reqs. Only the top-level reqs should have indedependent config files,
# though - loops within outputs are contained in those top-level configs.
matrix_dir_len = len(os.listdir(matrix_dir))
assert matrix_dir_len == 13
matrix_dir = Path(feedstock_dir) / ".ci_support"
matrix_files = list(matrix_dir.glob("*.yaml"))
linux_libpng16 = matrix_dir / "linux_64_libpng1.6libpq9.5.yaml"
assert linux_libpng16 in matrix_files
assert len(matrix_files) == 16
linux_libpng16 = os.path.join(
matrix_dir, "linux_64_libpng1.6libpq9.5.yaml"
)
assert os.path.isfile(linux_libpng16)
with open(linux_libpng16) as f:
config = yaml.safe_load(f)
assert "libpng" in config
assert config["libpng"] == ["1.6"]
assert "libpq" in config
assert config["libpq"] == ["9.5"]
# this is a zipped key, but it's not used, so it shouldn't show up
assert "libtiff" not in config
Expand All @@ -139,6 +144,32 @@ def test_init_multiple_output_matrix(testing_workdir):
# not show up in the final configs.
assert "zlib" not in config

# script vars are present
assert "script_all" in config
assert config["script_all"] == ["a"]
assert "script_only_2" in config
assert config["script_only_2"] == ["a2", "b2"]

# windows script_bat shouldn't be in config
assert "script_bat" not in config

# check windows, which has additional axis
win_libpng16 = matrix_dir / "win_64_libpng1.5libpq9.6script_bata2.yaml"
assert win_libpng16 in matrix_files
with win_libpng16.open() as f:
config = yaml.safe_load(f)

# script vars are present
assert "script_all" in config
assert config["script_all"] == ["a"]

# sh-only var not in windows config
assert "script_only_2" not in config

# windows script_bat should be in config
assert "script_bat" in config
assert config["script_bat"] == ["a2"]


@pytest.mark.parametrize(
"dirname", ["multiple_outputs", "multiple_outputs2", "multiple_outputs3"]
Expand Down
85 changes: 26 additions & 59 deletions tests/test_configure_feedstock.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import shutil
import tempfile
import textwrap
from itertools import product
from pathlib import Path

import pytest
Expand Down Expand Up @@ -1982,67 +1981,19 @@ def test_get_used_key_values_by_input_order(
assert used_key_values == expected_used_key_values


def test_reduce_variants(config_yaml, jinja_env):
if config_yaml.type == "rattler-build":
pytest.skip("only conda-build")
_thisdir = os.path.abspath(os.path.dirname(__file__))
recipe = os.path.join(_thisdir, "recipes", "multiple_outputs")
dest_recipe = os.path.join(config_yaml.workdir, "recipe")
shutil.copytree(recipe, dest_recipe, dirs_exist_ok=True)

forge_config = configure_feedstock._load_forge_config(
config_yaml.workdir,
exclusive_config_file=os.path.join(
config_yaml.workdir, "recipe", "default_config.yaml"
),
)

configure_feedstock.render_azure(
jinja_env=jinja_env,
forge_config=forge_config,
forge_dir=config_yaml.workdir,
)
ci_support = Path(config_yaml.workdir) / ".ci_support"
all_yamls = list(ci_support.glob("linux*.yaml"))
print(all_yamls)
matrix_entry = next(iter(ci_support.glob("linux*.yaml")))
with matrix_entry.open() as f:
cbc = yaml.safe_load(f)
assert len(all_yamls) == 8 # 2 libpq * 2 libpng * 2 script_only
# top-level entries
assert "libpq" in cbc
assert len(cbc["libpq"]) == 1
assert "libpng" in cbc
assert len(cbc["libpng"]) == 1
assert "script_only" in cbc
assert len(cbc["script_only"]) == 1

# inner per-build variants
assert "jpeg" in cbc
assert len(cbc["jpeg"]) == 2
assert "script_only_2" in cbc
assert len(cbc["script_only_2"]) == 2

def test_conda_build_api_render_for_smithy(testing_workdir):
import conda_build.api

_thisdir = os.path.abspath(os.path.dirname(__file__))
recipe = os.path.join(_thisdir, "recipes", "multiple_outputs")
dest_recipe = os.path.join(testing_workdir, "recipe")
shutil.copytree(recipe, dest_recipe)
with open(os.path.join(dest_recipe, "conda_build_config.yaml")) as f:
cbc = yaml.safe_load(f)

# all variants
# libpng, libpq contribute to top-level build matrix entries
# jpeg, script_only, script_only_2 contribute to output-only variants (not top-level builds)
# make sure all variants are still captured
variant_keys = ("libpng", "libpq", "jpeg", "script_only", "script_only_2")

all_top_level_builds = set(
tuple(map(str, variant))
for variant in product(*(cbc[key] for key in variant_keys))
)
all_top_level_builds = {
("1.5", "9.5"),
("1.5", "9.6"),
("1.6", "9.5"),
("1.6", "9.6"),
}

cs_metas = configure_feedstock._conda_build_api_render_for_smithy(
dest_recipe,
Expand All @@ -2063,10 +2014,18 @@ def test_conda_build_api_render_for_smithy(testing_workdir):
for meta, _, _ in cs_metas:
for variant in meta.config.variants:
top_level_builds.add(
tuple(variant.get(key) for key in variant_keys)
(
variant.get("libpng"),
variant.get("libpq"),
)
)
variant = meta.config.variant
top_level_builds.add(tuple(variant.get(key) for key in variant_keys))
top_level_builds.add(
(
variant.get("libpng"),
variant.get("libpq"),
)
)
assert len(top_level_builds) == len(all_top_level_builds)
assert top_level_builds == all_top_level_builds
cb_metas = conda_build.api.render(
Expand All @@ -2089,10 +2048,18 @@ def test_conda_build_api_render_for_smithy(testing_workdir):
for meta, _, _ in cb_metas:
for variant in meta.config.variants:
top_level_builds.add(
tuple(variant.get(key) for key in variant_keys)
(
variant.get("libpng"),
variant.get("libpq"),
)
)
variant = meta.config.variant
top_level_builds.add(tuple(variant.get(key) for key in variant_keys))
top_level_builds.add(
(
variant.get("libpng"),
variant.get("libpq"),
)
)
assert len(top_level_builds) < len(all_top_level_builds)
assert top_level_builds.issubset(all_top_level_builds)

Expand Down

0 comments on commit df502f9

Please sign in to comment.