def test_dist()

in utils/build-dists.py [0:0]


def test_dist(dist):
    with set_tmp_dir() as tmp_dir:
        dist_name = (
            re.match(r"^(elasticsearch\d*[_-]dsl)-", os.path.basename(dist))
            .group(1)
            .replace("-", "_")
        )

        # Build the venv and install the dist
        run("python", "-m", "venv", os.path.join(tmp_dir, "venv"))
        venv_python = os.path.join(tmp_dir, "venv/bin/python")
        run(venv_python, "-m", "pip", "install", "-U", "pip")
        run(venv_python, "-m", "pip", "install", dist)

        # Test the sync namespaces
        run(venv_python, "-c", f"from {dist_name} import Q")

        # Ensure that the namespaces are correct for the dist
        for suffix in ("", "1", "2", "5", "6", "7", "8", "9", "10"):
            distx_name = f"elasticsearch{suffix}_dsl"
            run(
                venv_python,
                "-c",
                f"import {distx_name}",
                expect_exit_code=256 if distx_name != dist_name else 0,
            )
            # Tests the dependencies of the dist
            run(
                venv_python,
                "-c",
                f"import elasticsearch{suffix}",
                expect_exit_code=256 if distx_name != dist_name else 0,
            )

        # Uninstall the dist, see that we can't import things anymore
        run(venv_python, "-m", "pip", "uninstall", "--yes", dist_name)
        run(
            venv_python,
            "-c",
            f"from {dist_name} import Q",
            expect_exit_code=256,
        )