"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tests/puzzle/test_provider.py" between
poetry-1.1.15.tar.gz and poetry-1.2.0.tar.gz

About: Poetry is a tool for dependency management and packaging in Python.

test_provider.py  (poetry-1.1.15):test_provider.py  (poetry-1.2.0)
from __future__ import annotations
from pathlib import Path
from subprocess import CalledProcessError from subprocess import CalledProcessError
from typing import TYPE_CHECKING
import pytest import pytest
from clikit.io import NullIO from cleo.io.null_io import NullIO
from poetry.core.packages.dependency import Dependency
from poetry.core.packages import ProjectPackage
from poetry.core.packages.directory_dependency import DirectoryDependency from poetry.core.packages.directory_dependency import DirectoryDependency
from poetry.core.packages.file_dependency import FileDependency from poetry.core.packages.file_dependency import FileDependency
from poetry.core.packages.package import Package
from poetry.core.packages.project_package import ProjectPackage
from poetry.core.packages.url_dependency import URLDependency
from poetry.core.packages.vcs_dependency import VCSDependency from poetry.core.packages.vcs_dependency import VCSDependency
from poetry.factory import Factory
from poetry.inspection.info import PackageInfo from poetry.inspection.info import PackageInfo
from poetry.packages import DependencyPackage
from poetry.puzzle.provider import Provider from poetry.puzzle.provider import Provider
from poetry.repositories.pool import Pool from poetry.repositories.pool import Pool
from poetry.repositories.repository import Repository from poetry.repositories.repository import Repository
from poetry.utils._compat import PY35
from poetry.utils._compat import Path
from poetry.utils.env import EnvCommandError from poetry.utils.env import EnvCommandError
from poetry.utils.env import MockEnv as BaseMockEnv from poetry.utils.env import MockEnv as BaseMockEnv
from tests.helpers import get_dependency from tests.helpers import get_dependency
if TYPE_CHECKING:
from pytest_mock import MockerFixture
SOME_URL = "https://example.com/path.tar.gz"
class MockEnv(BaseMockEnv): class MockEnv(BaseMockEnv):
def run(self, bin, *args): def run(self, bin: str, *args: str) -> None:
raise EnvCommandError(CalledProcessError(1, "python", output="")) raise EnvCommandError(CalledProcessError(1, "python", output=""))
@pytest.fixture @pytest.fixture
def root(): def root() -> ProjectPackage:
return ProjectPackage("root", "1.2.3") return ProjectPackage("root", "1.2.3")
@pytest.fixture @pytest.fixture
def repository(): def repository() -> Repository:
return Repository() return Repository("repo")
@pytest.fixture @pytest.fixture
def pool(repository): def pool(repository: Repository) -> Pool:
pool = Pool() pool = Pool()
pool.add_repository(repository) pool.add_repository(repository)
return pool return pool
@pytest.fixture @pytest.fixture
def provider(root, pool): def provider(root: ProjectPackage, pool: Pool) -> Provider:
return Provider(root, pool, NullIO()) return Provider(root, pool, NullIO())
@pytest.mark.parametrize(
"dependency, expected",
[
(Dependency("foo", "<2"), [Package("foo", "1")]),
(Dependency("foo", "<2", extras=["bar"]), [Package("foo", "1")]),
(Dependency("foo", ">=1"), [Package("foo", "2"), Package("foo", "1")]),
(
Dependency("foo", ">=1a"),
[
Package("foo", "3a"),
Package("foo", "2"),
Package("foo", "2a"),
Package("foo", "1"),
],
),
(
Dependency("foo", ">=1", allows_prereleases=True),
[
Package("foo", "3a"),
Package("foo", "2"),
Package("foo", "2a"),
Package("foo", "1"),
],
),
],
)
def test_search_for(
provider: Provider,
repository: Repository,
dependency: Dependency,
expected: list[Package],
) -> None:
foo1 = Package("foo", "1")
foo2a = Package("foo", "2a")
foo2 = Package("foo", "2")
foo3a = Package("foo", "3a")
repository.add_package(foo1)
repository.add_package(foo2a)
repository.add_package(foo2)
repository.add_package(foo3a)
assert provider.search_for(dependency) == expected
@pytest.mark.parametrize(
"dependency, direct_origin_dependency, expected_before, expected_after",
[
(
Dependency("foo", ">=1"),
URLDependency("foo", SOME_URL),
[Package("foo", "3")],
[Package("foo", "2a", source_type="url", source_url=SOME_URL)],
),
(
Dependency("foo", ">=2"),
URLDependency("foo", SOME_URL),
[Package("foo", "3")],
[],
),
(
Dependency("foo", ">=1", extras=["bar"]),
URLDependency("foo", SOME_URL),
[Package("foo", "3")],
[Package("foo", "2a", source_type="url", source_url=SOME_URL)],
),
(
Dependency("foo", ">=1"),
URLDependency("foo", SOME_URL, extras=["baz"]),
[Package("foo", "3")],
[Package("foo", "2a", source_type="url", source_url=SOME_URL)],
),
(
Dependency("foo", ">=1", extras=["bar"]),
URLDependency("foo", SOME_URL, extras=["baz"]),
[Package("foo", "3")],
[Package("foo", "2a", source_type="url", source_url=SOME_URL)],
),
],
)
def test_search_for_direct_origin_and_extras(
provider: Provider,
repository: Repository,
mocker: MockerFixture,
dependency: Dependency,
direct_origin_dependency: Dependency,
expected_before: list[Package],
expected_after: list[Package],
) -> None:
foo2a_direct_origin = Package("foo", "2a", source_type="url", source_url=SOM
E_URL)
mocker.patch(
"poetry.puzzle.provider.Provider.search_for_direct_origin_dependency",
return_value=foo2a_direct_origin,
)
foo2a = Package("foo", "2a")
foo3 = Package("foo", "3")
repository.add_package(foo2a)
repository.add_package(foo3)
assert provider.search_for(dependency) == expected_before
assert provider.search_for(direct_origin_dependency) == [foo2a_direct_origin
]
assert provider.search_for(dependency) == expected_after
@pytest.mark.parametrize("value", [True, False]) @pytest.mark.parametrize("value", [True, False])
def test_search_for_vcs_retains_develop_flag(provider, value): def test_search_for_vcs_retains_develop_flag(provider: Provider, value: bool):
dependency = VCSDependency( dependency = VCSDependency(
"demo", "git", "https://github.com/demo/demo.git", develop=value "demo", "git", "https://github.com/demo/demo.git", develop=value
) )
package = provider.search_for_vcs(dependency)[0] package = provider.search_for_direct_origin_dependency(dependency)
assert package.develop == value assert package.develop == value
def test_search_for_vcs_setup_egg_info(provider): def test_search_for_vcs_setup_egg_info(provider: Provider):
dependency = VCSDependency("demo", "git", "https://github.com/demo/demo.git" ) dependency = VCSDependency("demo", "git", "https://github.com/demo/demo.git" )
package = provider.search_for_vcs(dependency)[0] package = provider.search_for_direct_origin_dependency(dependency)
assert package.name == "demo" assert package.name == "demo"
assert package.version.text == "0.1.2" assert package.version.text == "0.1.2"
required = [r for r in package.requires if not r.is_optional()] required = [r for r in package.requires if not r.is_optional()]
optional = [r for r in package.requires if r.is_optional()] optional = [r for r in package.requires if r.is_optional()]
assert required == [get_dependency("pendulum", ">=1.4.4")] assert required == [get_dependency("pendulum", ">=1.4.4")]
assert optional == [get_dependency("tomlkit"), get_dependency("cleo")] assert optional == [get_dependency("tomlkit"), get_dependency("cleo")]
assert package.extras == { assert package.extras == {
"foo": [get_dependency("cleo")], "foo": [get_dependency("cleo")],
"bar": [get_dependency("tomlkit")], "bar": [get_dependency("tomlkit")],
} }
def test_search_for_vcs_setup_egg_info_with_extras(provider): def test_search_for_vcs_setup_egg_info_with_extras(provider: Provider):
dependency = VCSDependency( dependency = VCSDependency(
"demo", "git", "https://github.com/demo/demo.git", extras=["foo"] "demo", "git", "https://github.com/demo/demo.git", extras=["foo"]
) )
package = provider.search_for_vcs(dependency)[0] package = provider.search_for_direct_origin_dependency(dependency)
assert package.name == "demo" assert package.name == "demo"
assert package.version.text == "0.1.2" assert package.version.text == "0.1.2"
required = [r for r in package.requires if not r.is_optional()] required = [r for r in package.requires if not r.is_optional()]
optional = [r for r in package.requires if r.is_optional()] optional = [r for r in package.requires if r.is_optional()]
assert required == [get_dependency("pendulum", ">=1.4.4")] assert required == [get_dependency("pendulum", ">=1.4.4")]
assert optional == [get_dependency("tomlkit"), get_dependency("cleo")] assert optional == [get_dependency("tomlkit"), get_dependency("cleo")]
assert package.extras == { assert package.extras == {
"foo": [get_dependency("cleo")], "foo": [get_dependency("cleo")],
"bar": [get_dependency("tomlkit")], "bar": [get_dependency("tomlkit")],
} }
@pytest.mark.skipif(not PY35, reason="AST parsing does not work for Python <3.4" def test_search_for_vcs_read_setup(provider: Provider, mocker: MockerFixture):
)
def test_search_for_vcs_read_setup(provider, mocker):
mocker.patch("poetry.utils.env.EnvManager.get", return_value=MockEnv()) mocker.patch("poetry.utils.env.EnvManager.get", return_value=MockEnv())
dependency = VCSDependency("demo", "git", "https://github.com/demo/demo.git" ) dependency = VCSDependency("demo", "git", "https://github.com/demo/demo.git" )
package = provider.search_for_vcs(dependency)[0] package = provider.search_for_direct_origin_dependency(dependency)
assert package.name == "demo" assert package.name == "demo"
assert package.version.text == "0.1.2" assert package.version.text == "0.1.2"
required = [r for r in package.requires if not r.is_optional()] required = [r for r in package.requires if not r.is_optional()]
optional = [r for r in package.requires if r.is_optional()] optional = [r for r in package.requires if r.is_optional()]
assert required == [get_dependency("pendulum", ">=1.4.4")] assert required == [get_dependency("pendulum", ">=1.4.4")]
assert optional == [get_dependency("tomlkit"), get_dependency("cleo")] assert optional == [get_dependency("tomlkit"), get_dependency("cleo")]
assert package.extras == { assert package.extras == {
"foo": [get_dependency("cleo")], "foo": [get_dependency("cleo")],
"bar": [get_dependency("tomlkit")], "bar": [get_dependency("tomlkit")],
} }
@pytest.mark.skipif(not PY35, reason="AST parsing does not work for Python <3.4" def test_search_for_vcs_read_setup_with_extras(
) provider: Provider, mocker: MockerFixture
def test_search_for_vcs_read_setup_with_extras(provider, mocker): ):
mocker.patch("poetry.utils.env.EnvManager.get", return_value=MockEnv()) mocker.patch("poetry.utils.env.EnvManager.get", return_value=MockEnv())
dependency = VCSDependency( dependency = VCSDependency(
"demo", "git", "https://github.com/demo/demo.git", extras=["foo"] "demo", "git", "https://github.com/demo/demo.git", extras=["foo"]
) )
package = provider.search_for_vcs(dependency)[0] package = provider.search_for_direct_origin_dependency(dependency)
assert package.name == "demo" assert package.name == "demo"
assert package.version.text == "0.1.2" assert package.version.text == "0.1.2"
required = [r for r in package.requires if not r.is_optional()] required = [r for r in package.requires if not r.is_optional()]
optional = [r for r in package.requires if r.is_optional()] optional = [r for r in package.requires if r.is_optional()]
assert required == [get_dependency("pendulum", ">=1.4.4")] assert required == [get_dependency("pendulum", ">=1.4.4")]
assert optional == [get_dependency("tomlkit"), get_dependency("cleo")] assert optional == [get_dependency("tomlkit"), get_dependency("cleo")]
def test_search_for_vcs_read_setup_raises_error_if_no_version(provider, mocker): def test_search_for_vcs_read_setup_raises_error_if_no_version(
provider: Provider, mocker: MockerFixture
):
mocker.patch( mocker.patch(
"poetry.inspection.info.PackageInfo._pep517_metadata", "poetry.inspection.info.get_pep517_metadata",
return_value=PackageInfo(name="demo", version=None), return_value=PackageInfo(name="demo", version=None),
) )
dependency = VCSDependency("demo", "git", "https://github.com/demo/no-versio n.git") dependency = VCSDependency("demo", "git", "https://github.com/demo/no-versio n.git")
with pytest.raises(RuntimeError): with pytest.raises(RuntimeError):
provider.search_for_vcs(dependency) provider.search_for_direct_origin_dependency(dependency)
@pytest.mark.parametrize("directory", ["demo", "non-canonical-name"]) @pytest.mark.parametrize("directory", ["demo", "non-canonical-name"])
def test_search_for_directory_setup_egg_info(provider, directory): def test_search_for_directory_setup_egg_info(provider: Provider, directory: str) :
dependency = DirectoryDependency( dependency = DirectoryDependency(
"demo", "demo",
Path(__file__).parent.parent Path(__file__).parent.parent
/ "fixtures" / "fixtures"
/ "git" / "git"
/ "github.com" / "github.com"
/ "demo" / "demo"
/ directory, / directory,
) )
package = provider.search_for_directory(dependency)[0] package = provider.search_for_direct_origin_dependency(dependency)
assert package.name == "demo" assert package.name == "demo"
assert package.version.text == "0.1.2" assert package.version.text == "0.1.2"
required = [r for r in package.requires if not r.is_optional()] required = [r for r in package.requires if not r.is_optional()]
optional = [r for r in package.requires if r.is_optional()] optional = [r for r in package.requires if r.is_optional()]
assert required == [get_dependency("pendulum", ">=1.4.4")] assert required == [get_dependency("pendulum", ">=1.4.4")]
assert optional == [get_dependency("tomlkit"), get_dependency("cleo")] assert optional == [get_dependency("tomlkit"), get_dependency("cleo")]
assert package.extras == { assert package.extras == {
"foo": [get_dependency("cleo")], "foo": [get_dependency("cleo")],
"bar": [get_dependency("tomlkit")], "bar": [get_dependency("tomlkit")],
} }
def test_search_for_directory_setup_egg_info_with_extras(provider): def test_search_for_directory_setup_egg_info_with_extras(provider: Provider):
dependency = DirectoryDependency( dependency = DirectoryDependency(
"demo", "demo",
Path(__file__).parent.parent Path(__file__).parent.parent
/ "fixtures" / "fixtures"
/ "git" / "git"
/ "github.com" / "github.com"
/ "demo" / "demo"
/ "demo", / "demo",
extras=["foo"], extras=["foo"],
) )
package = provider.search_for_directory(dependency)[0] package = provider.search_for_direct_origin_dependency(dependency)
assert package.name == "demo" assert package.name == "demo"
assert package.version.text == "0.1.2" assert package.version.text == "0.1.2"
required = [r for r in package.requires if not r.is_optional()] required = [r for r in package.requires if not r.is_optional()]
optional = [r for r in package.requires if r.is_optional()] optional = [r for r in package.requires if r.is_optional()]
assert required == [get_dependency("pendulum", ">=1.4.4")] assert required == [get_dependency("pendulum", ">=1.4.4")]
assert optional == [get_dependency("tomlkit"), get_dependency("cleo")] assert optional == [get_dependency("tomlkit"), get_dependency("cleo")]
assert package.extras == { assert package.extras == {
"foo": [get_dependency("cleo")], "foo": [get_dependency("cleo")],
"bar": [get_dependency("tomlkit")], "bar": [get_dependency("tomlkit")],
} }
@pytest.mark.parametrize("directory", ["demo", "non-canonical-name"]) @pytest.mark.parametrize("directory", ["demo", "non-canonical-name"])
def test_search_for_directory_setup_with_base(provider, directory): def test_search_for_directory_setup_with_base(provider: Provider, directory: str ):
dependency = DirectoryDependency( dependency = DirectoryDependency(
"demo", "demo",
Path(__file__).parent.parent Path(__file__).parent.parent
/ "fixtures" / "fixtures"
/ "git" / "git"
/ "github.com" / "github.com"
/ "demo" / "demo"
/ directory, / directory,
base=Path(__file__).parent.parent base=Path(__file__).parent.parent
/ "fixtures" / "fixtures"
/ "git" / "git"
/ "github.com" / "github.com"
/ "demo" / "demo"
/ directory, / directory,
) )
package = provider.search_for_directory(dependency)[0] package = provider.search_for_direct_origin_dependency(dependency)
assert package.name == "demo" assert package.name == "demo"
assert package.version.text == "0.1.2" assert package.version.text == "0.1.2"
required = [r for r in package.requires if not r.is_optional()] required = [r for r in package.requires if not r.is_optional()]
optional = [r for r in package.requires if r.is_optional()] optional = [r for r in package.requires if r.is_optional()]
assert required == [get_dependency("pendulum", ">=1.4.4")] assert required == [get_dependency("pendulum", ">=1.4.4")]
assert optional == [get_dependency("tomlkit"), get_dependency("cleo")] assert optional == [get_dependency("tomlkit"), get_dependency("cleo")]
assert package.extras == { assert package.extras == {
"foo": [get_dependency("cleo")], "foo": [get_dependency("cleo")],
skipping to change at line 229 skipping to change at line 343
} }
assert package.root_dir == ( assert package.root_dir == (
Path(__file__).parent.parent Path(__file__).parent.parent
/ "fixtures" / "fixtures"
/ "git" / "git"
/ "github.com" / "github.com"
/ "demo" / "demo"
/ directory / directory
) )
@pytest.mark.skipif(not PY35, reason="AST parsing does not work for Python <3.4" def test_search_for_directory_setup_read_setup(
) provider: Provider, mocker: MockerFixture
def test_search_for_directory_setup_read_setup(provider, mocker): ):
mocker.patch("poetry.utils.env.EnvManager.get", return_value=MockEnv()) mocker.patch("poetry.utils.env.EnvManager.get", return_value=MockEnv())
dependency = DirectoryDependency( dependency = DirectoryDependency(
"demo", "demo",
Path(__file__).parent.parent Path(__file__).parent.parent
/ "fixtures" / "fixtures"
/ "git" / "git"
/ "github.com" / "github.com"
/ "demo" / "demo"
/ "demo", / "demo",
) )
package = provider.search_for_directory(dependency)[0] package = provider.search_for_direct_origin_dependency(dependency)
assert package.name == "demo" assert package.name == "demo"
assert package.version.text == "0.1.2" assert package.version.text == "0.1.2"
required = [r for r in package.requires if not r.is_optional()] required = [r for r in package.requires if not r.is_optional()]
optional = [r for r in package.requires if r.is_optional()] optional = [r for r in package.requires if r.is_optional()]
assert required == [get_dependency("pendulum", ">=1.4.4")] assert required == [get_dependency("pendulum", ">=1.4.4")]
assert optional == [get_dependency("tomlkit"), get_dependency("cleo")] assert optional == [get_dependency("tomlkit"), get_dependency("cleo")]
assert package.extras == { assert package.extras == {
"foo": [get_dependency("cleo")], "foo": [get_dependency("cleo")],
"bar": [get_dependency("tomlkit")], "bar": [get_dependency("tomlkit")],
} }
@pytest.mark.skipif(not PY35, reason="AST parsing does not work for Python <3.4" def test_search_for_directory_setup_read_setup_with_extras(
) provider: Provider, mocker: MockerFixture
def test_search_for_directory_setup_read_setup_with_extras(provider, mocker): ):
mocker.patch("poetry.utils.env.EnvManager.get", return_value=MockEnv()) mocker.patch("poetry.utils.env.EnvManager.get", return_value=MockEnv())
dependency = DirectoryDependency( dependency = DirectoryDependency(
"demo", "demo",
Path(__file__).parent.parent Path(__file__).parent.parent
/ "fixtures" / "fixtures"
/ "git" / "git"
/ "github.com" / "github.com"
/ "demo" / "demo"
/ "demo", / "demo",
extras=["foo"], extras=["foo"],
) )
package = provider.search_for_directory(dependency)[0] package = provider.search_for_direct_origin_dependency(dependency)
assert package.name == "demo" assert package.name == "demo"
assert package.version.text == "0.1.2" assert package.version.text == "0.1.2"
required = [r for r in package.requires if not r.is_optional()] required = [r for r in package.requires if not r.is_optional()]
optional = [r for r in package.requires if r.is_optional()] optional = [r for r in package.requires if r.is_optional()]
assert required == [get_dependency("pendulum", ">=1.4.4")] assert required == [get_dependency("pendulum", ">=1.4.4")]
assert optional == [get_dependency("tomlkit"), get_dependency("cleo")] assert optional == [get_dependency("tomlkit"), get_dependency("cleo")]
assert package.extras == { assert package.extras == {
"foo": [get_dependency("cleo")], "foo": [get_dependency("cleo")],
"bar": [get_dependency("tomlkit")], "bar": [get_dependency("tomlkit")],
} }
@pytest.mark.skipif(not PY35, reason="AST parsing does not work for Python <3.4" def test_search_for_directory_setup_read_setup_with_no_dependencies(provider: Pr
) ovider):
def test_search_for_directory_setup_read_setup_with_no_dependencies(provider):
dependency = DirectoryDependency( dependency = DirectoryDependency(
"demo", "demo",
Path(__file__).parent.parent Path(__file__).parent.parent
/ "fixtures" / "fixtures"
/ "git" / "git"
/ "github.com" / "github.com"
/ "demo" / "demo"
/ "no-dependencies", / "no-dependencies",
) )
package = provider.search_for_directory(dependency)[0] package = provider.search_for_direct_origin_dependency(dependency)
assert package.name == "demo" assert package.name == "demo"
assert package.version.text == "0.1.2" assert package.version.text == "0.1.2"
assert package.requires == [] assert package.requires == []
assert package.extras == {} assert package.extras == {}
def test_search_for_directory_poetry(provider): def test_search_for_directory_poetry(provider: Provider):
dependency = DirectoryDependency( dependency = DirectoryDependency(
"project-with-extras", "project-with-extras",
Path(__file__).parent.parent / "fixtures" / "project_with_extras", Path(__file__).parent.parent / "fixtures" / "project_with_extras",
) )
package = provider.search_for_directory(dependency)[0] package = provider.search_for_direct_origin_dependency(dependency)
assert package.name == "project-with-extras" assert package.name == "project-with-extras"
assert package.version.text == "1.2.3" assert package.version.text == "1.2.3"
required = [ required = [
r for r in sorted(package.requires, key=lambda r: r.name) if not r.is_op tional() r for r in sorted(package.requires, key=lambda r: r.name) if not r.is_op tional()
] ]
optional = [ optional = [
r for r in sorted(package.requires, key=lambda r: r.name) if r.is_option al() r for r in sorted(package.requires, key=lambda r: r.name) if r.is_option al()
] ]
assert required == [] assert required == []
assert optional == [ assert optional == [
get_dependency("cachy", ">=0.2.0"), get_dependency("cachy", ">=0.2.0"),
get_dependency("pendulum", ">=1.4.4"), get_dependency("pendulum", ">=1.4.4"),
] ]
assert package.extras == { assert package.extras == {
"extras_a": [get_dependency("pendulum", ">=1.4.4")], "extras_a": [get_dependency("pendulum", ">=1.4.4")],
"extras_b": [get_dependency("cachy", ">=0.2.0")], "extras_b": [get_dependency("cachy", ">=0.2.0")],
} }
def test_search_for_directory_poetry_with_extras(provider): def test_search_for_directory_poetry_with_extras(provider: Provider):
dependency = DirectoryDependency( dependency = DirectoryDependency(
"project-with-extras", "project-with-extras",
Path(__file__).parent.parent / "fixtures" / "project_with_extras", Path(__file__).parent.parent / "fixtures" / "project_with_extras",
extras=["extras_a"], extras=["extras_a"],
) )
package = provider.search_for_directory(dependency)[0] package = provider.search_for_direct_origin_dependency(dependency)
assert package.name == "project-with-extras" assert package.name == "project-with-extras"
assert package.version.text == "1.2.3" assert package.version.text == "1.2.3"
required = [ required = [
r for r in sorted(package.requires, key=lambda r: r.name) if not r.is_op tional() r for r in sorted(package.requires, key=lambda r: r.name) if not r.is_op tional()
] ]
optional = [ optional = [
r for r in sorted(package.requires, key=lambda r: r.name) if r.is_option al() r for r in sorted(package.requires, key=lambda r: r.name) if r.is_option al()
] ]
assert required == [] assert required == []
assert optional == [ assert optional == [
get_dependency("cachy", ">=0.2.0"), get_dependency("cachy", ">=0.2.0"),
get_dependency("pendulum", ">=1.4.4"), get_dependency("pendulum", ">=1.4.4"),
] ]
assert package.extras == { assert package.extras == {
"extras_a": [get_dependency("pendulum", ">=1.4.4")], "extras_a": [get_dependency("pendulum", ">=1.4.4")],
"extras_b": [get_dependency("cachy", ">=0.2.0")], "extras_b": [get_dependency("cachy", ">=0.2.0")],
} }
def test_search_for_file_sdist(provider): def test_search_for_file_sdist(provider: Provider):
dependency = FileDependency( dependency = FileDependency(
"demo", "demo",
Path(__file__).parent.parent Path(__file__).parent.parent
/ "fixtures" / "fixtures"
/ "distributions" / "distributions"
/ "demo-0.1.0.tar.gz", / "demo-0.1.0.tar.gz",
) )
package = provider.search_for_file(dependency)[0] package = provider.search_for_direct_origin_dependency(dependency)
assert package.name == "demo" assert package.name == "demo"
assert package.version.text == "0.1.0" assert package.version.text == "0.1.0"
required = [ required = [
r for r in sorted(package.requires, key=lambda r: r.name) if not r.is_op tional() r for r in sorted(package.requires, key=lambda r: r.name) if not r.is_op tional()
] ]
optional = [ optional = [
r for r in sorted(package.requires, key=lambda r: r.name) if r.is_option al() r for r in sorted(package.requires, key=lambda r: r.name) if r.is_option al()
] ]
assert required == [get_dependency("pendulum", ">=1.4.4")] assert required == [get_dependency("pendulum", ">=1.4.4")]
assert optional == [ assert optional == [
get_dependency("cleo"), get_dependency("cleo"),
get_dependency("tomlkit"), get_dependency("tomlkit"),
] ]
assert package.extras == { assert package.extras == {
"foo": [get_dependency("cleo")], "foo": [get_dependency("cleo")],
"bar": [get_dependency("tomlkit")], "bar": [get_dependency("tomlkit")],
} }
def test_search_for_file_sdist_with_extras(provider): def test_search_for_file_sdist_with_extras(provider: Provider):
dependency = FileDependency( dependency = FileDependency(
"demo", "demo",
Path(__file__).parent.parent Path(__file__).parent.parent
/ "fixtures" / "fixtures"
/ "distributions" / "distributions"
/ "demo-0.1.0.tar.gz", / "demo-0.1.0.tar.gz",
extras=["foo"], extras=["foo"],
) )
package = provider.search_for_file(dependency)[0] package = provider.search_for_direct_origin_dependency(dependency)
assert package.name == "demo" assert package.name == "demo"
assert package.version.text == "0.1.0" assert package.version.text == "0.1.0"
required = [ required = [
r for r in sorted(package.requires, key=lambda r: r.name) if not r.is_op tional() r for r in sorted(package.requires, key=lambda r: r.name) if not r.is_op tional()
] ]
optional = [ optional = [
r for r in sorted(package.requires, key=lambda r: r.name) if r.is_option al() r for r in sorted(package.requires, key=lambda r: r.name) if r.is_option al()
] ]
assert required == [get_dependency("pendulum", ">=1.4.4")] assert required == [get_dependency("pendulum", ">=1.4.4")]
assert optional == [ assert optional == [
get_dependency("cleo"), get_dependency("cleo"),
get_dependency("tomlkit"), get_dependency("tomlkit"),
] ]
assert package.extras == { assert package.extras == {
"foo": [get_dependency("cleo")], "foo": [get_dependency("cleo")],
"bar": [get_dependency("tomlkit")], "bar": [get_dependency("tomlkit")],
} }
def test_search_for_file_wheel(provider): def test_search_for_file_wheel(provider: Provider):
dependency = FileDependency( dependency = FileDependency(
"demo", "demo",
Path(__file__).parent.parent Path(__file__).parent.parent
/ "fixtures" / "fixtures"
/ "distributions" / "distributions"
/ "demo-0.1.0-py2.py3-none-any.whl", / "demo-0.1.0-py2.py3-none-any.whl",
) )
package = provider.search_for_file(dependency)[0] package = provider.search_for_direct_origin_dependency(dependency)
assert package.name == "demo" assert package.name == "demo"
assert package.version.text == "0.1.0" assert package.version.text == "0.1.0"
required = [ required = [
r for r in sorted(package.requires, key=lambda r: r.name) if not r.is_op tional() r for r in sorted(package.requires, key=lambda r: r.name) if not r.is_op tional()
] ]
optional = [ optional = [
r for r in sorted(package.requires, key=lambda r: r.name) if r.is_option al() r for r in sorted(package.requires, key=lambda r: r.name) if r.is_option al()
] ]
assert required == [get_dependency("pendulum", ">=1.4.4")] assert required == [get_dependency("pendulum", ">=1.4.4")]
assert optional == [ assert optional == [
get_dependency("cleo"), get_dependency("cleo"),
get_dependency("tomlkit"), get_dependency("tomlkit"),
] ]
assert package.extras == { assert package.extras == {
"foo": [get_dependency("cleo")], "foo": [get_dependency("cleo")],
"bar": [get_dependency("tomlkit")], "bar": [get_dependency("tomlkit")],
} }
def test_search_for_file_wheel_with_extras(provider): def test_search_for_file_wheel_with_extras(provider: Provider):
dependency = FileDependency( dependency = FileDependency(
"demo", "demo",
Path(__file__).parent.parent Path(__file__).parent.parent
/ "fixtures" / "fixtures"
/ "distributions" / "distributions"
/ "demo-0.1.0-py2.py3-none-any.whl", / "demo-0.1.0-py2.py3-none-any.whl",
extras=["foo"], extras=["foo"],
) )
package = provider.search_for_file(dependency)[0] package = provider.search_for_direct_origin_dependency(dependency)
assert package.name == "demo" assert package.name == "demo"
assert package.version.text == "0.1.0" assert package.version.text == "0.1.0"
required = [ required = [
r for r in sorted(package.requires, key=lambda r: r.name) if not r.is_op tional() r for r in sorted(package.requires, key=lambda r: r.name) if not r.is_op tional()
] ]
optional = [ optional = [
r for r in sorted(package.requires, key=lambda r: r.name) if r.is_option al() r for r in sorted(package.requires, key=lambda r: r.name) if r.is_option al()
] ]
assert required == [get_dependency("pendulum", ">=1.4.4")] assert required == [get_dependency("pendulum", ">=1.4.4")]
assert optional == [ assert optional == [
get_dependency("cleo"), get_dependency("cleo"),
get_dependency("tomlkit"), get_dependency("tomlkit"),
] ]
assert package.extras == { assert package.extras == {
"foo": [get_dependency("cleo")], "foo": [get_dependency("cleo")],
"bar": [get_dependency("tomlkit")], "bar": [get_dependency("tomlkit")],
} }
def test_complete_package_preserves_source_type(
provider: Provider, root: ProjectPackage
) -> None:
fixtures = Path(__file__).parent.parent / "fixtures"
project_dir = fixtures.joinpath("with_conditional_path_deps")
for folder in ["demo_one", "demo_two"]:
path = (project_dir / folder).as_posix()
root.add_dependency(Factory.create_dependency("demo", {"path": path}))
complete_package = provider.complete_package(
DependencyPackage(root.to_dependency(), root)
)
requires = complete_package.package.all_requires
assert len(requires) == 2
assert {requires[0].source_url, requires[1].source_url} == {
project_dir.joinpath("demo_one").as_posix(),
project_dir.joinpath("demo_two").as_posix(),
}
def test_complete_package_preserves_source_type_with_subdirectories(
provider: Provider, root: ProjectPackage
) -> None:
dependency_one = Factory.create_dependency(
"one",
{
"git": "https://github.com/demo/subdirectories.git",
"subdirectory": "one",
},
)
dependency_one_copy = Factory.create_dependency(
"one",
{
"git": "https://github.com/demo/subdirectories.git",
"subdirectory": "one-copy",
},
)
dependency_two = Factory.create_dependency(
"two",
{"git": "https://github.com/demo/subdirectories.git", "subdirectory": "t
wo"},
)
root.add_dependency(
Factory.create_dependency(
"one",
{
"git": "https://github.com/demo/subdirectories.git",
"subdirectory": "one",
},
)
)
root.add_dependency(dependency_one_copy)
root.add_dependency(dependency_two)
complete_package = provider.complete_package(
DependencyPackage(root.to_dependency(), root)
)
requires = complete_package.package.all_requires
assert len(requires) == 3
assert {r.to_pep_508() for r in requires} == {
dependency_one.to_pep_508(),
dependency_one_copy.to_pep_508(),
dependency_two.to_pep_508(),
}
 End of changes. 52 change blocks. 
58 lines changed or deleted 171 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)