From 9bedee5d1158d22b23d59f21333f6e3de27f29be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Sat, 27 Aug 2022 08:03:52 +0200 Subject: [PATCH] test(dependency): increase test coverage for VCSDependency.to_pep_508() --- tests/packages/test_vcs_dependency.py | 56 +++++++++++++++++++-------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/tests/packages/test_vcs_dependency.py b/tests/packages/test_vcs_dependency.py index e849b726d..97aa666c9 100644 --- a/tests/packages/test_vcs_dependency.py +++ b/tests/packages/test_vcs_dependency.py @@ -1,17 +1,52 @@ from __future__ import annotations +from typing import Any + import pytest from poetry.core.packages.vcs_dependency import VCSDependency -def test_to_pep_508() -> None: +@pytest.mark.parametrize( + "kwargs, expected", + [ + ({}, "poetry @ git+https://github.com/python-poetry/poetry.git"), + ( + {"extras": ["foo"]}, + "poetry[foo] @ git+https://github.com/python-poetry/poetry.git", + ), + ( + {"extras": ["foo", "bar"]}, + "poetry[bar,foo] @ git+https://github.com/python-poetry/poetry.git", + ), + ( + {"branch": "main"}, + "poetry @ git+https://github.com/python-poetry/poetry.git@main", + ), + ( + {"tag": "1.0"}, + "poetry @ git+https://github.com/python-poetry/poetry.git@1.0", + ), + ( + {"rev": "12345"}, + "poetry @ git+https://github.com/python-poetry/poetry.git@12345", + ), + ( + {"directory": "sub"}, + "poetry @ git+https://github.com/python-poetry/poetry.git#subdirectory=sub", + ), + ( + {"branch": "main", "directory": "sub"}, + "poetry @ git+https://github.com/python-poetry/poetry.git" + "@main#subdirectory=sub", + ), + ], +) +def test_to_pep_508(kwargs: dict[str, Any], expected: str) -> None: dependency = VCSDependency( - "poetry", "git", "https://github.com/python-poetry/poetry.git" + "poetry", "git", "https://github.com/python-poetry/poetry.git", **kwargs ) - expected = "poetry @ git+https://github.com/python-poetry/poetry.git" - assert dependency.to_pep_508() == expected @@ -23,19 +58,6 @@ def test_to_pep_508_ssh() -> None: assert dependency.to_pep_508() == expected -def test_to_pep_508_with_extras() -> None: - dependency = VCSDependency( - "poetry", - "git", - "https://github.com/python-poetry/poetry.git", - extras=["foo", "bar"], - ) - - expected = "poetry[bar,foo] @ git+https://github.com/python-poetry/poetry.git" - - assert dependency.to_pep_508() == expected - - def test_to_pep_508_in_extras() -> None: dependency = VCSDependency( "poetry", "git", "https://github.com/python-poetry/poetry.git"