2020-07-13 21:34:10 +00:00
|
|
|
import os
|
|
|
|
from pathlib import Path
|
|
|
|
|
2022-02-21 22:27:03 +00:00
|
|
|
import pytest
|
2020-07-13 21:34:10 +00:00
|
|
|
from pkg_resources import parse_version
|
|
|
|
|
|
|
|
import pyodide_build.mkpkg
|
2022-09-11 07:20:56 +00:00
|
|
|
from pyodide_build.io import MetaConfig
|
2020-07-13 21:34:10 +00:00
|
|
|
|
2021-11-15 09:26:55 +00:00
|
|
|
# Following tests make real network calls to the PyPI JSON API.
|
2020-07-13 21:34:10 +00:00
|
|
|
# Since the response is fully cached, and small, it is very fast and is
|
|
|
|
# unlikely to fail.
|
|
|
|
|
|
|
|
|
2022-02-12 21:44:10 +00:00
|
|
|
@pytest.mark.parametrize("source_fmt", ["wheel", "sdist"])
|
2022-04-09 20:41:10 +00:00
|
|
|
def test_mkpkg(tmpdir, capsys, source_fmt):
|
2020-07-13 21:34:10 +00:00
|
|
|
base_dir = Path(str(tmpdir))
|
2022-02-12 21:44:10 +00:00
|
|
|
|
2022-04-09 20:41:10 +00:00
|
|
|
pyodide_build.mkpkg.make_package(base_dir, "idna", None, source_fmt)
|
2020-07-13 21:34:10 +00:00
|
|
|
assert os.listdir(base_dir) == ["idna"]
|
|
|
|
meta_path = base_dir / "idna" / "meta.yaml"
|
|
|
|
assert meta_path.exists()
|
2021-09-12 21:13:49 +00:00
|
|
|
captured = capsys.readouterr()
|
2023-01-16 04:46:38 +00:00
|
|
|
assert "Output written to" in captured.out
|
|
|
|
assert str(meta_path) in captured.out
|
2020-07-13 21:34:10 +00:00
|
|
|
|
2022-09-11 07:20:56 +00:00
|
|
|
db = MetaConfig.from_yaml(meta_path)
|
2020-07-13 21:34:10 +00:00
|
|
|
|
2022-09-11 07:20:56 +00:00
|
|
|
assert db.package.name == "idna"
|
|
|
|
assert db.source.url is not None
|
2022-02-12 21:44:10 +00:00
|
|
|
if source_fmt == "wheel":
|
2022-09-11 07:20:56 +00:00
|
|
|
assert db.source.url.endswith(".whl")
|
2022-02-12 21:44:10 +00:00
|
|
|
else:
|
2022-09-11 07:20:56 +00:00
|
|
|
assert db.source.url.endswith(".tar.gz")
|
2020-07-13 21:34:10 +00:00
|
|
|
|
|
|
|
|
2022-02-12 21:44:10 +00:00
|
|
|
@pytest.mark.parametrize("old_dist_type", ["wheel", "sdist"])
|
|
|
|
@pytest.mark.parametrize("new_dist_type", ["wheel", "sdist", "same"])
|
2022-04-09 20:41:10 +00:00
|
|
|
def test_mkpkg_update(tmpdir, old_dist_type, new_dist_type):
|
2020-07-13 21:34:10 +00:00
|
|
|
base_dir = Path(str(tmpdir))
|
|
|
|
|
2022-02-12 21:44:10 +00:00
|
|
|
old_ext = ".tar.gz" if old_dist_type == "sdist" else ".whl"
|
|
|
|
old_url = "https://<some>/idna-2.0" + old_ext
|
2022-09-11 07:20:56 +00:00
|
|
|
db_init = MetaConfig(
|
|
|
|
package={"name": "idna", "version": "2.0"},
|
|
|
|
source={
|
2020-07-13 21:34:10 +00:00
|
|
|
"sha256": "b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6",
|
2022-02-12 21:44:10 +00:00
|
|
|
"url": old_url,
|
2020-07-13 21:34:10 +00:00
|
|
|
},
|
2022-09-11 07:20:56 +00:00
|
|
|
test={"imports": ["idna"]},
|
|
|
|
)
|
2020-07-13 21:34:10 +00:00
|
|
|
|
2022-04-09 20:41:10 +00:00
|
|
|
package_dir = base_dir / "idna"
|
|
|
|
package_dir.mkdir(parents=True)
|
|
|
|
meta_path = package_dir / "meta.yaml"
|
2022-09-11 07:20:56 +00:00
|
|
|
db_init.to_yaml(meta_path)
|
2022-02-12 21:44:10 +00:00
|
|
|
source_fmt = new_dist_type
|
|
|
|
if new_dist_type == "same":
|
|
|
|
source_fmt = None
|
2022-04-09 20:41:10 +00:00
|
|
|
pyodide_build.mkpkg.update_package(base_dir, "idna", None, False, source_fmt)
|
2020-07-13 21:34:10 +00:00
|
|
|
|
2022-09-11 07:20:56 +00:00
|
|
|
db = MetaConfig.from_yaml(meta_path)
|
|
|
|
assert parse_version(db.package.version) > parse_version(db_init.package.version)
|
|
|
|
assert db.source.url is not None
|
2022-02-12 21:44:10 +00:00
|
|
|
if new_dist_type == "wheel":
|
2022-09-11 07:20:56 +00:00
|
|
|
assert db.source.url.endswith(".whl")
|
2022-02-12 21:44:10 +00:00
|
|
|
elif new_dist_type == "sdist":
|
2022-09-11 07:20:56 +00:00
|
|
|
assert db.source.url.endswith(".tar.gz")
|
2022-02-12 21:44:10 +00:00
|
|
|
else:
|
2022-09-11 07:20:56 +00:00
|
|
|
assert db.source.url.endswith(old_ext)
|