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 7b79f15
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
14 changes: 12 additions & 2 deletions tests/console/commands/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

import pytest

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

from poetry.repositories.legacy_repository import LegacyRepository
from poetry.utils._compat import metadata
from tests.helpers import get_dependency
from tests.helpers import get_package

Expand Down Expand Up @@ -981,7 +983,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 +994,10 @@ def test_add_chooses_prerelease_if_only_prereleases_are_available(
• Installing foo (1.2.3b1)
"""
if not parse_constraint(">1.1.0a7").allows(
Version.parse(metadata.version("poetry-core"))
):
expected = expected.replace("^1.2.3b1", "^1.2.3-beta.1")

assert expected in tester.io.fetch_output()

Expand Down Expand Up @@ -1912,7 +1918,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 +1929,10 @@ def test_add_chooses_prerelease_if_only_prereleases_are_available_old_installer(
- Installing foo (1.2.3b1)
"""
if not parse_constraint(">1.1.0a7").allows(
Version.parse(metadata.version("poetry-core"))
):
expected = expected.replace("^1.2.3b1", "^1.2.3-beta.1")

assert expected in old_tester.io.fetch_output()

Expand Down
24 changes: 16 additions & 8 deletions tests/console/commands/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

import pytest

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

from poetry.console.commands.version import VersionCommand
from poetry.utils._compat import metadata


if TYPE_CHECKING:
Expand Down Expand Up @@ -35,23 +39,27 @@ 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 not parse_constraint(">1.1.0a7").allows(
Version.parse(metadata.version("poetry-core"))
):
expected = expected.replace("a", "-alpha.").replace("b", "-beta.")
assert command.increment_version(version, rule).text == expected


Expand Down

0 comments on commit 7b79f15

Please sign in to comment.