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
|
import os
import urllib.request
from importlib.metadata import PackageNotFoundError
from unittest.mock import patch
import pytest
from npe2 import PluginManifest, fetch_manifest
from npe2._inspection._fetch import (
_manifest_from_pypi_sdist,
get_hub_plugin,
get_manifest_from_wheel,
get_pypi_url,
)
def test_fetch_npe2_manifest():
mf = fetch_manifest("napari-omero")
assert mf.name == "napari-omero"
assert any(mf.contributions.dict().values())
assert mf.npe1_shim is False
@pytest.mark.skip("package looks deleted from pypi")
def test_fetch_npe1_manifest_with_writer():
mf = fetch_manifest("dummy-test-plugin", version="0.1.3")
assert mf.name == "example-plugin"
assert mf.contributions.writers
# Test will eventually fail when example-plugin is updated to npe2
# This is here as a sentinel
assert mf.npe1_shim is True
def test_fetch_npe1_manifest_with_sample_data():
mf = fetch_manifest("napari-kics")
assert mf.name == "napari-kics"
assert mf.contributions.sample_data
# Test will eventually fail when napari-kics is updated to npe2
# This is here as a sentinel
assert mf.npe1_shim is True
def test_fetch_npe1_manifest_dock_widget_as_attribute():
# This tests is just to add coverage of a specific branch of code in the
# napari_experimental_provide_dock_widget parser, (where the return value
# is a dotted attribute, rather than a direct name). I only saw it in
# brainreg-segment.
mf = fetch_manifest("brainreg-segment", version="0.2.18")
assert mf.name == "brainreg-segment"
assert mf.contributions.widgets
# This is here as a sentinel
assert mf.npe1_shim is True
@pytest.mark.parametrize("version", [None, "0.1.0"])
@pytest.mark.parametrize("packagetype", ["sdist", "bdist_wheel", None])
def test_get_pypi_url(version, packagetype):
assert "npe2" in get_pypi_url("npe2", version=version, packagetype=packagetype)
def test_from_pypi_wheel_bdist_missing():
error = PackageNotFoundError("No bdist_wheel releases found")
with patch("npe2._inspection._fetch.get_pypi_url", side_effect=error):
with pytest.raises(PackageNotFoundError):
fetch_manifest("my-package")
@pytest.mark.skipif(not os.getenv("CI"), reason="slow, only run on CI")
def test_manifest_from_sdist():
mf = _manifest_from_pypi_sdist("zarpaint")
assert mf.name == "zarpaint"
def test_get_manifest_from_wheel(tmp_path):
url = "https://files.pythonhosted.org/packages/f0/cc/7f6fbce81be3eb73266f398e49df92859ba247134eb086704dd70b43819a/affinder-0.2.3-py3-none-any.whl"
dest = tmp_path / "affinder-0.2.3-py3-none-any.whl"
urllib.request.urlretrieve(url, dest)
mf = get_manifest_from_wheel(dest)
assert mf.name == "affinder"
def test_get_hub_plugin():
info = get_hub_plugin("napari-svg")
assert info["name"] == "napari-svg"
@pytest.mark.skipif(not os.getenv("CI"), reason="slow, only run on CI")
@pytest.mark.parametrize(
"url",
[
"https://files.pythonhosted.org/packages/fb/01/e59bc1d6ac96f84ce9d7a46cc5422250e047958ead6c5693ed386cf94003/napari_dv-0.3.0.tar.gz",
"https://files.pythonhosted.org/packages/5d/ae/17779e12ce60d8329306963e1a8dec608465caee582440011ff0c1310715/example_plugin-0.0.7-py3-none-any.whl",
"git+https://github.com/napari/dummy-test-plugin.git@npe1",
# this one doesn't use setuptools_scm, can check direct zip without clone
"https://github.com/jo-mueller/napari-stl-exporter/archive/refs/heads/main.zip",
],
)
def test_fetch_urls(url):
assert isinstance(fetch_manifest(url), PluginManifest)
|