async def test_install_no_deps(mock_fetch: mock_fetch_cls) -> None: dummy = "dummy" dep = "dep" mock_fetch.add_pkg_version(dummy, requirements=[dep]) mock_fetch.add_pkg_version(dep) await micropip.install(dummy, deps=False) assert dummy in micropip.list() assert dep not in micropip.list()
async def test_list_pypi_package(mock_fetch: mock_fetch_cls) -> None: dummy = "dummy" mock_fetch.add_pkg_version(dummy) await micropip.install(dummy) pkg_list = micropip.list() assert dummy in pkg_list assert pkg_list[dummy].source.lower() == "pypi"
async def test_list_wheel_name_mismatch(mock_fetch: mock_fetch_cls) -> None: dummy_pkg_name = "dummy-Dummy" mock_fetch.add_pkg_version(dummy_pkg_name) dummy_url = "https://dummy.com/dummy_dummy-1.0.0-py3-none-any.whl" await micropip.install(dummy_url) pkg_list = micropip.list() assert dummy_pkg_name in pkg_list assert pkg_list[dummy_pkg_name].source.lower() == dummy_url
async def test_list_wheel_package(mock_fetch: mock_fetch_cls) -> None: dummy = "dummy" mock_fetch.add_pkg_version(dummy) dummy_url = f"https://dummy.com/{dummy}-1.0.0-py3-none-any.whl" await micropip.install(dummy_url) pkg_list = micropip.list() assert dummy in pkg_list assert pkg_list[dummy].source.lower() == dummy_url
async def test_install_pre( mock_fetch: mock_fetch_cls, pre: bool, ) -> None: dummy = "dummy" version_alpha = "2.0.1a1" version_stable = "1.0.0" version_should_select = version_alpha if pre else version_stable mock_fetch.add_pkg_version(dummy, version_stable) mock_fetch.add_pkg_version(dummy, version_alpha) await micropip.install(dummy, pre=pre) assert micropip.list()[dummy].version == version_should_select
async def test_install_version_compare_prerelease( mock_fetch: mock_fetch_cls) -> None: dummy = "dummy" version_old = "3.2.0" version_new = "3.2.1a1" mock_fetch.add_pkg_version(dummy, version_old) mock_fetch.add_pkg_version(dummy, version_new) await micropip.install(f"{dummy}=={version_new}") await micropip.install(f"{dummy}>={version_old}") installed_pkgs = micropip.list() # Older version should not be installed assert installed_pkgs[dummy].version == version_new
async def test_package_with_extra(mock_fetch): mock_fetch.add_pkg_version("depa") mock_fetch.add_pkg_version("depb") mock_fetch.add_pkg_version("pkga", extras={"opt_feature": ["depa"]}) mock_fetch.add_pkg_version("pkgb", extras={"opt_feature": ["depb"]}) await micropip.install(["pkga[opt_feature]", "pkgb"]) pkg_list = micropip.list() assert "pkga" in pkg_list assert "depa" in pkg_list assert "pkgb" in pkg_list assert "depb" not in pkg_list
async def test_package_with_extra_transitive(mock_fetch, transitive_req, mock_importlib): mock_fetch.add_pkg_version("depb") pkga_optional_dep = "depa[opt_feature]" if transitive_req else "depa" mock_fetch.add_pkg_version("depa", extras={"opt_feature": ["depb"]}) mock_fetch.add_pkg_version("pkga", extras={"opt_feature": [pkga_optional_dep]}) await micropip.install(["pkga[opt_feature]"]) pkg_list = micropip.list() assert "depa" in pkg_list if transitive_req: assert "depb" in pkg_list else: assert "depb" not in pkg_list