Skip to content

Commit

Permalink
TST split up tests (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
beckermr authored Jun 5, 2024
1 parent a9d9700 commit fcaee2f
Show file tree
Hide file tree
Showing 5 changed files with 249 additions and 223 deletions.
6 changes: 3 additions & 3 deletions conda_forge_feedstock_check_solvable/check_solvable.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import psutil
from ruamel.yaml import YAML

from conda_forge_feedstock_check_solvable.mamba_solver import _mamba_factory
from conda_forge_feedstock_check_solvable.mamba_solver import mamba_solver_factory
from conda_forge_feedstock_check_solvable.utils import (
MAX_GLIBC_MINOR,
apply_pins,
Expand Down Expand Up @@ -282,8 +282,8 @@ def _is_recipe_solvable_on_platform(
# we check run and host and ignore the rest
print_debug("getting mamba solver")
with suppress_output():
solver = _mamba_factory(tuple(channel_sources), f"{platform}-{arch}")
build_solver = _mamba_factory(
solver = mamba_solver_factory(tuple(channel_sources), f"{platform}-{arch}")
build_solver = mamba_solver_factory(
tuple(channel_sources),
f"{build_platform}-{build_arch}",
)
Expand Down
2 changes: 1 addition & 1 deletion conda_forge_feedstock_check_solvable/mamba_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,5 @@ def _get_run_exports(


@cachetools.func.ttl_cache(maxsize=8, ttl=60)
def _mamba_factory(channels, platform):
def mamba_solver_factory(channels, platform):
return MambaSolver(list(channels), platform)
28 changes: 28 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@

import pytest

from conda_forge_feedstock_check_solvable.mamba_solver import mamba_solver_factory

FEEDSTOCK_DIR = os.path.join(os.path.dirname(__file__), "test_feedstock")
ALL_SOLVERS = ["mamba"]


def pytest_addoption(parser):
parser.addoption(
"--solver",
action="append",
default=[],
help="conda solver to use",
)


@pytest.fixture()
Expand All @@ -15,3 +27,19 @@ def feedstock_dir(tmp_path):
for fn in os.listdir(src_ci_support):
shutil.copy(src_ci_support / fn, ci_support / fn)
return str(tmp_path)


def pytest_generate_tests(metafunc):
if "solver" in metafunc.fixturenames:
metafunc.parametrize(
"solver", metafunc.config.getoption("solver") or ALL_SOLVERS
)
if "solver_factory" in metafunc.fixturenames:
solvers = metafunc.config.getoption("solver") or ALL_SOLVERS
factories = []
for solver in solvers:
if solver == "mamba":
factories.append(mamba_solver_factory)
else:
raise ValueError(f"Unknown solver {solver}")
metafunc.parametrize("solver_factory", factories)
219 changes: 0 additions & 219 deletions tests/test_mamba_solvable.py → tests/test_check_solvable.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,158 +8,12 @@
from flaky import flaky

from conda_forge_feedstock_check_solvable.check_solvable import is_recipe_solvable
from conda_forge_feedstock_check_solvable.mamba_solver import (
MambaSolver,
_mamba_factory,
)
from conda_forge_feedstock_check_solvable.utils import apply_pins, suppress_output
from conda_forge_feedstock_check_solvable.virtual_packages import (
FakePackage,
FakeRepoData,
virtual_package_repodata,
)


@flaky
def test_mamba_solver_apply_pins(tmp_path):
with open(tmp_path / "meta.yaml", "w") as fp:
fp.write(
"""\
{% set name = "cf-autotick-bot-test-package" %}
{% set version = "0.9" %}

package:
name: {{ name|lower }}
version: {{ version }}

source:
path: .

build:
number: 8

requirements:
host:
- python
- pip
- jpeg
run:
- python

test:
commands:
- echo "works!"

about:
home: https://github.com/regro/cf-scripts
license: BSD-3-Clause
license_family: BSD
license_file: LICENSE
summary: testing feedstock for the regro-cf-autotick-bot

extra:
recipe-maintainers:
- beckermr
- conda-forge/bot
""",
)

with open(tmp_path / "conda_build_config.yaml", "w") as fp:
fp.write(
"""\
pin_run_as_build:
python:
min_pin: x.x
max_pin: x.x
python:
- 3.8.* *_cpython
""",
)
import conda_build.api

with suppress_output():
config = conda_build.config.get_or_merge_config(
None,
platform="linux",
arch="64",
variant_config_files=[],
)
cbc, _ = conda_build.variants.get_package_combined_spec(
str(tmp_path),
config=config,
)

solver = _mamba_factory(("conda-forge", "defaults"), "linux-64")

metas = conda_build.api.render(
str(tmp_path),
platform="linux",
arch="64",
ignore_system_variants=True,
variants=cbc,
permit_undefined_jinja=True,
finalize=False,
bypass_env_check=True,
channel_urls=("conda-forge", "defaults"),
)

m = metas[0][0]
outnames = [m.name() for m, _, _ in metas]
build_req = m.get_value("requirements/build", [])
host_req = m.get_value("requirements/host", [])
run_req = m.get_value("requirements/run", [])
_, _, build_req, rx = solver.solve(build_req, get_run_exports=True)
print("build req: %s" % pprint.pformat(build_req))
print("build rex: %s" % pprint.pformat(rx))
host_req = list(set(host_req) | rx["strong"])
run_req = list(set(run_req) | rx["strong"])
_, _, host_req, rx = solver.solve(host_req, get_run_exports=True)
print("host req: %s" % pprint.pformat(host_req))
print("host rex: %s" % pprint.pformat(rx))
run_req = list(set(run_req) | rx["weak"])
run_req = apply_pins(run_req, host_req, build_req, outnames, m)
print("run req: %s" % pprint.pformat(run_req))
assert any(r.startswith("python >=3.8") for r in run_req)
assert any(r.startswith("jpeg >=") for r in run_req)


@flaky
def test_mamba_solver_constraints():
with suppress_output():
solver = _mamba_factory(("conda-forge",), "osx-64")
solvable, err, solution = solver.solve(
["simplejson"], constraints=["python=3.10", "zeromq=4.2"]
)
assert solvable, err
python = [pkg for pkg in solution if pkg.split()[0] == "python"][0]
name, version, build = python.split(None, 2)
assert version.startswith("3.10.")
assert not any(pkg.startswith("zeromq") for pkg in solution), pprint.pformat(
solution
)


@flaky
def test_mamba_solver_constraints_unsolvable():
with suppress_output():
solver = MambaSolver(("conda-forge",), "osx-64")
solvable, err, solution = solver.solve(
["simplejson"], constraints=["python=3.10", "python=3.11"]
)
assert not solvable, pprint.pformat(solution)


@flaky
def test_mamba_solver_nvcc():
with suppress_output():
virtual_packages = virtual_package_repodata()
solver = MambaSolver([virtual_packages, "conda-forge", "defaults"], "linux-64")
out = solver.solve(
["gcc_linux-64 7.*", "gxx_linux-64 7.*", "nvcc_linux-64 11.0.*"]
)
assert out[0], out[1]


@flaky
def test_is_recipe_solvable_ok(feedstock_dir):
recipe_file = os.path.join(feedstock_dir, "recipe", "meta.yaml")
Expand Down Expand Up @@ -507,72 +361,6 @@ def test_is_recipe_solvable_notok(feedstock_dir):
assert not is_recipe_solvable(feedstock_dir)[0]


@flaky
def test_mamba_solver_hangs():
with suppress_output():
solver = _mamba_factory(("conda-forge", "defaults"), "osx-64")
res = solver.solve(
[
"pytest",
"selenium",
"requests-mock",
"ncurses >=6.2,<7.0a0",
"libffi >=3.2.1,<4.0a0",
"xz >=5.2.5,<6.0a0",
"nbconvert >=5.6",
"sqlalchemy",
"jsonschema",
"six >=1.11",
"python_abi 3.9.* *_cp39",
"tornado",
"jupyter",
"requests",
"jupyter_client",
"notebook >=4.2",
"tk >=8.6.10,<8.7.0a0",
"openssl >=1.1.1h,<1.1.2a",
"readline >=8.0,<9.0a0",
"fuzzywuzzy",
"python >=3.9,<3.10.0a0",
"traitlets",
"sqlite >=3.33.0,<4.0a0",
"alembic",
"zlib >=1.2.11,<1.3.0a0",
"python-dateutil",
"nbformat",
"jupyter_core",
],
)
assert res[0]

with suppress_output():
solver = _mamba_factory(("conda-forge", "defaults"), "linux-64")
res = solver.solve(
[
"gdal >=2.1.0",
"ncurses >=6.2,<7.0a0",
"geopandas",
"scikit-image >=0.16.0",
"pandas",
"pyproj >=2.2.0",
"libffi >=3.2.1,<4.0a0",
"six",
"tk >=8.6.10,<8.7.0a0",
"spectral",
"zlib >=1.2.11,<1.3.0a0",
"shapely",
"readline >=8.0,<9.0a0",
"python >=3.8,<3.9.0a0",
"numpy",
"python_abi 3.8.* *_cp38",
"xz >=5.2.5,<6.0a0",
"openssl >=1.1.1h,<1.1.2a",
"sqlite >=3.33.0,<4.0a0",
],
)
assert res[0]


@flaky
def test_arrow_solvable_timeout(tmp_path):
feedstock_dir = clone_and_checkout_repo(
Expand All @@ -592,7 +380,6 @@ def test_arrow_solvable_timeout(tmp_path):
assert solvable_by_variant == {}


@flaky
@pytest.mark.xfail
def test_pillow_solvable(tmp_path):
"""pillow acted up for python310"""
Expand Down Expand Up @@ -661,9 +448,3 @@ def test_pillow_solvable(tmp_path):
pprint.pprint(solvable_by_variant)
assert solvable, pprint.pformat(errors)
assert any("python3.10" in k for k in solvable_by_variant)


if __name__ == "__main__":
pth = os.path.join(os.path.dirname(__file__), "xgboost-feedstock")
assert is_recipe_solvable(pth, timeout=None, verbosity=2)[0]
assert is_recipe_solvable(pth, verbosity=2)[0]
Loading

0 comments on commit fcaee2f

Please sign in to comment.