Skip to content

Commit

Permalink
Add: Add support for pontos-version verify current to Go and CMake …
Browse files Browse the repository at this point in the history
…projects

Extend and test verify current for go and cmake bases projects.
  • Loading branch information
bjoernricks committed Mar 3, 2023
1 parent edf9bfa commit ed61a34
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
7 changes: 7 additions & 0 deletions pontos/version/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,20 @@ def update_version(
)

def get_current_version(self) -> Version:
if not self.project_file_path.exists():
raise VersionError(f"{self.project_file_path} not found.")

content = self.project_file_path.read_text(encoding="utf-8")
return CMakeVersionParser(content).get_current_version()

def verify_version(
self, version: Union[Literal["current"], Version]
) -> None:
current_version = self.get_current_version()

if version == "current":
return

if current_version != version:
raise VersionError(
f"Provided version {version} does not match the "
Expand Down
4 changes: 4 additions & 0 deletions pontos/version/go.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ def verify_version(
) -> None:
"""Verify the current version of this project"""
current_version = self.get_current_version()

if version == "current":
return

if current_version != version:
raise VersionError(
f"Provided version {version} does not match the "
Expand Down
15 changes: 13 additions & 2 deletions tests/version/test_cmake_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@


class VerifyCMakeVersionCommandTestCase(unittest.TestCase):
def test_verify_version(self):
def test_verify_failure(self):
with temp_file(
"project(VERSION 1.2.3)\n" "set(PROJECT_DEV_VERSION 0)",
"project(VERSION 1.2.3)\nset(PROJECT_DEV_VERSION 0)",
name="CMakeLists.txt",
change_into=True,
):
Expand All @@ -43,6 +43,17 @@ def test_verify_version(self):
):
cmake.verify_version(Version("2.3.4"))

def test_verify_current(self):
with temp_directory(
change_into=True,
):
cmake = CMakeVersionCommand()

with self.assertRaisesRegex(
VersionError, "^.*CMakeLists.txt not found."
):
cmake.verify_version("current")


class GetCurrentCMakeVersionCommandTestCase(unittest.TestCase):
@patch(
Expand Down
23 changes: 23 additions & 0 deletions tests/version/test_go_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,29 @@ def test_verify_branch_not_equal(self):
cmd = GoVersionCommand()
cmd.verify_version(Version("21.2"))

def test_verify_current(self):
with temp_file(
name="go.mod",
change_into=True,
), patch.object(
GoVersionCommand,
"get_current_version",
MagicMock(return_value=Version("21.0.1")),
):
cmd = GoVersionCommand()
cmd.verify_version("current")

def test_verify_current_failure(self):
with temp_file(
name="go.mod",
change_into=True,
), self.assertRaisesRegex(
VersionError,
"^No version.go file found. This file is required for pontos",
):
cmd = GoVersionCommand()
cmd.verify_version("current")


class UpdateGoVersionCommandTestCase(unittest.TestCase):
def test_no_file_but_tag_update_version(self):
Expand Down

0 comments on commit ed61a34

Please sign in to comment.