示例#1
0
def test_merge_pypi_sdist_metadata():
    recipe = PyPi(name="gsw", version="3.3.1")
    pypi_metadata = recipe._get_pypi_metadata(name="gsw", version="3.3.1")
    sdist_metadata = recipe._get_sdist_metadata(pypi_metadata["sdist_url"], "gsw")
    merged_data = PyPi._merge_pypi_sdist_metadata(pypi_metadata, sdist_metadata)
    assert merged_data["compilers"] == ["c"]
    assert sorted(merged_data["setup_requires"]) == sorted(["numpy"])
示例#2
0
def test_get_test_entry_points():
    assert PyPi._get_test_entry_points("grayskull = grayskull.__main__:main") == [
        "grayskull --help"
    ]
    assert PyPi._get_test_entry_points(
        ["pytest = py.test:main", "py.test = py.test:main"]
    ) == ["pytest --help", "py.test --help"]
示例#3
0
def test_get_test_imports():
    assert PyPi._get_test_imports({"packages": ["pkg", "pkg.mod1", "pkg.mod2"]}) == [
        "pkg",
        "pkg.mod1",
    ]
    assert PyPi._get_test_imports({"packages": None}, default="pkg-mod") == ["pkg_mod"]
    assert PyPi._get_test_imports({"packages": "pkg"}, default="pkg-mod") == ["pkg"]
示例#4
0
def test_panel_entry_points(tmpdir):
    recipe = PyPi(name="panel", version="0.9.1")
    recipe.generate_recipe(folder_path=str(tmpdir))
    recipe_path = str(tmpdir / "panel" / "meta.yaml")
    with open(recipe_path, "r") as f:
        content = f.read()
    assert "- panel = panel.cli:main" in content
示例#5
0
def test_get_compilers():
    assert PyPi._get_compilers(["pybind11"], {}) == ["cxx"]
    assert PyPi._get_compilers(["cython"], {}) == ["c"]
    assert sorted(PyPi._get_compilers(["pybind11", "cython"],
                                      {})) == sorted(["cxx", "c"])
    assert sorted(PyPi._get_compilers(
        ["pybind11"], {"compilers": ["c"]})) == sorted(["cxx", "c"])
示例#6
0
def test_injection_distutils_compiler_gsw():
    recipe = PyPi(name="gsw", version="3.3.1")
    data = recipe._get_sdist_metadata(
        "https://pypi.io/packages/source/g/gsw/gsw-3.3.1.tar.gz", "gsw"
    )
    assert data.get("compilers") == ["c"]
    assert data["packages"] == ["gsw"]
示例#7
0
def test_get_all_selectors_pypi():
    recipe = PyPi(name="pytest", version="5.3.1")
    assert recipe._get_all_selectors_pypi([
        ("(", "sys_platform", "==", "win32", "", "and"),
        ("", "python_version", "==", "2.7", ")", "and"),
        ("", "extra", "==", "socks", "", ""),
    ]) == ["(", "win", "and", "py==27", ")"]
示例#8
0
def test_injection_distutils_setup_reqs_ensure_list():
    pkg_name, pkg_ver = "pyinstaller-hooks-contrib", "2020.7"
    recipe = PyPi(name=pkg_name, version=pkg_ver)
    data = recipe._get_sdist_metadata(
        f"https://pypi.io/packages/source/p/{pkg_name}/{pkg_name}-{pkg_ver}.tar.gz",
        pkg_name,
    )
    assert data.get("setup_requires") == ["setuptools >= 30.3.0"]
示例#9
0
def pkg_pytest(tmpdir_factory) -> str:
    folder = tmpdir_factory.mktemp("test-download-pkg")
    dest_pkg = str(folder / "PYTEST-PKG.tar.gz")
    PyPi._download_sdist_pkg(
        "https://pypi.io/packages/source/p/pytest/pytest-5.3.5.tar.gz",
        dest_pkg)
    shutil.unpack_archive(dest_pkg, str(folder))
    return dest_pkg
示例#10
0
def test_get_selector():
    assert PyPi._parse_extra_metadata_to_selector("extra", "==", "win32") == ""
    assert (
        PyPi._parse_extra_metadata_to_selector("sys_platform", "==", "win32") == "win"
    )
    assert (
        PyPi._parse_extra_metadata_to_selector("python_version", "<", "3.6") == "py<36"
    )
示例#11
0
def test_platform_system_selector():
    assert (
        PyPi._parse_extra_metadata_to_selector("platform_system", "==", "Windows")
        == "win"
    )
    assert (
        PyPi._parse_extra_metadata_to_selector("platform_system", "!=", "Windows")
        == "not win"
    )
示例#12
0
def test_py_version_to_limit_python(requires_python, exp_limit, ex_cf):
    metadata = {"requires_python": requires_python}
    assert PyPi.py_version_to_limit_python(metadata) == f"{exp_limit}"

    if ex_cf != "skip":
        result = PyPi.py_version_to_limit_python(metadata, is_strict_cf=True)
        if isinstance(ex_cf, str):
            assert ex_cf == result
        else:
            assert ex_cf is result
示例#13
0
def test_py_version_to_selector(requires_python, exp_selector, ex_cf):
    metadata = {"requires_python": requires_python}
    assert PyPi.py_version_to_selector(metadata) == f"# [py{exp_selector}]"

    if ex_cf != "skip":
        expected = f"# [py{ex_cf}]" if ex_cf else None
        result = PyPi.py_version_to_selector(metadata, is_strict_cf=True)
        if isinstance(expected, str):
            assert expected == result
        else:
            assert expected is result
示例#14
0
def test_update_requirements_with_pin():
    req = {
        "build": ["<{ compiler('c') }}"],
        "host": ["python", "numpy"],
        "run": ["python", "numpy"],
    }
    PyPi._update_requirements_with_pin(req)
    assert req == {
        "build": ["<{ compiler('c') }}"],
        "host": ["python", "numpy"],
        "run": ["python", "<{ pin_compatible('numpy') }}"],
    }
示例#15
0
def test_format_host_requirements():
    assert sorted(
        PyPi._format_dependencies(["setuptools>=40.0", "pkg2"],
                                  "pkg1")) == sorted(
                                      ["setuptools >=40.0", "pkg2"])
    assert sorted(
        PyPi._format_dependencies(["setuptools>=40.0", "pkg2"],
                                  "pkg2")) == sorted(["setuptools >=40.0"])
    assert sorted(PyPi._format_dependencies(
        ["setuptools >= 40.0"], "pkg")) == sorted(["setuptools >=40.0"])
    assert sorted(
        PyPi._format_dependencies(["setuptools_scm [toml] >=3.4.1"],
                                  "pkg")) == sorted(["setuptools_scm >=3.4.1"])
示例#16
0
def test_injection_distutils():
    recipe = PyPi(name="hypothesis", version="5.5.1")
    data = recipe._get_sdist_metadata(
        "https://pypi.io/packages/source/h/hypothesis/hypothesis-5.5.1.tar.gz",
        "hypothesis",
    )
    assert sorted(data["install_requires"]) == sorted(
        ["attrs>=19.2.0", "sortedcontainers>=2.1.0,<3.0.0"])
    assert data["entry_points"] == {
        "pytest11": ["hypothesispytest = hypothesis.extra.pytestplugin"]
    }
    assert data["version"] == "5.5.1"
    assert data["name"] == "hypothesis"
    assert not data.get("compilers")
示例#17
0
def test_recipe_extension():
    recipe = PyPi(name="azure-identity", version="1.3.1")
    assert (
        recipe["source"]["url"][0].value
        == "https://pypi.io/packages/source/{{ name[0] }}/{{ name }}/"
        "azure-identity-{{ version }}.zip"
    )
示例#18
0
def test_zipp_recipe_tags_on_deps():
    recipe = PyPi(name="zipp", version="3.0.0")
    assert recipe["build"]["noarch"]
    assert recipe["requirements"]["host"] == [
        "pip",
        "python >=3.6",
        "setuptools_scm >=3.4.1",
    ]
示例#19
0
def test_extract_pypi_requirements(pypi_metadata):
    recipe = PyPi(name="pytest", version="5.3.1")
    pypi_reqs = recipe._extract_requirements(pypi_metadata["info"])
    assert sorted(pypi_reqs["host"]) == sorted(["python", "pip"])
    assert sorted(pypi_reqs["run"]) == sorted([
        "python",
        "py >=1.5.0",
        "packaging",
        "attrs >=17.4.0",
        "more-itertools >=4.0.0",
        "pluggy <1.0,>=0.12",
        "wcwidth",
        "pathlib2 >=2.2.0  # [py<36]",
        "importlib-metadata >=0.12  # [py<38]",
        "atomicwrites >=1.0  # [win]",
        "colorama   # [win]",
    ])
示例#20
0
def test_requests_recipe_extra_deps(capsys):
    CLIConfig().stdout = True
    recipe = PyPi(name="requests", version="2.22.0")
    captured_stdout = capsys.readouterr()
    assert "win-inet-pton" not in recipe["requirements"]["run"]
    assert recipe["build"]["noarch"]
    assert not recipe["build"]["skip"]
    assert f"{Fore.GREEN}{Style.BRIGHT}python" in captured_stdout.out
示例#21
0
def test_get_extra_from_requires_dist():
    assert PyPi._get_extra_from_requires_dist(' python_version < "3.6"') == [
        ("", "python_version", "<", "3.6", "", "",)
    ]
    assert PyPi._get_extra_from_requires_dist(
        " python_version < \"3.6\" ; extra =='test'"
    ) == [
        ("", "python_version", "<", "3.6", "", ""),
        ("", "extra", "==", "test", "", ""),
    ]
    assert PyPi._get_extra_from_requires_dist(
        ' (sys_platform =="win32" and python_version =="2.7") and extra =="socks"'
    ) == [
        ("(", "sys_platform", "==", "win32", "", "and"),
        ("", "python_version", "==", "2.7", ")", "and"),
        ("", "extra", "==", "socks", "", ""),
    ]
示例#22
0
def test_get_sha256_from_pypi_metadata():
    metadata = {
        "urls": [
            {"packagetype": "egg", "digests": {"sha256": "23123"}},
            {"packagetype": "sdist", "digests": {"sha256": "1234sha256"}},
        ]
    }
    assert PyPi.get_sha256_from_pypi_metadata(metadata) == "1234sha256"

    metadata = {
        "urls": [
            {"packagetype": "egg", "digests": {"sha256": "23123"}},
            {"packagetype": "wheel", "digests": {"sha256": "1234sha256"}},
        ]
    }
    with pytest.raises(AttributeError) as err:
        PyPi.get_sha256_from_pypi_metadata(metadata)
    assert err.match("Hash information for sdist was not found on PyPi metadata.")
示例#23
0
def test_pytest_recipe_entry_points():
    recipe = PyPi(name="pytest", version="5.3.5")
    assert sorted(recipe["build"]["entry_points"]) == sorted(
        ["pytest=pytest:main", "py.test=pytest:main"])
    assert recipe["about"]["license"] == "MIT"
    assert recipe["about"]["license_file"] == "LICENSE"
    assert recipe["build"]["skip"].values[0].value
    assert recipe["build"]["skip"].values[0].selector == "py2k"
    assert not recipe["build"]["noarch"]
示例#24
0
def test_pymc_recipe_fortran():
    recipe = PyPi(name="pymc", version="2.3.6")
    assert sorted(recipe["requirements"]["build"]) == sorted(
        ["<{ compiler('c') }}", "<{ compiler('fortran') }}"])
    assert sorted(recipe["requirements"]["host"]) == sorted(
        ["numpy", "python", "pip"])
    assert sorted(recipe["requirements"]["run"]) == sorted(
        ["<{ pin_compatible('numpy') }}", "python"])
    assert not recipe["build"]["noarch"]
示例#25
0
def test_ciso_recipe():
    recipe = PyPi(name="ciso", version="0.1.0")
    assert sorted(recipe["requirements"]["host"]) == sorted(
        ["cython", "numpy", "pip", "python", "versioneer"])
    assert sorted(recipe["requirements"]["run"]) == sorted(
        ["cython", "python", "<{ pin_compatible('numpy') }}"])
    assert recipe["test"]["commands"] == "pip check"
    assert recipe["test"]["requires"] == "pip"
    assert recipe["test"]["imports"] == "ciso"
示例#26
0
def test_run_requirements_sdist():
    recipe = PyPi(name="botocore", version="1.14.17")
    assert sorted(recipe["requirements"]["run"]) == sorted([
        "docutils >=0.10,<0.16",
        "jmespath >=0.7.1,<1.0.0",
        "python",
        "python-dateutil >=2.1,<3.0.0",
        "urllib3 >=1.20,<1.26",
    ])
示例#27
0
def test_get_url_filename():
    assert PyPi._get_url_filename({}) == "{{ name }}-{{ version }}.tar.gz"
    assert PyPi._get_url_filename({}, "default") == "default"
    assert (PyPi._get_url_filename({"urls": [{
        "packagetype": "nothing"
    }]}) == "{{ name }}-{{ version }}.tar.gz")
    assert (PyPi._get_url_filename({"urls": [{
        "packagetype": "nothing"
    }]}, "default") == "default")
    assert (PyPi._get_url_filename({
        "info": {
            "version": "1.2.3"
        },
        "urls": [{
            "packagetype": "sdist",
            "filename": "foo_file-1.2.3.zip"
        }],
    }) == "foo_file-{{ version }}.zip")
示例#28
0
def test_get_entry_points_from_sdist():
    assert PyPi._get_entry_points_from_sdist({}) == []
    assert PyPi._get_entry_points_from_sdist(
        {"entry_points": {
            "console_scripts": ["console_scripts=entrypoints"]
        }}) == ["console_scripts=entrypoints"]
    assert PyPi._get_entry_points_from_sdist(
        {"entry_points": {
            "gui_scripts": ["gui_scripts=entrypoints"]
        }}) == ["gui_scripts=entrypoints"]

    assert sorted(
        PyPi._get_entry_points_from_sdist({
            "entry_points": {
                "gui_scripts": ["gui_scripts=entrypoints"],
                "console_scripts": ["console_scripts=entrypoints"],
            }
        })) == sorted(
            ["gui_scripts=entrypoints", "console_scripts=entrypoints"])
示例#29
0
def test_injection_distutils_pytest():
    recipe = PyPi(name="pytest", version="5.3.2")
    data = recipe._get_sdist_metadata(
        "https://pypi.io/packages/source/p/pytest/pytest-5.3.2.tar.gz",
        "pytest")
    assert sorted(data["install_requires"]) == sorted([
        "py>=1.5.0",
        "packaging",
        "attrs>=17.4.0",
        "more-itertools>=4.0.0",
        'atomicwrites>=1.0;sys_platform=="win32"',
        'pathlib2>=2.2.0;python_version<"3.6"',
        'colorama;sys_platform=="win32"',
        "pluggy>=0.12,<1.0",
        'importlib-metadata>=0.12;python_version<"3.8"',
        "wcwidth",
    ])
    assert sorted(data["setup_requires"]) == sorted(
        ["setuptools>=40.0", "setuptools_scm"])
    assert not data.get("compilers")
示例#30
0
def test_download_pkg_sdist(pkg_pytest):
    with open(pkg_pytest, "rb") as pkg_file:
        content = pkg_file.read()
        pkg_sha256 = hashlib.sha256(content).hexdigest()
    assert (pkg_sha256 ==
            "0d5fe9189a148acc3c3eb2ac8e1ac0742cb7618c084f3d228baaec0c254b318d")
    setup_cfg = PyPi._get_setup_cfg(os.path.dirname(pkg_pytest))
    assert setup_cfg["name"] == "pytest"
    assert setup_cfg["python_requires"] == ">=3.5"
    assert setup_cfg["entry_points"] == {
        "console_scripts": ["pytest=pytest:main", "py.test=pytest:main"]
    }