1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
import glob
import os
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path
import pytest
import tomli
from hatch_jupyter_builder.compare_migrated.cli import main
HERE = Path(__file__).parent.absolute()
REPO_ROOT = str(HERE.parent).replace(os.sep, "/")
@pytest.mark.migration_test
def test_npm_builder_migration():
python = sys.executable
os.environ["BUILDER_VERSION_SPEC"] = f"@file://{REPO_ROOT}"
# Copy the source cookiecutter extension into two temporary directories.
with tempfile.TemporaryDirectory() as td1, tempfile.TemporaryDirectory() as td2:
source = HERE / "data" / "npm_builder"
shutil.copytree(source / "myextension", Path(td1) / "myextension")
shutil.copytree(source / "myextension", Path(td2) / "myextension")
target1 = Path(td1) / "myextension"
target2 = Path(td2) / "myextension"
# Migrate the first extension and compare its migrated pyproject.toml
# to the expected one.
subprocess.check_call([python, "-m", "hatch_jupyter_builder.migrate", target1])
source_toml = source.joinpath("pyproject.toml").read_text(encoding="utf-8")
target_toml = target1.joinpath("pyproject.toml").read_text(encoding="utf-8")
source_data = tomli.loads(source_toml)
target_data = tomli.loads(target_toml)
# The hatchling and hatch_jupyter_builder versions might differ.
source_data["build-system"]["requires"] = target_data["build-system"]["requires"]
source_hooks = source_data["tool"]["hatch"]["build"]["hooks"]
target_hooks = target_data["tool"]["hatch"]["build"]["hooks"]
source_hooks["jupyter-builder"] = target_hooks["jupyter-builder"]
assert source_data == target_data
# Compare the produced wheel and sdist for the migrated and unmigrated
# extensions.
for asset in ["sdist", "wheel"]:
results = main(target2, target1, asset)
if asset == "sdist":
for item in results["removed"]:
assert "static/remoteEntry." in item
for item in results["added"]:
assert ".eslintrc.js" in item or "static/remoteEntry." in item
else:
for item in results["removed"]:
assert "static/remoteEntry." in item or "top_level.txt" in item
for item in results["added"]:
assert "static/remoteEntry." in item
# Check the produced dist file in strict mode.
dist_files = glob.glob(str(target1 / "dist/*.*"))
assert len(dist_files) == 1
subprocess.check_call([python, "-m", "twine", "check", "--strict", dist_files[0]])
@pytest.mark.migration_test
def test_create_cmdclass_migration():
python = sys.executable
os.environ["BUILDER_VERSION_SPEC"] = f"@file://{REPO_ROOT}"
# Copy the source cookiecutter extension into two temporary directories.
with tempfile.TemporaryDirectory() as td1, tempfile.TemporaryDirectory() as td2:
source = HERE / "data" / "create_cmdclass"
shutil.copytree(source / "myproject", Path(td1) / "myproject")
shutil.copytree(source / "myproject", Path(td2) / "myproject")
target1 = Path(td1) / "myproject"
target2 = Path(td2) / "myproject"
# Migrate the first extension and compare its migrated pyproject.toml
# to the expected one.
subprocess.check_call([python, "-m", "hatch_jupyter_builder.migrate", target1])
source_toml = source.joinpath("pyproject.toml").read_text(encoding="utf-8")
target_toml = target1.joinpath("pyproject.toml").read_text(encoding="utf-8")
source_data = tomli.loads(source_toml)
target_data = tomli.loads(target_toml)
# The hatchling and hatch_jupyter_builder versions might differ.
source_data["build-system"]["requires"] = target_data["build-system"]["requires"]
source_hooks = source_data["tool"]["hatch"]["build"]["hooks"]
target_hooks = target_data["tool"]["hatch"]["build"]["hooks"]
source_hooks["jupyter-builder"] = target_hooks["jupyter-builder"]
assert source_data == target_data
# Compare the produced wheel and sdist for the migrated and unmigrated
# extensions.
for asset in ["sdist", "wheel"]:
results = main(target2, target1, asset)
for item in results["removed"]:
assert (
"remoteEntry." in item
or "embed-bundle.js" in item
or "dist-info/LICENSE.txt" in item
or "dist-info/top_level.txt" in item
)
if asset == "sdist":
assert len(results["added"]) == 8
else:
for item in results["added"]:
assert (
"remoteEntry." in item
or "licenses/LICENSE.txt" in item
or "dist-info/entry_points.txt" in item
)
# Check the produced dist file in strict mode.
dist_files = glob.glob(str(target1 / "dist/*.*"))
assert len(dist_files) == 1
subprocess.check_call([python, "-m", "twine", "check", "--strict", dist_files[0]])
|