Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into test_api_build_dll_…
Browse files Browse the repository at this point in the history
…package
  • Loading branch information
kenodegard committed Jan 18, 2023
2 parents 24aead4 + ce48a92 commit f4a3203
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 93 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
shell: bash

- name: Cache conda
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/conda_pkgs_dir
key: ${{ runner.os }}-conda-${{ env.TIMESTAMP }}
Expand Down Expand Up @@ -211,7 +211,7 @@ jobs:
shell: bash

- name: Cache conda
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/conda_pkgs_dir
key: ${{ runner.os }}-conda-${{ env.TIMESTAMP }}
Expand Down Expand Up @@ -327,7 +327,7 @@ jobs:
shell: bash

- name: Cache conda
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/conda_pkgs_dir
key: ${{ runner.os }}-conda-${{ env.TIMESTAMP }}
Expand Down
12 changes: 11 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,17 @@ def no_numpy_version():

@pytest.fixture(
scope="function",
params=[{}, {"MACOSX_DEPLOYMENT_TARGET": ["10.9"]}] if on_mac else [{}],
params=[
pytest.param({}, id="default MACOSX_DEPLOYMENT_TARGET"),
pytest.param(
{"MACOSX_DEPLOYMENT_TARGET": ["10.9"]},
id="override MACOSX_DEPLOYMENT_TARGET",
),
]
if on_mac
else [
pytest.param({}, id="no MACOSX_DEPLOYMENT_TARGET"),
],
)
def variants_conda_build_sysroot(monkeypatch, request):
if not on_mac:
Expand Down
14 changes: 4 additions & 10 deletions tests/test_api_build_go_package.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
# Copyright (C) 2014 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
import os
import pytest

from conda_build import api
from conda_build.api import build

from .utils import thisdir


@pytest.fixture()
def recipe():
return os.path.join(thisdir, 'test-recipes', 'go-package')
from .utils import go_dir


@pytest.mark.sanity
@pytest.mark.serial
def test_recipe_build(recipe, testing_config, testing_workdir, monkeypatch):
def test_recipe_build(testing_config, testing_workdir, monkeypatch):
# These variables are defined solely for testing purposes,
# so they can be checked within build scripts
testing_config.activate = True
monkeypatch.setenv("CONDA_TEST_VAR", "conda_test")
monkeypatch.setenv("CONDA_TEST_VAR_2", "conda_test_2")
api.build(recipe, config=testing_config)
build(go_dir, config=testing_config)
15 changes: 0 additions & 15 deletions tests/test_api_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,8 @@
from conda_build import api
from .utils import metadata_dir

thisdir = os.path.dirname(os.path.abspath(__file__))


@pytest.mark.sanity
def test_check_recipe():
"""Technically not inspect, but close enough to belong here"""
assert api.check(os.path.join(metadata_dir, "source_git_jinja2"))


# These tests are already being done in test_cli.py. If we have a better way to test, move here.
def test_inpect_linkages():
pass


def test_inspect_objects():
pass


def test_installable():
pass
83 changes: 34 additions & 49 deletions tests/test_os_utils_external.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,42 @@
# Copyright (C) 2014 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
import sys
import os
import os.path
from pathlib import Path

from conda.common.compat import on_win
from conda_build.os_utils.external import find_executable


def test_find_executable(testing_workdir, monkeypatch):
if sys.platform != "win32":
import stat

path_components = []

def create_file(unix_path, put_on_path, executable):
localized_path = os.path.join(testing_workdir, *unix_path.split('/'))
# empty prefix by default - extra bit at beginning of file
if sys.platform == "win32":
localized_path = localized_path + ".bat"

dirname = os.path.split(localized_path)[0]
if not os.path.isdir(dirname):
os.makedirs(dirname)

if sys.platform == "win32":
prefix = "@echo off\n"
else:
prefix = "#!/bin/bash\nexec 1>&2\n"
with open(localized_path, 'w') as f:
f.write(prefix + """
echo ******* You have reached the dummy {}. It is likely there is a bug in
echo ******* conda that makes it not add the _build/bin directory onto the
echo ******* PATH before running the source checkout tool
exit -1
""".format(localized_path))

if put_on_path:
path_components.append(dirname)

if executable:
st = os.stat(localized_path)
os.chmod(localized_path, st.st_mode | stat.S_IEXEC)

return localized_path

create_file('executable/not/on/path/with/target_name', put_on_path=False, executable=True)
create_file('non_executable/on/path/with/target_name', put_on_path=True, executable=False)
create_file('executable/on/path/with/non_target_name', put_on_path=True, executable=True)
target_path = create_file('executable/on/path/with/target_name', put_on_path=True, executable=True)
create_file('another/executable/later/on/path/with/target_name', put_on_path=True, executable=True)

monkeypatch.setenv('PATH', os.pathsep.join(path_components))

find = find_executable('target_name')

assert find == target_path, f"Expected to find 'target_name' in '{target_path}', but found it in '{find}'"
search_path = []

def touch(target, searchable=True, executable=True, alternative=False):
path = Path(
testing_workdir,
"alt" if alternative else "not",
"exec" if executable else "not",
"search" if searchable else "not",
target,
)
if on_win:
path = path.with_suffix(".bat")
path.parent.mkdir(parents=True, exist_ok=True)

path.touch(0o100 if executable else 0o666)

if searchable:
search_path.append(str(path.parent))

return str(path)

touch("target", searchable=False)
# Windows doesn't have an execute bit so this is the path found
win_expected = touch("target", executable=False)
touch("not_target")
nix_expected = touch("target")
touch("target", alternative=True)
expected = win_expected if on_win else nix_expected

monkeypatch.setenv("PATH", os.pathsep.join(search_path))

assert find_executable("target") == expected
35 changes: 20 additions & 15 deletions tests/test_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,36 @@
# SPDX-License-Identifier: BSD-3-Clause
import os

import pytest

from conda_build import api
from conda_build import render


def test_output_with_noarch_says_noarch(testing_metadata):
testing_metadata.meta['build']['noarch'] = 'python'
output = api.get_output_file_path(testing_metadata)
assert os.path.sep + "noarch" + os.path.sep in output[0]


def test_output_with_noarch_python_says_noarch(testing_metadata):
testing_metadata.meta['build']['noarch_python'] = True
@pytest.mark.parametrize(
"build",
[
pytest.param({"noarch": "python"}, id="noarch"),
pytest.param({"noarch_python": True}, id="noarch_python"),
],
)
def test_noarch_output(build, testing_metadata):
testing_metadata.meta["build"].update(build)
output = api.get_output_file_path(testing_metadata)
assert os.path.sep + "noarch" + os.path.sep in output[0]


def test_reduce_duplicate_specs(testing_metadata):
reqs = {"build": ["exact", "exact 1.2.3 1", "exact >1.0,<2"], "host": ["exact", "exact 1.2.3 1"]}
testing_metadata.meta["requirements"] = reqs
testing_metadata.meta["requirements"] = {
"build": ["exact", "exact 1.2.3 1", "exact >1.0,<2"],
"host": ["exact", "exact 1.2.3 1"],
}
render._simplify_to_exact_constraints(testing_metadata)
assert (testing_metadata.meta['requirements']['build'] ==
testing_metadata.meta['requirements']['host'])
simplified_deps = testing_metadata.meta['requirements']
assert len(simplified_deps['build']) == 1
assert 'exact 1.2.3 1' in simplified_deps['build']
simplified = testing_metadata.meta["requirements"]

assert simplified["build"] == simplified["host"]
assert len(simplified["build"]) == 1
assert "exact 1.2.3 1" in simplified["build"]


def test_pin_run_as_build_preserve_string(testing_metadata):
Expand Down
1 change: 1 addition & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def numpy_installed():
fail_dir = os.path.join(thisdir, "test-recipes", "fail")
variants_dir = os.path.join(thisdir, "test-recipes", "variants")
dll_dir = os.path.join(thisdir, "test-recipes", "dll-package")
go_dir = os.path.join(thisdir, "test-recipes", "go-package")
archive_dir = os.path.join(thisdir, "archives")


Expand Down

0 comments on commit f4a3203

Please sign in to comment.