Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Yikun Jiang <[email protected]>
  • Loading branch information
Yikun committed Oct 13, 2023
1 parent c0cd9c2 commit 2f9dfb5
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 11 deletions.
33 changes: 22 additions & 11 deletions bioconda_utils/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,27 @@ def get_subdags(dag, n_workers, worker_offset):
return subdags


def check_native_platform_skippable(recipe_folder: str, recipe: str):
"""
Given a recipe, check this recipe should skip in current platform or not.
Arguments:
recipe_folder: Directory containing possibly many, and possibly nested, recipes.
recipe: recipe name
Returns:
Return True if current native platform are not included in recipe's additional platforms (no need to build).
"""
recipe_obj = _recipe.Recipe.from_file(recipe_folder, recipe)
native_platform = utils.RepoData().native_platform()
# On linux-aarch64 env, only build recipe with linux-aarch64 extra_additional_platforms
if native_platform == "linux-aarch64":
if "linux-aarch64" not in recipe_obj.extra_additional_platforms:
logger.info("BUILD SKIP: skipping %s for %s platform", recipe, native_platform)
return True
return False


def build_recipes(recipe_folder: str, config_path: str, recipes: List[str],
mulled_test: bool = True, testonly: bool = False,
force: bool = False,
Expand Down Expand Up @@ -356,19 +377,9 @@ def build_recipes(recipe_folder: str, config_path: str, recipes: List[str],
skipped_recipes = []
failed_uploads = []

def skip_additional_platform():
recipe_obj = _recipe.Recipe.from_file(recipe_folder, recipe)
native_platform = utils.RepoData().native_platform()
# On linux-aarch64 env, only build recipe with linux-aarch64 additional_platforms
if native_platform == "linux-aarch64":
if "linux-aarch64" not in recipe_obj.extra_additional_platforms:
logger.info("BUILD SKIP: skipping %s for %s platform", recipe, native_platform)
return True
return False

for recipe, name in recipes:
# If not force, skip recipes that are not for this platform
if not force and skip_additional_platform():
if not force and check_native_platform_skippable(recipe_folder, recipe):
continue

if name in skip_dependent:
Expand Down
37 changes: 37 additions & 0 deletions test/test_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,33 @@
license: BSD
home: https://elsewhere
summary: the_summary
three:
folder: three
meta.yaml:
#{% set version="0.1" %}
package:
name: three
version: #{{version}}
source:
- url: https://somewhere # [osx]
sha256: 123 # [osx[
- url: https://somewhere # [linux]
sha256: 456 # [linux]
build:
number: 0
outputs:
- name: libthree
- name: three-tools
test:
commands:
- do nothing
about:
license: BSD
home: https://elsewhere
summary: the_summary
extra:
additional-platforms:
- linux-aarch64
"""
RECIPES = yaml.load(RECIPE_DATA)

Expand Down Expand Up @@ -258,6 +285,16 @@ def test_recipe_package_names(recipe):
assert recipe.package_names == expected


@with_recipes
def test_recipe_extra_additional_platforms(recipe):
expected = {
'one': [],
'two': [],
'three': ["linux-aarch64"]
}[recipe.name]
assert recipe.extra_additional_platforms == expected


@with_recipes
def test_get_deps_dict(recipe):
recipe.meta_yaml.extend([
Expand Down
37 changes: 37 additions & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import tempfile
import requests
import uuid
import unittest.mock
import contextlib
import tarfile
import logging
Expand Down Expand Up @@ -889,6 +890,42 @@ def test_load_meta_skipping():
assert utils.load_all_meta(recipe) == []


@unittest.mock.patch('bioconda_utils.utils.RepoData.native_platform')
def test_native_platform_skipping(func_mock):
expections = [
# Don't skip linux-x86 for any recipes
["one", "linux", False],
["two", "linux", False],
# Skip recipe without linux aarch64 enable on linux-aarch64 platform
["one", "linux-aarch64", True],
# Don't skip recipe with linux aarch64 enable on linux-aarch64 platform
["two", "linux-aarch64", False],
]
r = Recipes(
"""
one:
meta.yaml: |
package:
name: one
version: "0.1"
two:
meta.yaml: |
package:
name: one
version: "0.1"
extra:
additional-platforms:
- linux-aarch64
""", from_string=True)
r.write_recipes()
# Make sure RepoData singleton init
utils.RepoData.register_config(config_fixture)
for recipe_name, native_platform, result in expections:
recipe_folder = os.path.dirname(r.recipe_dirs[recipe_name])
func_mock.return_value = native_platform
assert build.check_native_platform_skippable(recipe_folder, r.recipe_dirs[recipe_name]) == result


def test_variants():
"""
Multiple variants should return multiple metadata
Expand Down

0 comments on commit 2f9dfb5

Please sign in to comment.