Skip to content

Commit

Permalink
test: Use testing_api fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
mbargull committed Nov 26, 2022
1 parent 186eb2c commit 330a777
Show file tree
Hide file tree
Showing 15 changed files with 612 additions and 651 deletions.
573 changes: 281 additions & 292 deletions tests/test_api_build.py

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions tests/test_api_build_conda_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@

import pytest

from conda_build import api

from .utils import metadata_dir


@pytest.mark.parametrize("pkg_format,pkg_ext", [(None, ".tar.bz2"), ("2", ".conda")])
def test_conda_pkg_format(
pkg_format, pkg_ext, testing_config, testing_workdir, monkeypatch, capfd
testing_api, pkg_format, pkg_ext, testing_config, monkeypatch, capfd
):
"""Conda package format "2" builds .conda packages."""

Expand All @@ -25,10 +23,10 @@ def test_conda_pkg_format(
monkeypatch.setenv("CONDA_TEST_VAR", "conda_test")
monkeypatch.setenv("CONDA_TEST_VAR_2", "conda_test_2")

output_file, = api.get_output_file_paths(recipe, config=testing_config)
output_file, = testing_api.get_output_file_paths(recipe, config=testing_config)
assert output_file.endswith(pkg_ext)

api.build(recipe, config=testing_config)
testing_api.build(recipe, config=testing_config)
assert os.path.exists(output_file)

out, err = capfd.readouterr()
Expand Down
6 changes: 2 additions & 4 deletions tests/test_api_build_dll_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import os
import pytest

from conda_build import api

from .utils import thisdir


Expand All @@ -14,10 +12,10 @@ def recipe():


@pytest.mark.sanity
def test_recipe_build(recipe, testing_config, testing_workdir, monkeypatch):
def test_recipe_build(testing_api, recipe, testing_config, 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)
testing_api.build(recipe, config=testing_config)
6 changes: 2 additions & 4 deletions tests/test_api_build_go_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import os
import pytest

from conda_build import api

from .utils import thisdir


Expand All @@ -15,10 +13,10 @@ def recipe():

@pytest.mark.sanity
@pytest.mark.serial
def test_recipe_build(recipe, testing_config, testing_workdir, monkeypatch):
def test_recipe_build(testing_api, recipe, 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)
testing_api.build(recipe, config=testing_config)
55 changes: 27 additions & 28 deletions tests/test_api_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@
import pytest

from conda_build.conda_interface import download
from conda_build import api
from conda_build.utils import package_has_file, on_win

from .utils import metadata_dir, assert_package_consistency


def test_convert_wheel_raises():
def test_convert_wheel_raises(testing_api):
with pytest.raises(RuntimeError) as exc:
api.convert("some_wheel.whl")
testing_api.convert("some_wheel.whl")
assert "Conversion from wheel packages" in str(exc)


def test_convert_exe_raises():
def test_convert_exe_raises(testing_api):
with pytest.raises(RuntimeError) as exc:
api.convert("some_wheel.exe")
testing_api.convert("some_wheel.exe")
assert "cannot convert:" in str(exc)


Expand All @@ -43,7 +42,7 @@ def assert_package_paths_matches_files(package_path):

@pytest.mark.parametrize('base_platform', ['linux', 'win', 'osx'])
@pytest.mark.parametrize('package', [('cryptography-1.8.1', '__about__.py')])
def test_show_imports(testing_workdir, base_platform, package, capfd):
def test_show_imports(testing_api, testing_workdir, base_platform, package, capfd):
package_name, example_file = package
platforms = ['osx-64', 'win-64', 'win-32', 'linux-64', 'linux-32']

Expand All @@ -60,7 +59,7 @@ def test_show_imports(testing_workdir, base_platform, package, capfd):

for platform in platforms:
with pytest.raises(SystemExit):
api.convert(fn, platforms=platform, show_imports=True)
testing_api.convert(fn, platforms=platform, show_imports=True)

output, error = capfd.readouterr()

Expand All @@ -72,7 +71,7 @@ def test_show_imports(testing_workdir, base_platform, package, capfd):

@pytest.mark.parametrize('base_platform', ['linux', 'win', 'osx'])
@pytest.mark.parametrize('package', [('itsdangerous-0.24', 'itsdangerous.py')])
def test_no_imports_found(testing_workdir, base_platform, package, capfd):
def test_no_imports_found(testing_api, testing_workdir, base_platform, package, capfd):
package_name, example_file = package

f = 'http://repo.anaconda.com/pkgs/free/{}-64/{}-py36_0.tar.bz2'.format(base_platform,
Expand All @@ -81,15 +80,15 @@ def test_no_imports_found(testing_workdir, base_platform, package, capfd):
download(f, fn)

with pytest.raises(SystemExit):
api.convert(fn, platforms=None, show_imports=True)
testing_api.convert(fn, platforms=None, show_imports=True)

output, error = capfd.readouterr()
assert 'No imports found.' in output


@pytest.mark.parametrize('base_platform', ['linux', 'win', 'osx'])
@pytest.mark.parametrize('package', [('cryptography-1.8.1', '__about__.py')])
def test_no_platform(testing_workdir, base_platform, package):
def test_no_platform(testing_api, testing_workdir, base_platform, package):
package_name, example_file = package

f = 'http://repo.anaconda.com/pkgs/free/{}-64/{}-py36_0.tar.bz2'.format(base_platform,
Expand All @@ -98,14 +97,14 @@ def test_no_platform(testing_workdir, base_platform, package):
download(f, fn)

with pytest.raises(SystemExit) as e:
api.convert(fn, platforms=None)
testing_api.convert(fn, platforms=None)

assert 'Error: --platform option required for conda package conversion.' in str(e.value)


@pytest.mark.parametrize('base_platform', ['linux', 'win', 'osx'])
@pytest.mark.parametrize('package', [('cryptography-1.8.1', '__about__.py')])
def test_c_extension_error(testing_workdir, base_platform, package):
def test_c_extension_error(testing_api, testing_workdir, base_platform, package):
package_name, example_file = package
platforms = ['osx-64', 'win-64', 'win-32', 'linux-64', 'linux-32']

Expand All @@ -122,15 +121,15 @@ def test_c_extension_error(testing_workdir, base_platform, package):

for platform in platforms:
with pytest.raises(SystemExit) as e:
api.convert(fn, platforms=platform)
testing_api.convert(fn, platforms=platform)

assert ('WARNING: Package {} contains C extensions; skipping conversion. '
'Use -f to force conversion.' .format(fn)) in str(e.value)


@pytest.mark.parametrize('base_platform', ['linux', 'win', 'osx'])
@pytest.mark.parametrize('package', [('cryptography-1.8.1', '__about__.py')])
def test_c_extension_conversion(testing_workdir, base_platform, package):
def test_c_extension_conversion(testing_api, testing_workdir, base_platform, package):
package_name, example_file = package
platforms = ['osx-64', 'win-64', 'win-32', 'linux-64', 'linux-32']

Expand All @@ -146,23 +145,23 @@ def test_c_extension_conversion(testing_workdir, base_platform, package):
download(f, fn)

for platform in platforms:
api.convert(fn, platforms=platform, force=True)
testing_api.convert(fn, platforms=platform, force=True)

assert os.path.exists('{}/{}' .format(platform, fn))


@pytest.mark.parametrize('base_platform', ['linux', 'win', 'osx'])
@pytest.mark.parametrize('package', [('itsdangerous-0.24', 'itsdangerous.py'),
('py-1.4.32', 'py/__init__.py')])
def test_convert_platform_to_others(testing_workdir, base_platform, package):
def test_convert_platform_to_others(testing_api, testing_workdir, base_platform, package):
package_name, example_file = package
subdir = f'{base_platform}-64'
f = 'http://repo.anaconda.com/pkgs/free/{}/{}-py27_0.tar.bz2'.format(subdir,
package_name)
fn = f"{package_name}-py27_0.tar.bz2"
download(f, fn)
expected_paths_json = package_has_file(fn, 'info/paths.json')
api.convert(fn, platforms='all', quiet=False, verbose=False)
testing_api.convert(fn, platforms='all', quiet=False, verbose=False)
for platform in ['osx-64', 'win-64', 'win-32', 'linux-64', 'linux-32']:
if subdir != platform:
python_folder = 'lib/python2.7' if not platform.startswith('win') else 'Lib'
Expand All @@ -177,11 +176,11 @@ def test_convert_platform_to_others(testing_workdir, base_platform, package):

@pytest.mark.slow
@pytest.mark.skipif(on_win, reason="we create the pkg to be converted in *nix; don't run on win.")
def test_convert_from_unix_to_win_creates_entry_points(testing_config):
def test_convert_from_unix_to_win_creates_entry_points(testing_api, testing_config):
recipe_dir = os.path.join(metadata_dir, "entry_points")
fn = api.build(recipe_dir, config=testing_config)[0]
fn = testing_api.build(recipe_dir, config=testing_config)[0]
for platform in ['win-64', 'win-32']:
api.convert(fn, platforms=[platform], force=True)
testing_api.convert(fn, platforms=[platform], force=True)
converted_fn = os.path.join(platform, os.path.basename(fn))
assert package_has_file(converted_fn, "Scripts/test-script-manual-script.py")
assert package_has_file(converted_fn, "Scripts/test-script-manual.exe")
Expand Down Expand Up @@ -226,7 +225,7 @@ def test_convert_from_unix_to_win_creates_entry_points(testing_config):

@pytest.mark.parametrize('base_platform', ['linux', 'win', 'osx'])
@pytest.mark.parametrize('package', [('anaconda-4.4.0', 'version.txt')])
def test_convert_dependencies(testing_workdir, base_platform, package):
def test_convert_dependencies(testing_api, testing_workdir, base_platform, package):
package_name, example_file = package
subdir = f'{base_platform}-64'
f = 'http://repo.anaconda.com/pkgs/free/{}/{}-np112py36_0.tar.bz2'.format(subdir,
Expand All @@ -236,7 +235,7 @@ def test_convert_dependencies(testing_workdir, base_platform, package):

dependencies = ['numpy 1.7.1 py36_0', 'cryptography 1.7.0 py36_0']
expected_paths_json = package_has_file(fn, 'info/paths.json')
api.convert(fn, platforms='all', dependencies=dependencies, quiet=False, verbose=False)
testing_api.convert(fn, platforms='all', dependencies=dependencies, quiet=False, verbose=False)
for platform in ['osx-64', 'win-64', 'win-32', 'linux-64', 'linux-32']:
if platform != subdir:
python_folder = 'lib/python3.6' if not platform.startswith('win') else 'Lib'
Expand All @@ -259,7 +258,7 @@ def test_convert_dependencies(testing_workdir, base_platform, package):

@pytest.mark.parametrize('base_platform', ['linux', 'win', 'osx'])
@pytest.mark.parametrize('package', [('anaconda-4.4.0', 'version.txt')])
def test_convert_no_dependencies(testing_workdir, base_platform, package):
def test_convert_no_dependencies(testing_api, testing_workdir, base_platform, package):
package_name, example_file = package
subdir = f'{base_platform}-64'
f = 'http://repo.anaconda.com/pkgs/free/{}/{}-np112py36_0.tar.bz2'.format(subdir,
Expand All @@ -268,7 +267,7 @@ def test_convert_no_dependencies(testing_workdir, base_platform, package):
download(f, fn)

expected_paths_json = package_has_file(fn, 'info/paths.json')
api.convert(fn, platforms='all', dependencies=None, quiet=False, verbose=False)
testing_api.convert(fn, platforms='all', dependencies=None, quiet=False, verbose=False)
for platform in ['osx-64', 'win-64', 'win-32', 'linux-64', 'linux-32']:
if platform != subdir:
python_folder = 'lib/python3.6' if not platform.startswith('win') else 'Lib'
Expand All @@ -289,7 +288,7 @@ def test_convert_no_dependencies(testing_workdir, base_platform, package):

@pytest.mark.parametrize('base_platform', ['linux', 'win', 'osx'])
@pytest.mark.parametrize('package', [('anaconda-4.4.0', 'version.txt')])
def test_skip_conversion(testing_workdir, base_platform, package, capfd):
def test_skip_conversion(testing_api, testing_workdir, base_platform, package, capfd):
package_name, example_file = package
source_plat_arch = '{}-64' .format(base_platform)

Expand All @@ -298,7 +297,7 @@ def test_skip_conversion(testing_workdir, base_platform, package, capfd):
fn = f"{package_name}-np112py36_0.tar.bz2"
download(f, fn)

api.convert(fn, platforms=source_plat_arch, dependencies=None, quiet=False, verbose=False)
testing_api.convert(fn, platforms=source_plat_arch, dependencies=None, quiet=False, verbose=False)

output, error = capfd.readouterr()

Expand All @@ -314,7 +313,7 @@ def test_skip_conversion(testing_workdir, base_platform, package, capfd):

@pytest.mark.parametrize('base_platform', ['linux', 'osx'])
@pytest.mark.parametrize('package', [('sparkmagic-0.12.1', '')])
def test_renaming_executables(testing_workdir, base_platform, package):
def test_renaming_executables(testing_api, testing_workdir, base_platform, package):
"""Test that the files in /bin are properly renamed.
When converting the bin/ directory to Scripts/, only scripts
Expand All @@ -331,7 +330,7 @@ def test_renaming_executables(testing_workdir, base_platform, package):
fn = f"{package_name}-py27_0.tar.bz2"
download(f, fn)
expected_paths_json = package_has_file(fn, 'info/paths.json')
api.convert(fn, platforms='all', quiet=False, verbose=False)
testing_api.convert(fn, platforms='all', quiet=False, verbose=False)
for platform in ['osx-64', 'win-64', 'win-32', 'linux-64', 'linux-32']:
if subdir != platform:
package = os.path.join(platform, fn)
Expand Down
29 changes: 14 additions & 15 deletions tests/test_api_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import sys

from conda_build import api
from tests import utils

from .utils import metadata_dir, thisdir, on_win
Expand Down Expand Up @@ -53,8 +52,8 @@ def check_test_files_present(work_dir, test=True):


@pytest.mark.slow
def test_debug_recipe_default_path(testing_config):
activation_string = api.debug(recipe_path, config=testing_config)
def test_debug_recipe_default_path(testing_api):
activation_string = testing_api.debug(recipe_path)
assert activation_string and "debug_1" in activation_string
_, work_dir, _, src_command, env_activation_script = activation_string.split()
_shell_cmd = shell_cmd + [' '.join((src_command, env_activation_script))]
Expand All @@ -68,8 +67,8 @@ def test_debug_recipe_default_path(testing_config):
utils.on_win and sys.version_info <= (3, 4),
reason="Skipping on windows and vc<14"
)
def test_debug_package_default_path(testing_config):
activation_string = api.debug(tarball_path, config=testing_config)
def test_debug_package_default_path(testing_api):
activation_string = testing_api.debug(tarball_path)
_, work_dir, _, src_command, env_activation_script = activation_string.split()
_shell_cmd = shell_cmd + [' '.join((src_command, env_activation_script))]
subprocess.check_call(_shell_cmd, cwd=work_dir)
Expand All @@ -79,8 +78,8 @@ def test_debug_package_default_path(testing_config):


@pytest.mark.slow
def test_debug_recipe_custom_path(testing_workdir):
activation_string = api.debug(recipe_path, path=testing_workdir)
def test_debug_recipe_custom_path(testing_api, testing_workdir):
activation_string = testing_api.debug(recipe_path, path=testing_workdir)
assert activation_string and "debug_1" not in activation_string
_, work_dir, _, src_command, env_activation_script = activation_string.split()
_shell_cmd = shell_cmd + [' '.join((src_command, env_activation_script))]
Expand All @@ -90,8 +89,8 @@ def test_debug_recipe_custom_path(testing_workdir):
assert_correct_folders(work_dir)


def test_debug_package_custom_path(testing_workdir):
activation_string = api.debug(tarball_path, path=testing_workdir)
def test_debug_package_custom_path(testing_api, testing_workdir):
activation_string = testing_api.debug(tarball_path, path=testing_workdir)
_, work_dir, _, src_command, env_activation_script = activation_string.split()
_shell_cmd = shell_cmd + [' '.join((src_command, env_activation_script))]
subprocess.check_call(_shell_cmd, cwd=work_dir)
Expand All @@ -100,8 +99,8 @@ def test_debug_package_custom_path(testing_workdir):
assert_correct_folders(work_dir, build=False)


def test_specific_output():
activation_string = api.debug(ambiguous_recipe_path, output_id="output1*")
def test_specific_output(testing_api):
activation_string = testing_api.debug(ambiguous_recipe_path, output_id="output1*")
_, work_dir, _, src_command, env_activation_script = activation_string.split()
_shell_cmd = shell_cmd + [' '.join((src_command, env_activation_script))]
subprocess.check_call(_shell_cmd, cwd=work_dir)
Expand All @@ -111,12 +110,12 @@ def test_specific_output():


@pytest.mark.sanity
def test_error_on_ambiguous_output():
def test_error_on_ambiguous_output(testing_api):
with pytest.raises(ValueError):
api.debug(ambiguous_recipe_path)
testing_api.debug(ambiguous_recipe_path)


@pytest.mark.sanity
def test_error_on_unmatched_output():
def test_error_on_unmatched_output(testing_api):
with pytest.raises(ValueError):
api.debug(ambiguous_recipe_path, output_id="frank")
testing_api.debug(ambiguous_recipe_path, output_id="frank")
Loading

0 comments on commit 330a777

Please sign in to comment.