diff --git a/poetry/core/factory.py b/poetry/core/factory.py index 3462ff504..d3becd29e 100644 --- a/poetry/core/factory.py +++ b/poetry/core/factory.py @@ -27,7 +27,7 @@ class Factory(object): """ def create_poetry( - self, cwd: Optional[Path] = None, with_dev: bool = True + self, cwd: Optional[Path] = None, with_groups: bool = True ) -> "Poetry": from .poetry import Poetry from .pyproject.toml import PyProjectTOML @@ -49,7 +49,7 @@ def create_poetry( version = local_config["version"] package = self.get_package(name, version) package = self.configure_package( - package, local_config, poetry_file.parent, with_dev=with_dev + package, local_config, poetry_file.parent, with_groups=with_groups ) return Poetry(poetry_file, local_config, package) @@ -66,9 +66,10 @@ def configure_package( package: "ProjectPackage", config: Dict[str, Any], root: Path, - with_dev: bool = True, + with_groups: bool = True, ) -> "ProjectPackage": from .packages.dependency import Dependency + from .packages.dependency_group import DependencyGroup from .spdx.helpers import license_by_id package.root_dir = root @@ -99,6 +100,7 @@ def configure_package( package.platform = config["platform"] if "dependencies" in config: + group = DependencyGroup("default") for name, constraint in config["dependencies"].items(): if name.lower() == "python": package.python_versions = constraint @@ -106,7 +108,7 @@ def configure_package( if isinstance(constraint, list): for _constraint in constraint: - package.add_dependency( + group.add_dependency( cls.create_dependency( name, _constraint, root_dir=package.root_dir ) @@ -114,31 +116,66 @@ def configure_package( continue - package.add_dependency( + group.add_dependency( cls.create_dependency(name, constraint, root_dir=package.root_dir) ) - if with_dev and "dev-dependencies" in config: + package.add_dependency_group(group) + + if with_groups and "group" in config: + for group_name, group_config in config["group"].items(): + group = DependencyGroup( + group_name, optional=group_config.get("optional", False) + ) + for name, constraint in group_config["dependencies"].items(): + if isinstance(constraint, list): + for _constraint in constraint: + group.add_dependency( + cls.create_dependency( + name, + _constraint, + groups=[group_name], + root_dir=package.root_dir, + ) + ) + + continue + + group.add_dependency( + cls.create_dependency( + name, + constraint, + groups=[group_name], + root_dir=package.root_dir, + ) + ) + + package.add_dependency_group(group) + + if with_groups and "dev-dependencies" in config: + group = DependencyGroup("dev") for name, constraint in config["dev-dependencies"].items(): if isinstance(constraint, list): for _constraint in constraint: - package.add_dependency( + group.add_dependency( cls.create_dependency( name, _constraint, - category="dev", + groups=["dev"], root_dir=package.root_dir, ) ) continue - package.add_dependency( + group.add_dependency( cls.create_dependency( - name, constraint, category="dev", root_dir=package.root_dir + name, constraint, groups=["dev"], root_dir=package.root_dir ) ) + package.add_dependency_group(group) + extras = config.get("extras", {}) for extra_name, requirements in extras.items(): package.extras[extra_name] = [] @@ -191,7 +228,7 @@ def create_dependency( cls, name: str, constraint: Union[str, Dict[str, Any]], - category: str = "main", + groups: Optional[List[str]] = None, root_dir: Optional[Path] = None, ) -> "DependencyTypes": from .packages.constraints import parse_constraint as parse_generic_constraint @@ -204,6 +241,9 @@ def create_dependency( from .version.markers import AnyMarker from .version.markers import parse_marker + if groups is None: + groups = ["default"] + if constraint is None: constraint = "*" @@ -234,7 +274,7 @@ def create_dependency( branch=constraint.get("branch", None), tag=constraint.get("tag", None), rev=constraint.get("rev", None), - category=category, + groups=groups, optional=optional, develop=constraint.get("develop", False), extras=constraint.get("extras", []), @@ -245,7 +285,7 @@ def create_dependency( dependency = FileDependency( name, file_path, - category=category, + groups=groups, base=root_dir, extras=constraint.get("extras", []), ) @@ -261,7 +301,7 @@ def create_dependency( dependency = FileDependency( name, path, - category=category, + groups=groups, optional=optional, base=root_dir, extras=constraint.get("extras", []), @@ -270,7 +310,7 @@ def create_dependency( dependency = DirectoryDependency( name, path, - category=category, + groups=groups, optional=optional, base=root_dir, develop=constraint.get("develop", False), @@ -280,7 +320,7 @@ def create_dependency( dependency = URLDependency( name, constraint["url"], - category=category, + groups=groups, optional=optional, extras=constraint.get("extras", []), ) @@ -291,7 +331,7 @@ def create_dependency( name, version, optional=optional, - category=category, + groups=groups, allows_prereleases=allows_prereleases, extras=constraint.get("extras", []), ) @@ -324,7 +364,7 @@ def create_dependency( dependency.source_name = constraint.get("source") else: - dependency = Dependency(name, constraint, category=category) + dependency = Dependency(name, constraint, groups=groups) return dependency diff --git a/poetry/core/json/schemas/poetry-schema.json b/poetry/core/json/schemas/poetry-schema.json index 16c81bc76..b1493503a 100644 --- a/poetry/core/json/schemas/poetry-schema.json +++ b/poetry/core/json/schemas/poetry-schema.json @@ -147,6 +147,32 @@ } } }, + "group": { + "type": "object", + "description": "This represents groups of dependencies", + "patternProperties": { + "^[a-zA-Z-_.0-9]+$": { + "type": "object", + "description": "This represents a single dependency group", + "required": [ + "dependencies" + ], + "properties": { + "optional": { + "type": "boolean", + "description": "Whether the dependency group is optional or not" + }, + "dependencies": { + "type": "object", + "description": "The dependencies of this dependency group", + "$ref": "#/definitions/dependencies", + "additionalProperties": false + } + }, + "additionalProperties": false + } + } + }, "build": { "$ref": "#/definitions/build-section" }, diff --git a/poetry/core/masonry/api.py b/poetry/core/masonry/api.py index e0a9be858..6f65141cb 100644 --- a/poetry/core/masonry/api.py +++ b/poetry/core/masonry/api.py @@ -39,7 +39,7 @@ def get_requires_for_build_wheel( def prepare_metadata_for_build_wheel( metadata_directory: str, config_settings: Optional[Dict[str, Any]] = None ) -> str: - poetry = Factory().create_poetry(Path(".").resolve(), with_dev=False) + poetry = Factory().create_poetry(Path(".").resolve(), with_groups=False) builder = WheelBuilder(poetry) dist_info = Path(metadata_directory, builder.dist_info) @@ -64,7 +64,7 @@ def build_wheel( metadata_directory: Optional[str] = None, ) -> str: """Builds a wheel, places it in wheel_directory""" - poetry = Factory().create_poetry(Path(".").resolve(), with_dev=False) + poetry = Factory().create_poetry(Path(".").resolve(), with_groups=False) return WheelBuilder.make_in(poetry, Path(wheel_directory)) @@ -73,7 +73,7 @@ def build_sdist( sdist_directory: str, config_settings: Optional[Dict[str, Any]] = None ) -> str: """Builds an sdist, places it in sdist_directory""" - poetry = Factory().create_poetry(Path(".").resolve(), with_dev=False) + poetry = Factory().create_poetry(Path(".").resolve(), with_groups=False) path = SdistBuilder(poetry).build(Path(sdist_directory)) diff --git a/poetry/core/packages/dependency.py b/poetry/core/packages/dependency.py index dd7fc1047..19a76201e 100644 --- a/poetry/core/packages/dependency.py +++ b/poetry/core/packages/dependency.py @@ -34,7 +34,7 @@ def __init__( name: str, constraint: Union[str, "VersionTypes"], optional: bool = False, - category: str = "main", + groups: Optional[List[str]] = None, allows_prereleases: bool = False, extras: Union[List[str], FrozenSet[str]] = None, source_type: Optional[str] = None, @@ -58,7 +58,11 @@ def __init__( self._pretty_constraint = str(constraint) self._optional = optional - self._category = category + + if groups is None: + groups = ["default"] + + self._groups = frozenset(groups) if ( isinstance(self._constraint, VersionRangeConstraint) @@ -113,8 +117,8 @@ def pretty_name(self) -> str: return self._pretty_name @property - def category(self) -> str: - return self._category + def groups(self) -> FrozenSet[str]: + return self._groups @property def python_versions(self) -> str: @@ -387,7 +391,7 @@ def with_constraint(self, constraint: Union[str, "VersionTypes"]) -> "Dependency self.pretty_name, constraint, optional=self.is_optional(), - category=self.category, + groups=list(self._groups), allows_prereleases=self.allows_prereleases(), extras=self._extras, source_type=self._source_type, diff --git a/poetry/core/packages/dependency_group.py b/poetry/core/packages/dependency_group.py new file mode 100644 index 000000000..65e26d603 --- /dev/null +++ b/poetry/core/packages/dependency_group.py @@ -0,0 +1,54 @@ +from typing import TYPE_CHECKING +from typing import List + + +if TYPE_CHECKING: + from .types import DependencyTypes + + +class DependencyGroup: + def __init__(self, name: str, optional: bool = False) -> None: + self._name: str = name + self._optional: bool = optional + self._dependencies: List["DependencyTypes"] = [] + + @property + def name(self) -> str: + return self._name + + @property + def dependencies(self) -> List["DependencyTypes"]: + return self._dependencies + + def is_optional(self) -> bool: + return self._optional + + def add_dependency(self, dependency: "DependencyTypes") -> None: + self._dependencies.append(dependency) + + def remove_dependency(self, name: "str") -> None: + from poetry.core.utils.helpers import canonicalize_name + + name = canonicalize_name(name) + + dependencies = [] + for dependency in dependencies: + if dependency.name == name: + continue + + dependencies.append(dependency) + + self._dependencies = dependencies + + def __eq__(self, other: "DependencyGroup") -> bool: + if not isinstance(other, DependencyGroup): + return NotImplemented + + return self._name == other.name and set(self._dependencies) == set( + other.dependencies + ) + + def __repr__(self) -> str: + return "{}({}, optional={})".format( + self.__class__.__name__, self._name, self._optional + ) diff --git a/poetry/core/packages/directory_dependency.py b/poetry/core/packages/directory_dependency.py index 184f534a2..de029915f 100644 --- a/poetry/core/packages/directory_dependency.py +++ b/poetry/core/packages/directory_dependency.py @@ -18,7 +18,7 @@ def __init__( self, name: str, path: Path, - category: str = "main", + groups: Optional[List[str]] = None, optional: bool = False, base: Optional[Path] = None, develop: bool = False, @@ -61,7 +61,7 @@ def __init__( super(DirectoryDependency, self).__init__( name, "*", - category=category, + groups=groups, optional=optional, allows_prereleases=True, source_type="directory", @@ -97,7 +97,7 @@ def with_constraint(self, constraint: "BaseConstraint") -> "DirectoryDependency" path=self.path, base=self.base, optional=self.is_optional(), - category=self.category, + groups=list(self._groups), develop=self._develop, extras=self._extras, ) diff --git a/poetry/core/packages/file_dependency.py b/poetry/core/packages/file_dependency.py index 6485a5c5e..dc5f2f6b2 100644 --- a/poetry/core/packages/file_dependency.py +++ b/poetry/core/packages/file_dependency.py @@ -22,7 +22,7 @@ def __init__( self, name: str, path: Path, - category: str = "main", + groups: Optional[List[str]] = None, optional: bool = False, base: Optional[Path] = None, extras: Optional[Union[List[str], FrozenSet[str]]] = None, @@ -46,7 +46,7 @@ def __init__( super(FileDependency, self).__init__( name, "*", - category=category, + groups=groups, optional=optional, allows_prereleases=True, source_type="file", @@ -83,7 +83,7 @@ def with_constraint(self, constraint: "BaseConstraint") -> "FileDependency": path=self.path, base=self.base, optional=self.is_optional(), - category=self.category, + groups=list(self._groups), extras=self._extras, ) diff --git a/poetry/core/packages/package.py b/poetry/core/packages/package.py index df90139f8..ff2851360 100644 --- a/poetry/core/packages/package.py +++ b/poetry/core/packages/package.py @@ -21,6 +21,7 @@ from poetry.core.spdx.license import License # noqa from poetry.core.version.markers import BaseMarker # noqa + from .dependency_group import DependencyGroup from .types import DependencyTypes AUTHOR_REGEX = re.compile(r"(?u)^(?P[- .,\w\d'’\"()&]+)(?: <(?P.+?)>)?$") @@ -87,11 +88,12 @@ def __init__( self._license = None self.readme = None - self.requires = [] - self.dev_requires = [] self.extras = {} self.requires_extras = [] + self._dependency_groups: Dict[str, "DependencyGroup"] = {} + + # For compatibility with previous version, we keep the category self.category = "main" self.files = [] self.optional = False @@ -183,11 +185,29 @@ def maintainer_name(self) -> str: def maintainer_email(self) -> str: return self._get_maintainer()["email"] + @property + def requires(self) -> List["DependencyTypes"]: + """ + Returns the default dependencies + """ + if not self._dependency_groups or "default" not in self._dependency_groups: + return [] + + return self._dependency_groups["default"].dependencies + @property def all_requires( self, ) -> List[Union["DependencyTypes"]]: - return self.requires + self.dev_requires + """ + Returns the default dependencies and group dependencies. + """ + return self.requires + [ + dependency + for group in self._dependency_groups.values() + for dependency in group.dependencies + if group.name != "default" + ] def _get_author(self) -> Dict[str, Optional[str]]: if not self._authors: @@ -332,17 +352,77 @@ def is_prerelease(self) -> bool: def is_root(self) -> bool: return False + def add_dependency_group(self, group: "DependencyGroup") -> None: + self._dependency_groups[group.name] = group + + def dependency_group(self, name: str) -> "DependencyGroup": + if name not in self._dependency_groups: + raise ValueError(f'The dependency group "{name}" does not exist.') + + return self._dependency_groups[name] + def add_dependency( self, dependency: "DependencyTypes", ) -> "DependencyTypes": - if dependency.category == "dev": - self.dev_requires.append(dependency) - else: - self.requires.append(dependency) + from .dependency_group import DependencyGroup + + for group_name in dependency.groups: + if group_name not in self._dependency_groups: + # Dynamically add the dependency group + self.add_dependency_group(DependencyGroup(group_name)) + + self._dependency_groups[group_name].add_dependency(dependency) return dependency + def without_dependency_groups(self, groups: List[str]) -> "Package": + """ + Returns a clone of the package with the given dependency groups excluded. + """ + package = self.clone() + + for group_name in groups: + if group_name in package._dependency_groups: + del package._dependency_groups[group_name] + + return package + + def without_optional_dependency_groups(self) -> "Package": + """ + Returns a clone of the package without optional dependency groups. + """ + package = self.clone() + + for group_name, group in self._dependency_groups.items(): + if group.is_optional(): + del package._dependency_groups[group_name] + + return package + + def with_dependency_groups( + self, groups: List[str], only: bool = False + ) -> "Package": + """ + Returns a clone of the package with the given dependency groups opted in. + + Note that it will return all dependencies across all groups + more the given, optional, groups. + + If `only` is set to True, then only the given groups will be selected. + """ + package = self.clone() + + for group_name, group in self._dependency_groups.items(): + if only: + if group_name not in groups: + del package._dependency_groups[group_name] + else: + if group.is_optional() and group_name not in groups: + del package._dependency_groups[group_name] + + return package + def to_dependency( self, ) -> Union["DependencyTypes"]: @@ -358,7 +438,7 @@ def to_dependency( dep = DirectoryDependency( self._name, Path(self._source_url), - category=self.category, + groups=list(self._dependency_groups.keys()), optional=self.optional, base=self.root_dir, develop=self.develop, @@ -368,7 +448,7 @@ def to_dependency( dep = FileDependency( self._name, Path(self._source_url), - category=self.category, + groups=list(self._dependency_groups.keys()), optional=self.optional, base=self.root_dir, extras=self.features, @@ -377,7 +457,7 @@ def to_dependency( dep = URLDependency( self._name, self._source_url, - category=self.category, + groups=list(self._dependency_groups.keys()), optional=self.optional, extras=self.features, ) @@ -388,7 +468,7 @@ def to_dependency( self.source_url, rev=self.source_reference, resolved_rev=self.source_resolved_reference, - category=self.category, + groups=list(self._dependency_groups.keys()), optional=self.optional, develop=self.develop, extras=self.features, diff --git a/poetry/core/packages/url_dependency.py b/poetry/core/packages/url_dependency.py index e8770e815..3e7aaafbc 100644 --- a/poetry/core/packages/url_dependency.py +++ b/poetry/core/packages/url_dependency.py @@ -1,6 +1,7 @@ from typing import TYPE_CHECKING from typing import FrozenSet from typing import List +from typing import Optional from typing import Union from urllib.parse import urlparse @@ -16,7 +17,7 @@ def __init__( self, name: str, url: str, - category: str = "main", + groups: Optional[List[str]] = None, optional: bool = False, extras: Union[List[str], FrozenSet[str]] = None, ): @@ -29,7 +30,7 @@ def __init__( super(URLDependency, self).__init__( name, "*", - category=category, + groups=groups, optional=optional, allows_prereleases=True, source_type="url", @@ -60,7 +61,7 @@ def with_constraint(self, constraint: "BaseConstraint") -> "URLDependency": self.pretty_name, url=self._url, optional=self.is_optional(), - category=self.category, + groups=list(self._groups), extras=self._extras, ) diff --git a/poetry/core/packages/vcs_dependency.py b/poetry/core/packages/vcs_dependency.py index 932338c16..145bd6b0c 100644 --- a/poetry/core/packages/vcs_dependency.py +++ b/poetry/core/packages/vcs_dependency.py @@ -25,7 +25,7 @@ def __init__( tag: Optional[str] = None, rev: Optional[str] = None, resolved_rev: Optional[str] = None, - category: str = "main", + groups: Optional[List[str]] = None, optional: bool = False, develop: bool = False, extras: Union[List[str], FrozenSet[str]] = None, @@ -45,7 +45,7 @@ def __init__( super(VCSDependency, self).__init__( name, "*", - category=category, + groups=groups, optional=optional, allows_prereleases=True, source_type=self._vcs.lower(), @@ -132,7 +132,7 @@ def with_constraint(self, constraint: "BaseConstraint") -> "VCSDependency": rev=self._rev, resolved_rev=self._source_resolved_reference, optional=self.is_optional(), - category=self.category, + groups=list(self._groups), develop=self._develop, extras=self._extras, ) diff --git a/tests/fixtures/sample_project/pyproject.toml b/tests/fixtures/sample_project/pyproject.toml index f2cc0bce2..b2911d645 100644 --- a/tests/fixtures/sample_project/pyproject.toml +++ b/tests/fixtures/sample_project/pyproject.toml @@ -50,7 +50,7 @@ dataclasses = {version = "^0.7", python = ">=3.6.1,<3.7"} [tool.poetry.extras] db = [ "orator" ] -[tool.poetry.dev-dependencies] +[tool.poetry.group.dev.dependencies] pytest = "~3.4" diff --git a/tests/packages/test_dependency.py b/tests/packages/test_dependency.py index 635077055..0baa12700 100644 --- a/tests/packages/test_dependency.py +++ b/tests/packages/test_dependency.py @@ -250,7 +250,7 @@ def test_with_constraint(): "foo", "^1.2.3", optional=True, - category="dev", + groups=["dev"], allows_prereleases=True, extras=["bar", "baz"], ) @@ -268,7 +268,7 @@ def test_with_constraint(): assert new.name == dependency.name assert str(new.constraint) == ">=1.2.6,<2.0.0" assert new.is_optional() - assert new.category == "dev" + assert new.groups == frozenset(["dev"]) assert new.allows_prereleases() assert set(new.extras) == {"bar", "baz"} assert new.marker == dependency.marker diff --git a/tests/packages/test_package.py b/tests/packages/test_package.py index 6432d582a..799255d2b 100644 --- a/tests/packages/test_package.py +++ b/tests/packages/test_package.py @@ -6,9 +6,26 @@ import pytest +from poetry.core.factory import Factory +from poetry.core.packages.dependency_group import DependencyGroup from poetry.core.packages.package import Package +@pytest.fixture() +def package_with_groups(): + package = Package("foo", "1.2.3") + + optional_group = DependencyGroup("optional", optional=True) + optional_group.add_dependency(Factory.create_dependency("bam", "^3.0.0")) + + package.add_dependency(Factory.create_dependency("bar", "^1.0.0")) + package.add_dependency(Factory.create_dependency("baz", "^1.1.0")) + package.add_dependency(Factory.create_dependency("bim", "^2.0.0", groups=["dev"])) + package.add_dependency_group(optional_group) + + return package + + def test_package_authors(): package = Package("foo", "0.1.0") @@ -34,21 +51,21 @@ def test_package_authors_invalid(): ) -@pytest.mark.parametrize("category", ["main", "dev"]) -def test_package_add_dependency_vcs_category(category, f): +@pytest.mark.parametrize("groups", [["default"], ["dev"]]) +def test_package_add_dependency_vcs_groups(groups, f): package = Package("foo", "0.1.0") dependency = package.add_dependency( f.create_dependency( "poetry", {"git": "https://github.com/python-poetry/poetry.git"}, - category=category, + groups=groups, ) ) - assert dependency.category == category + assert dependency.groups == frozenset(groups) -def test_package_add_dependency_vcs_category_default_main(f): +def test_package_add_dependency_vcs_groups_default_main(f): package = Package("foo", "0.1.0") dependency = package.add_dependency( @@ -56,12 +73,12 @@ def test_package_add_dependency_vcs_category_default_main(f): "poetry", {"git": "https://github.com/python-poetry/poetry.git"} ) ) - assert dependency.category == "main" + assert dependency.groups == frozenset(["default"]) -@pytest.mark.parametrize("category", ["main", "dev"]) +@pytest.mark.parametrize("groups", [["default"], ["dev"]]) @pytest.mark.parametrize("optional", [True, False]) -def test_package_url_category_optional(category, optional, f): +def test_package_url_groups_optional(groups, optional, f): package = Package("foo", "0.1.0") dependency = package.add_dependency( @@ -71,10 +88,10 @@ def test_package_url_category_optional(category, optional, f): "url": "https://github.com/python-poetry/poetry/releases/download/1.0.5/poetry-1.0.5-linux.tar.gz", "optional": optional, }, - category=category, + groups=groups, ) ) - assert dependency.category == category + assert dependency.groups == frozenset(groups) assert dependency.is_optional() == optional @@ -301,6 +318,8 @@ def test_package_clone(f): features=["abc", "def"], develop=random.choice((True, False)), ) + p.add_dependency(Factory.create_dependency("foo", "^1.2.3")) + p.add_dependency(Factory.create_dependency("foo", "^1.2.3", groups=["dev"])) p.files = (["file1", "file2", "file3"],) p.homepage = "https://some.other.url" p.repository_url = "http://bug.farm" @@ -309,3 +328,58 @@ def test_package_clone(f): assert p == p2 assert p.__dict__ == p2.__dict__ + assert len(p2.requires) == 1 + assert len(p2.all_requires) == 2 + + +def test_dependency_groups(package_with_groups): + assert len(package_with_groups.requires) == 2 + assert len(package_with_groups.all_requires) == 4 + + +def test_without_dependency_groups(package_with_groups): + package = package_with_groups.without_dependency_groups(["dev"]) + + assert len(package.requires) == 2 + assert len(package.all_requires) == 3 + + package = package_with_groups.without_dependency_groups(["dev", "optional"]) + + assert len(package.requires) == 2 + assert len(package.all_requires) == 2 + + +def test_with_dependency_groups(package_with_groups): + package = package_with_groups.with_dependency_groups([]) + + assert len(package.requires) == 2 + assert len(package.all_requires) == 3 + + package = package_with_groups.with_dependency_groups(["optional"]) + + assert len(package.requires) == 2 + assert len(package.all_requires) == 4 + + +def test_without_optional_dependency_groups(package_with_groups): + package = package_with_groups.without_optional_dependency_groups() + + assert len(package.requires) == 2 + assert len(package.all_requires) == 3 + + +def test_only_with_dependency_groups(package_with_groups): + package = package_with_groups.with_dependency_groups(["dev"], only=True) + + assert len(package.requires) == 0 + assert len(package.all_requires) == 1 + + package = package_with_groups.with_dependency_groups(["dev", "optional"], only=True) + + assert len(package.requires) == 0 + assert len(package.all_requires) == 2 + + package = package_with_groups.with_dependency_groups(["default"], only=True) + + assert len(package.requires) == 2 + assert len(package.all_requires) == 2 diff --git a/tests/packages/test_vcs_dependency.py b/tests/packages/test_vcs_dependency.py index 188350c6a..5e97769fd 100644 --- a/tests/packages/test_vcs_dependency.py +++ b/tests/packages/test_vcs_dependency.py @@ -59,15 +59,15 @@ def test_to_pep_508_in_extras(): assert expected == dependency.to_pep_508() -@pytest.mark.parametrize("category", ["main", "dev"]) -def test_category(category): +@pytest.mark.parametrize("groups", [["main"], ["dev"]]) +def test_category(groups): dependency = VCSDependency( "poetry", "git", "https://github.com/python-poetry/poetry.git", - category=category, + groups=groups, ) - assert category == dependency.category + assert dependency.groups == frozenset(groups) def test_vcs_dependency_can_have_resolved_reference_specified(): diff --git a/tests/test_factory.py b/tests/test_factory.py index 165127be1..e4b3eb538 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -199,11 +199,11 @@ def test_create_poetry_fails_on_invalid_configuration(): def test_create_poetry_omits_dev_dependencies_iff_with_dev_is_false(): - poetry = Factory().create_poetry(fixtures_dir / "sample_project", with_dev=False) - assert not any(r for r in poetry.package.dev_requires if "pytest" in str(r)) + poetry = Factory().create_poetry(fixtures_dir / "sample_project", with_groups=False) + assert not any("dev" in r.groups for r in poetry.package.all_requires) poetry = Factory().create_poetry(fixtures_dir / "sample_project") - assert any(r for r in poetry.package.dev_requires if "pytest" in str(r)) + assert any("dev" in r.groups for r in poetry.package.all_requires) def test_create_poetry_fails_with_invalid_dev_dependencies_iff_with_dev_is_true(): @@ -212,5 +212,5 @@ def test_create_poetry_fails_with_invalid_dev_dependencies_iff_with_dev_is_true( assert "does not exist" in str(err.value) Factory().create_poetry( - fixtures_dir / "project_with_invalid_dev_deps", with_dev=False + fixtures_dir / "project_with_invalid_dev_deps", with_groups=False )