Skip to content

Commit

Permalink
Fix windows tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanChristopheMorinPerso committed Jul 2, 2023
1 parent 1e9eba6 commit cc61cec
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 60 deletions.
24 changes: 22 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import time
import typing
import pathlib
import zipfile
import platform
import textwrap
Expand All @@ -12,6 +13,8 @@
import rez.packages
import rez.package_maker

from . import utils

DOWNLOAD_DIR = os.path.abspath(os.path.join("tests", "data", "_tmp_download"))


Expand All @@ -30,9 +33,26 @@ def pytest_runtest_makereport(item: pytest.Item, call):
item.stash.setdefault(phaseReportKey, {})[rep.when] = rep


@pytest.fixture(scope="session")
def indexPath(tmpdir_factory: pytest.TempdirFactory) -> pathlib.Path:
"""Build PyPI Index and return the path"""

srcPackages = os.path.join(os.path.dirname(__file__), "data", "src_packages")

indexPath = tmpdir_factory.mktemp("pypi_index").dirpath()

for pkg in os.listdir(srcPackages):
dest = indexPath.mkdir(pkg)
utils.buildPackage(pkg, os.fspath(dest))

return pathlib.Path(indexPath.strpath)


@pytest.fixture(scope="function")
def pypi(
printer_session: typing.Callable[[str], None], request: pytest.FixtureRequest
printer_session: typing.Callable[[str], None],
indexPath,
request: pytest.FixtureRequest,
) -> typing.Generator[str, None, None]:
"""Start a PyPI instance and return the URL to talk to it."""
port = 45678
Expand All @@ -42,7 +62,7 @@ def pypi(
[
"pypi-server",
"run",
os.path.join(os.path.dirname(__file__), "data", "index"),
os.fspath(indexPath),
f"--port={port}",
f"--host={host}",
"--disable-fallback",
Expand Down
4 changes: 0 additions & 4 deletions tests/data/index/README.md

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed tests/data/index/tomli/tomli-2.0.1-py3-none-any.whl
Binary file not shown.
Binary file not shown.
Binary file removed tests/data/index/zipp/zipp-3.15.0-py3-none-any.whl
Binary file not shown.
11 changes: 11 additions & 0 deletions tests/data/src_packages/package_a/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "package_a"
version = "1.0.0"

dependencies = [
"package_b"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import sys


def run():
# We want to test that the executable is really the correct one, the one we expect.
# So printing it will allow us to compare it.
sys.stdout.write(sys.executable)
7 changes: 7 additions & 0 deletions tests/data/src_packages/package_b/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "package_b"
version = "2.0.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import sys


def run():
# We want to test that the executable is really the correct one, the one we expect.
# So printing it will allow us to compare it.
sys.stdout.write(sys.executable)
21 changes: 5 additions & 16 deletions tests/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,13 @@ def test_installer_schemes():
)


# @pytest.fixture(scope="module")
def buildPackage(name: str, outputDir: str):
sourcePath = os.path.join(os.path.dirname(__file__), "data", "src_packages", name)

subprocess.run(
[sys.executable, "-m", "build", "-w", ".", "--outdir", outputDir],
cwd=sourcePath,
check=True,
)

return glob.glob(os.path.join(outputDir, "*.whl"))[0]


@pytest.mark.integration
def test_console_scripts(pythonRezPackage: str, rezRepo: str, tmp_path: pathlib.Path):
def test_console_scripts(
pythonRezPackage: str, rezRepo: str, tmp_path: pathlib.Path, indexPath: pathlib.Path
):
executable, ctx = utils.getPythonRezPackageExecutablePath(pythonRezPackage, rezRepo)

wheel = buildPackage("console_scripts", str(tmp_path / "wheels"))
assert executable is not None

installPath = tmp_path / "install"
rez_pip.install.installWheel(
Expand All @@ -61,7 +50,7 @@ def test_console_scripts(pythonRezPackage: str, rezRepo: str, tmp_path: pathlib.
True,
rez_pip.pip.Metadata("0.1.0", "console_scripts"),
),
wheel,
next(indexPath.joinpath("console_scripts").glob("*.whl")),
os.fspath(installPath),
)

Expand Down
59 changes: 21 additions & 38 deletions tests/test_pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
import uuid
import typing
import pathlib
import platform
import subprocess

import rich
import pytest
import rez.packages
import rez.vendor.version.version

import rez_pip.pip
import rez_pip.exceptions
Expand All @@ -29,59 +26,61 @@ def test_getBundledPip():
"packages,expectedPackages",
[
[
["build"],
["package_a"],
[
rez_pip.pip.PackageInfo(
rez_pip.pip.DownloadInfo(
"{pypi}/packages/build/build-0.10.0-py3-none-any.whl",
"{pypi}/packages/package_a/package_a-1.0.0-py2.py3-none-any.whl",
rez_pip.pip.ArchiveInfo(
"sha256=af266720050a66c893a6096a2f410989eeac74ff9a68ba194b3f6473e8e26171",
"sha256=4225440d89bf46e1dbb75cc58a35da0e9d144b86b4ea0c65ede3758dfc8178ef",
{
"sha256": "af266720050a66c893a6096a2f410989eeac74ff9a68ba194b3f6473e8e26171"
"sha256": "4225440d89bf46e1dbb75cc58a35da0e9d144b86b4ea0c65ede3758dfc8178ef"
},
),
),
False,
True,
rez_pip.pip.Metadata("0.10.0", "build"),
rez_pip.pip.Metadata("1.0.0", "package_a"),
),
],
],
[
["build", "packaging"],
["package_a", "console_scripts"],
[
rez_pip.pip.PackageInfo(
rez_pip.pip.DownloadInfo(
"{pypi}/packages/build/build-0.10.0-py3-none-any.whl",
"{pypi}/packages/package_a/package_a-1.0.0-py2.py3-none-any.whl",
rez_pip.pip.ArchiveInfo(
"sha256=af266720050a66c893a6096a2f410989eeac74ff9a68ba194b3f6473e8e26171",
"sha256=4225440d89bf46e1dbb75cc58a35da0e9d144b86b4ea0c65ede3758dfc8178ef",
{
"sha256": "af266720050a66c893a6096a2f410989eeac74ff9a68ba194b3f6473e8e26171"
"sha256": "4225440d89bf46e1dbb75cc58a35da0e9d144b86b4ea0c65ede3758dfc8178ef"
},
),
),
False,
True,
rez_pip.pip.Metadata("0.10.0", "build"),
rez_pip.pip.Metadata("1.0.0", "package_a"),
),
rez_pip.pip.PackageInfo(
download_info=rez_pip.pip.DownloadInfo(
url="{pypi}/packages/packaging/packaging-23.1-py3-none-any.whl",
url="{pypi}/packages/console_scripts/console_scripts-0.1.0-py2.py3-none-any.whl",
archive_info=rez_pip.pip.ArchiveInfo(
hash="sha256=994793af429502c4ea2ebf6bf664629d07c1a9fe974af92966e4b8d2df7edc61",
hash="sha256=75dbc7107e3582d65c18c674fa13f74d8c509f4ae72c8278e54baa8d549b9775",
hashes={
"sha256": "994793af429502c4ea2ebf6bf664629d07c1a9fe974af92966e4b8d2df7edc61"
"sha256": "75dbc7107e3582d65c18c674fa13f74d8c509f4ae72c8278e54baa8d549b9775"
},
),
),
is_direct=False,
requested=True,
metadata=rez_pip.pip.Metadata(version="23.1", name="packaging"),
metadata=rez_pip.pip.Metadata(
version="0.1.0", name="console_scripts"
),
),
],
],
],
ids=["build", "build+packaging"],
ids=["package_a", "package_a+console_scripts"],
)
def test_getPackages_no_deps(
packages: typing.List[str],
Expand All @@ -105,7 +104,7 @@ def test_getPackages_no_deps(
executable,
[],
[],
["--index-url", pypi, "-vvv", "--no-deps"],
["--index-url", pypi, "-vvv", "--no-deps", "--retries=0"],
)

for packageInfo in expectedPackages:
Expand All @@ -126,34 +125,18 @@ def test_getPackages_with_deps(
assert executable is not None

resolvedPackages = rez_pip.pip.getPackages(
["build"],
["package_a"],
rez_pip.pip.getBundledPip(),
"3.11",
executable,
[],
[],
["--index-url", pypi, "-vvv"],
["--index-url", pypi, "-vvv", "--retries=0"],
)

resolvedPackageNames = [pkg.name for pkg in resolvedPackages]

pythonPackage = typing.cast(
rez.packages.Variant, ctx.get_resolved_package("python")
)

expectedPackageNames = ["build", "packaging", "pyproject_hooks"]
if pythonPackage.resource.version in rez.vendor.version.version.VersionRange("3.7"):
expectedPackageNames.extend(
["importlib-metadata", "tomli", "typing_extensions", "zipp"]
)

if pythonPackage.resource.version in rez.vendor.version.version.VersionRange("3.9"):
expectedPackageNames.append("tomli")

if platform.system() == "Windows":
expectedPackageNames.append("colorama")

assert sorted(resolvedPackageNames) == sorted(expectedPackageNames)
assert sorted(resolvedPackageNames) == ["package_a", "package_b"]


def test_getPackages_error(
Expand Down
26 changes: 26 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import os
import sys
import glob
import pathlib
import platform
import subprocess

import rez.packages
import rez.resolved_context
Expand All @@ -18,3 +23,24 @@ def getPythonRezPackageExecutablePath(version: str, repo: str):
executable = "python.exe"

return ctx.which(executable), ctx


def buildPackage(name: str, outputDir: str) -> pathlib.Path:
sourcePath = os.path.join(os.path.dirname(__file__), "data", "src_packages", name)

subprocess.run(
[
sys.executable,
"-m",
"build",
"-w",
".",
"--outdir",
outputDir,
"--no-isolation",
],
cwd=sourcePath,
check=True,
)

return pathlib.Path(glob.glob(os.path.join(outputDir, f"{name}*.whl"))[0])

0 comments on commit cc61cec

Please sign in to comment.