Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: make tests compatible with core > 1.1.0a7 #5589

Merged
merged 1 commit into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,13 @@
from typing import Protocol
except ImportError:
from typing_extensions import Protocol # noqa: F401, TC002

from poetry.core.semver.helpers import parse_constraint
from poetry.core.semver.version import Version

from poetry.utils._compat import metadata


is_poetry_core_1_1_0a7_compat = not parse_constraint(">1.1.0a7").allows(
Version.parse(metadata.version("poetry-core"))
)
9 changes: 7 additions & 2 deletions tests/console/commands/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from poetry.core.semver.version import Version

from poetry.repositories.legacy_repository import LegacyRepository
from tests.compat import is_poetry_core_1_1_0a7_compat
from tests.helpers import get_dependency
from tests.helpers import get_package

Expand Down Expand Up @@ -981,7 +982,7 @@ def test_add_chooses_prerelease_if_only_prereleases_are_available(
tester.execute("foo")

expected = """\
Using version ^1.2.3-beta.1 for foo
Using version ^1.2.3b1 for foo

Updating dependencies
Resolving dependencies...
Expand All @@ -992,6 +993,8 @@ def test_add_chooses_prerelease_if_only_prereleases_are_available(

• Installing foo (1.2.3b1)
"""
if is_poetry_core_1_1_0a7_compat:
expected = expected.replace("^1.2.3b1", "^1.2.3-beta.1")

assert expected in tester.io.fetch_output()

Expand Down Expand Up @@ -1912,7 +1915,7 @@ def test_add_chooses_prerelease_if_only_prereleases_are_available_old_installer(
old_tester.execute("foo")

expected = """\
Using version ^1.2.3-beta.1 for foo
Using version ^1.2.3b1 for foo

Updating dependencies
Resolving dependencies...
Expand All @@ -1923,6 +1926,8 @@ def test_add_chooses_prerelease_if_only_prereleases_are_available_old_installer(

- Installing foo (1.2.3b1)
"""
if is_poetry_core_1_1_0a7_compat:
expected = expected.replace("^1.2.3b1", "^1.2.3-beta.1")

assert expected in old_tester.io.fetch_output()

Expand Down
19 changes: 11 additions & 8 deletions tests/console/commands/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest

from poetry.console.commands.version import VersionCommand
from tests.compat import is_poetry_core_1_1_0a7_compat


if TYPE_CHECKING:
Expand Down Expand Up @@ -35,23 +36,25 @@ def tester(command_tester_factory: CommandTesterFactory) -> CommandTester:
("1.2.3", "patch", "1.2.4"),
("1.2.3", "minor", "1.3.0"),
("1.2.3", "major", "2.0.0"),
("1.2.3", "prepatch", "1.2.4-alpha.0"),
("1.2.3", "preminor", "1.3.0-alpha.0"),
("1.2.3", "premajor", "2.0.0-alpha.0"),
("1.2.3", "prepatch", "1.2.4a0"),
("1.2.3", "preminor", "1.3.0a0"),
("1.2.3", "premajor", "2.0.0a0"),
("1.2.3-beta.1", "patch", "1.2.3"),
("1.2.3-beta.1", "minor", "1.3.0"),
("1.2.3-beta.1", "major", "2.0.0"),
("1.2.3-beta.1", "prerelease", "1.2.3-beta.2"),
("1.2.3-beta1", "prerelease", "1.2.3-beta.2"),
("1.2.3beta1", "prerelease", "1.2.3-beta.2"),
("1.2.3b1", "prerelease", "1.2.3-beta.2"),
("1.2.3", "prerelease", "1.2.4-alpha.0"),
("1.2.3-beta.1", "prerelease", "1.2.3b2"),
("1.2.3-beta1", "prerelease", "1.2.3b2"),
("1.2.3beta1", "prerelease", "1.2.3b2"),
("1.2.3b1", "prerelease", "1.2.3b2"),
("1.2.3", "prerelease", "1.2.4a0"),
("0.0.0", "1.2.3", "1.2.3"),
],
)
def test_increment_version(
version: str, rule: str, expected: str, command: VersionCommand
):
if is_poetry_core_1_1_0a7_compat:
expected = expected.replace("a", "-alpha.").replace("b", "-beta.")
assert command.increment_version(version, rule).text == expected


Expand Down
10 changes: 2 additions & 8 deletions tests/utils/test_dependency_specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
import pytest

from deepdiff import DeepDiff
from poetry.core.semver.helpers import parse_constraint
from poetry.core.semver.version import Version

from poetry.utils._compat import metadata
from poetry.utils.dependency_specification import parse_dependency_specification
from tests.compat import is_poetry_core_1_1_0a7_compat


if TYPE_CHECKING:
Expand Down Expand Up @@ -78,11 +76,7 @@
"markers": 'python_version == "2.7"',
"url": "http://foo.com",
**(
{"extras": ["fred", "bar"]}
if parse_constraint(">1.1.0a7").allows(
Version.parse(metadata.version("poetry-core"))
)
else {}
{} if is_poetry_core_1_1_0a7_compat else {"extras": ["fred", "bar"]}
),
},
),
Expand Down