Exemplo n.º 1
0
def test_build_editable(tmp_path: Path) -> None:
    with build_fixture_project("demo-package") as project:
        wheel_name = api.build_editable(tmp_path.as_posix())
        assert api.get_requires_for_build_editable() == []
        with zipfile.ZipFile(tmp_path / wheel_name) as zf:
            namelist = zf.namelist()
            assert "demo_package.pth" in namelist
            assert "__editables_demo_package.py" in namelist

            metadata = email.message_from_bytes(
                zf.read("demo_package-0.1.0.dist-info/METADATA")
            )
            assert "editables" in metadata.get_all("Requires-Dist", [])

            pth_content = zf.read("demo_package.pth").decode("utf-8").strip()
            assert pth_content == "import __editables_demo_package"

            proxy_module = (
                zf.read("__editables_demo_package.py").decode("utf-8").strip()
            )
            assert proxy_module == (
                "from editables.redirector import RedirectingFinder as F\n"
                "F.install()\n"
                "F.map_module('my_package', {!r})".format(
                    str((project / "my_package" / "__init__.py").resolve())
                )
            )
Exemplo n.º 2
0
def test_build_editable_pep420(tmp_path):
    with build_fixture_project("demo-pep420-package") as project:
        wheel_name = api.build_editable(tmp_path.as_posix())

        with zipfile.ZipFile(tmp_path / wheel_name) as zf:
            namelist = zf.namelist()
            assert "demo_package.pth" in namelist
            assert "_demo_package.py" not in namelist

            metadata = email.message_from_bytes(
                zf.read("demo_package-0.1.0.dist-info/METADATA"))
            assert "editables" not in metadata.get_all("Requires-Dist", [])

            pth_content = zf.read("demo_package.pth").decode("utf-8").strip()
            assert pth_content == str(project.resolve())
Exemplo n.º 3
0
def test_build_editable_src(tmp_path):
    with build_fixture_project("demo-src-package-include") as project:
        wheel_name = api.build_editable(tmp_path.as_posix())

        with zipfile.ZipFile(tmp_path / wheel_name) as zf:
            namelist = zf.namelist()
            assert "demo_package.pth" in namelist
            assert "_demo_package.py" in namelist
            assert "my_package/data.json" not in namelist
            assert "data_out.json" in namelist

            pth_content = zf.read("demo_package.pth").decode("utf-8").strip()
            assert pth_content == "import _demo_package"

            proxy_module = zf.read("_demo_package.py").decode("utf-8").strip()
            assert proxy_module == (
                "from editables.redirector import RedirectingFinder as F\n"
                "F.install()\n"
                "F.map_module('my_package', {!r})".format(
                    str((project / "sub" / "my_package" /
                         "__init__.py").resolve())))