Skip to content

Commit

Permalink
tests: make tests compatible with core > 1.1.0a7
Browse files Browse the repository at this point in the history
  • Loading branch information
radoering committed May 10, 2022
1 parent f19d137 commit 8743a71
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
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

0 comments on commit 8743a71

Please sign in to comment.