Skip to content

Commit

Permalink
test(algorithm): adjust unit tests of increment_version logic
Browse files Browse the repository at this point in the history
This clarifies repeated function calls and pytest parameter names included
the unclear assert diff.  Adds additional tests to check bad states for failures
and refactored to match new function signature.
  • Loading branch information
codejedi365 committed Apr 20, 2024
1 parent ba3e326 commit 15796ae
Showing 1 changed file with 73 additions and 41 deletions.
114 changes: 73 additions & 41 deletions tests/unit/semantic_release/version/test_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def test_sorted_repo_tags_and_versions(tags, sorted_tags):
translator = VersionTranslator()
tagrefs = [repo.tag(tag) for tag in tags]
actual = [t.name for t, _ in tags_and_versions(tagrefs, translator)]
assert actual == sorted_tags
assert sorted_tags == actual


@pytest.mark.parametrize(
Expand Down Expand Up @@ -184,35 +184,26 @@ def test_tags_and_versions_ignores_invalid_tags_as_versions(
translator = VersionTranslator(tag_format=tag_format)
tagrefs = [repo.tag(tag) for tag in (*valid_tags, *invalid_tags)]
actual = [t.name for t, _ in tags_and_versions(tagrefs, translator)]
assert set(actual) == set(valid_tags)
assert set(valid_tags) == set(actual)


@pytest.mark.parametrize(
"latest_version, latest_full_version, latest_full_version_in_history, level_bump, "
"latest_version, latest_full_version_in_history, level_bump, "
"prerelease, prerelease_token, expected_version",
[
# NOTE: level_bump != LevelBump.NO_RELEASE, we return early in the
# algorithm to discount this case
# NOTE: you can only perform a PRERELEASE_REVISION bump on a previously
# prerelease version and if you are requesting a prerelease
(
"1.0.0",
"1.0.0",
"1.0.0",
LevelBump.PRERELEASE_REVISION,
False,
"rc",
"1.0.0-rc.1",
),
(
"1.0.0",
"1.0.0",
"1.0.1-rc.1",
"1.0.0",
LevelBump.PRERELEASE_REVISION,
True,
"rc",
"1.0.0-rc.1",
"1.0.1-rc.2",
),
(
"1.0.0",
"1.0.0",
"1.0.0",
LevelBump.PATCH,
Expand All @@ -221,7 +212,6 @@ def test_tags_and_versions_ignores_invalid_tags_as_versions(
"1.0.1",
),
(
"1.0.0",
"1.0.0",
"1.0.0",
LevelBump.PATCH,
Expand All @@ -230,7 +220,6 @@ def test_tags_and_versions_ignores_invalid_tags_as_versions(
"1.0.1-rc.1",
),
(
"1.0.0",
"1.0.0",
"1.0.0",
LevelBump.MINOR,
Expand All @@ -239,7 +228,6 @@ def test_tags_and_versions_ignores_invalid_tags_as_versions(
"1.1.0",
),
(
"1.0.0",
"1.0.0",
"1.0.0",
LevelBump.MINOR,
Expand All @@ -248,7 +236,6 @@ def test_tags_and_versions_ignores_invalid_tags_as_versions(
"1.1.0-rc.1",
),
(
"1.0.0",
"1.0.0",
"1.0.0",
LevelBump.MAJOR,
Expand All @@ -257,7 +244,6 @@ def test_tags_and_versions_ignores_invalid_tags_as_versions(
"2.0.0",
),
(
"1.0.0",
"1.0.0",
"1.0.0",
LevelBump.MAJOR,
Expand All @@ -267,16 +253,14 @@ def test_tags_and_versions_ignores_invalid_tags_as_versions(
),
(
"1.2.4-rc.1",
"1.2.0",
"1.2.3",
LevelBump.PATCH,
False,
LevelBump.PRERELEASE_REVISION,
True,
"rc",
"1.2.4",
"1.2.4-rc.2",
),
(
"1.2.4-rc.1",
"1.2.0",
"1.2.3",
LevelBump.PATCH,
True,
Expand All @@ -285,7 +269,14 @@ def test_tags_and_versions_ignores_invalid_tags_as_versions(
),
(
"1.2.4-rc.1",
"1.2.0",
"1.2.3",
LevelBump.PATCH,
False,
"rc",
"1.2.4",
),
(
"1.2.4-rc.1",
"1.2.3",
LevelBump.MINOR,
False,
Expand All @@ -294,7 +285,6 @@ def test_tags_and_versions_ignores_invalid_tags_as_versions(
),
(
"1.2.4-rc.1",
"1.2.0",
"1.2.3",
LevelBump.MINOR,
True,
Expand All @@ -303,7 +293,6 @@ def test_tags_and_versions_ignores_invalid_tags_as_versions(
),
(
"1.2.4-rc.1",
"1.2.0",
"1.2.3",
LevelBump.MAJOR,
False,
Expand All @@ -312,7 +301,6 @@ def test_tags_and_versions_ignores_invalid_tags_as_versions(
),
(
"1.2.4-rc.1",
"1.2.0",
"1.2.3",
LevelBump.MAJOR,
True,
Expand All @@ -321,16 +309,14 @@ def test_tags_and_versions_ignores_invalid_tags_as_versions(
),
(
"2.0.0-rc.1",
"1.22.0",
"1.19.3",
LevelBump.PATCH,
False,
LevelBump.PRERELEASE_REVISION,
True,
"rc",
"2.0.0",
"2.0.0-rc.2",
),
(
"2.0.0-rc.1",
"1.22.0",
"1.19.3",
LevelBump.PATCH,
True,
Expand All @@ -339,7 +325,14 @@ def test_tags_and_versions_ignores_invalid_tags_as_versions(
),
(
"2.0.0-rc.1",
"1.22.0",
"1.19.3",
LevelBump.PATCH,
False,
"rc",
"2.0.0",
),
(
"2.0.0-rc.1",
"1.19.3",
LevelBump.MINOR,
False,
Expand All @@ -348,7 +341,6 @@ def test_tags_and_versions_ignores_invalid_tags_as_versions(
),
(
"2.0.0-rc.1",
"1.22.0",
"1.19.3",
LevelBump.MINOR,
True,
Expand All @@ -357,7 +349,6 @@ def test_tags_and_versions_ignores_invalid_tags_as_versions(
),
(
"2.0.0-rc.1",
"1.22.0",
"1.19.3",
LevelBump.MAJOR,
False,
Expand All @@ -366,7 +357,6 @@ def test_tags_and_versions_ignores_invalid_tags_as_versions(
),
(
"2.0.0-rc.1",
"1.22.0",
"1.19.3",
LevelBump.MAJOR,
True,
Expand All @@ -377,7 +367,6 @@ def test_tags_and_versions_ignores_invalid_tags_as_versions(
)
def test_increment_version_no_major_on_zero(
latest_version: str,
latest_full_version: str,
latest_full_version_in_history: str,
level_bump: LevelBump,
prerelease: bool,
Expand All @@ -386,7 +375,6 @@ def test_increment_version_no_major_on_zero(
):
actual = _increment_version(
latest_version=Version.parse(latest_version),
latest_full_version=Version.parse(latest_full_version),
latest_full_version_in_history=Version.parse(latest_full_version_in_history),
level_bump=level_bump,
prerelease=prerelease,
Expand All @@ -395,3 +383,47 @@ def test_increment_version_no_major_on_zero(
allow_zero_version=True,
)
assert expected_version == str(actual)


@pytest.mark.parametrize(
"latest_version, latest_full_version_in_history, level_bump, prerelease, prerelease_token",
[
# NOTE: level_bump != LevelBump.NO_RELEASE, we return early in the
# algorithm to discount this case
# NOTE: you can only perform a PRERELEASE_REVISION bump on a previously
# prerelease version and if you are requesting a prerelease
(
"1.0.0",
"1.0.0",
LevelBump.PRERELEASE_REVISION,
False,
"rc",
),
(
"1.0.0",
"1.0.0",
LevelBump.PRERELEASE_REVISION,
True,
"rc",
),
],
)
def test_increment_version_invalid_operation(
latest_version: str,
latest_full_version_in_history: str,
level_bump: LevelBump,
prerelease: bool,
prerelease_token: str,
):
with pytest.raises(ValueError):
_increment_version(
latest_version=Version.parse(latest_version),
latest_full_version_in_history=Version.parse(
latest_full_version_in_history
),
level_bump=level_bump,
prerelease=prerelease,
prerelease_token=prerelease_token,
major_on_zero=False,
allow_zero_version=True,
)

0 comments on commit 15796ae

Please sign in to comment.