Skip to content

Commit

Permalink
test: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Wackyator committed Oct 2, 2023
1 parent 1701fac commit 91a322f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 88 deletions.
21 changes: 21 additions & 0 deletions py-rattler/pixi.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions py-rattler/pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ license = "BSD-3-Clause"

[tasks]
build = "PIP_REQUIRE_VIRTUALENV=false maturin develop"
build-release = "PIP_REQUIRE_VIRTUALENV=false maturin develop --release"
test = { cmd = "pytest --doctest-modules", depends_on = ["build"] }
fmt-python = "black ."
fmt-rust = "cargo fmt --all"
Expand All @@ -34,3 +35,6 @@ black = "~=23.7.0"
ruff = "~=0.0.285"
mypy = "~=1.5.1"
pytest-asyncio = "0.21.1.*"

[target.linux-64.dependencies]
patchelf = "~=0.17.2"
101 changes: 13 additions & 88 deletions py-rattler/tests/unit/test_solver.py
Original file line number Diff line number Diff line change
@@ -1,108 +1,33 @@
# type: ignore
import os.path
import subprocess

import pytest
from rattler import (
solve,
Channel,
ChannelConfig,
fetch_repo_data,
Platform,
solve,
MatchSpec,
RepoDataRecord,
SparseRepoData,
)


@pytest.fixture(scope="session")
def noarch_repo_data() -> None:
port, repo_name = 8812, "test-repo-1"

test_data_dir = os.path.join(
os.path.dirname(__file__), "../../../test-data/test-server"
)

with subprocess.Popen(
[
"python",
os.path.join(test_data_dir, "reposerver.py"),
"-d",
os.path.join(test_data_dir, "repo"),
"-n",
repo_name,
"-p",
str(port),
]
) as proc:
yield port, repo_name
proc.terminate()


@pytest.fixture(scope="session")
def linux64_repo_data() -> None:
port, repo_name = 8813, "test-repo-2"

test_data_dir = os.path.join(os.path.dirname(__file__), "../../../test-data/")

with subprocess.Popen(
[
"python",
os.path.join(test_data_dir, "test-server/reposerver.py"),
"-d",
os.path.join(test_data_dir, "channels/dummy/"),
"-n",
repo_name,
"-p",
str(port),
]
) as proc:
yield port, repo_name
proc.terminate()


@pytest.mark.asyncio
async def test_solve(
tmp_path,
noarch_repo_data,
linux64_repo_data,
):
noarch_port, noarch_repo = noarch_repo_data
linux64_port, linux64_repo = linux64_repo_data
cache_dir = tmp_path / "test_repo_data_download"
noarch_chan = Channel(
noarch_repo, ChannelConfig(f"http://localhost:{noarch_port}/")
)
plat_noarch = Platform("noarch")
linux64_chan = Channel(
linux64_repo, ChannelConfig(f"http://localhost:{linux64_port}/")
)
plat_linux64 = Platform("linux-64")

noarch_data = await fetch_repo_data(
channels=[noarch_chan],
platforms=[plat_noarch],
cache_path=cache_dir,
callback=None,
)

linux64_data = await fetch_repo_data(
channels=[linux64_chan],
platforms=[plat_linux64],
cache_path=cache_dir,
callback=None,
async def test_solve():
linux64_chan = Channel("conda-forge", ChannelConfig(f"http://localhost:{8813}/"))
data_dir = os.path.join(os.path.dirname(__file__), "../../../test-data/")
linux64_path = os.path.join(data_dir, "channels/conda-forge/linux-64/repodata.json")
linux64_data = SparseRepoData(
channel=linux64_chan,
subdir="linux-64",
path=linux64_path,
)

available_packages = [(data, noarch_chan) for data in noarch_data] + [
(data, linux64_chan) for data in linux64_data
]
solved_data = solve(
[MatchSpec("test-package"), MatchSpec("foobar"), MatchSpec("baz")],
available_packages,
[],
[],
[],
[MatchSpec("python"), MatchSpec("sqlite")],
[linux64_data],
)

assert isinstance(solved_data, list)
assert isinstance(solved_data[0], RepoDataRecord)
assert len(solved_data) == 4
assert len(solved_data) == 19

0 comments on commit 91a322f

Please sign in to comment.