def test_fetch_wheel_fail(monkeypatch): pytest.importorskip("packaging") from micropip import _micropip def _mock_fetch_bytes(*args, **kwargs): raise Exception("Failed to fetch") monkeypatch.setattr(_micropip, "fetch_bytes", _mock_fetch_bytes) msg = "Access-Control-Allow-Origin" with pytest.raises(ValueError, match=msg): asyncio.get_event_loop().run_until_complete( _micropip.install("htps://x.com/xxx-1.0.0-py3-none-any.whl"))
def test_list_wheel_package(monkeypatch): pytest.importorskip("packaging") from micropip import _micropip dummy_pkg_name = "dummy" dummy_url = f"https://dummy.com/{dummy_pkg_name}-1.0.0-py3-none-any.whl" _mock_fetch_bytes = mock_fetch_bytes(dummy_pkg_name, "UNKNOWN") monkeypatch.setattr(_micropip, "fetch_bytes", _mock_fetch_bytes) asyncio.get_event_loop().run_until_complete(_micropip.install(dummy_url)) pkg_list = _micropip._list() assert "dummy" in pkg_list and pkg_list["dummy"].source.lower( ) == dummy_url
def test_list_pypi_package(monkeypatch): pytest.importorskip("packaging") from micropip import _micropip dummy_pkg_name = "dummy" _mock_get_pypi_json = mock_get_pypi_json( {dummy_pkg_name: f"{dummy_pkg_name}-1.0.0-py3-none-any.whl"}) _mock_fetch_bytes = mock_fetch_bytes(dummy_pkg_name, "UNKNOWN") monkeypatch.setattr(_micropip, "_get_pypi_json", _mock_get_pypi_json) monkeypatch.setattr(_micropip, "fetch_bytes", _mock_fetch_bytes) asyncio.get_event_loop().run_until_complete( _micropip.install(dummy_pkg_name)) pkg_list = _micropip._list() assert "dummy" in pkg_list and pkg_list["dummy"].source.lower() == "pypi"
def test_install_keep_going(monkeypatch): pytest.importorskip("packaging") from micropip import _micropip dummy_pkg_name = "dummy" _mock_get_pypi_json = mock_get_pypi_json( {dummy_pkg_name: f"{dummy_pkg_name}-1.0.0-py3-none-any.whl"}) _mock_fetch_bytes = mock_fetch_bytes( dummy_pkg_name, "Requires-Dist: dep1\nRequires-Dist: dep2\n\nUNKNOWN") monkeypatch.setattr(_micropip, "_get_pypi_json", _mock_get_pypi_json) monkeypatch.setattr(_micropip, "fetch_bytes", _mock_fetch_bytes) # report order is non-deterministic msg = "(dep1|dep2).*(dep2|dep1)" with pytest.raises(ValueError, match=msg): asyncio.get_event_loop().run_until_complete( _micropip.install(dummy_pkg_name, keep_going=True))