From c6ef8404513f7f52e7d728e257733bed020cd8fa Mon Sep 17 00:00:00 2001 From: Stefan Tolksdorf Date: Thu, 28 Sep 2023 11:06:43 +0200 Subject: [PATCH] Add test for get_current_version --- pontos/version/commands/_java.py | 12 ++++++------ tests/version/commands/test_java.py | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/pontos/version/commands/_java.py b/pontos/version/commands/_java.py index 0c42b141d..f3dc1de4a 100644 --- a/pontos/version/commands/_java.py +++ b/pontos/version/commands/_java.py @@ -85,7 +85,7 @@ def _update_version_files(self, new_version) -> List[Path]: changed_files: List[Path] = [] for file_config in config["files"]: file_path = file_config["path"] - with open(Path.cwd() / file_path, "r") as input_file_handle: + with (Path.cwd() / file_path).open("r") as input_file_handle: lines = input_file_handle.readlines() line_number = file_config["line"] version_line = lines[line_number - 1] @@ -110,7 +110,7 @@ def _update_version_files(self, new_version) -> List[Path]: changed_files.append(Path(file_config["path"])) return changed_files - def _load_config(self) -> Dict: + def _load_config(self) -> Dict[str, Any]: version_config_file = Path.cwd() / "upgradeVersion.json" if not version_config_file.exists(): raise VersionError( @@ -118,12 +118,12 @@ def _load_config(self) -> Dict: "This file is required for pontos" ) - with open(version_config_file, "r") as f: + with version_config_file.open("r") as f: json_string = f.read() config = json.loads(json_string) return config - def _read_versions_from_files(self) -> Dict: + def _read_versions_from_files(self) -> Dict[str, str]: config = self._load_config() file_versions = {} @@ -133,7 +133,7 @@ def _read_versions_from_files(self) -> Dict: if not file.exists(): raise VersionError(f"No {file} file found.") - with open(file, "r") as f: + with file.open("r") as f: line_number = file_config["line"] readlines = f.readlines() if line_number - 1 > len(readlines): @@ -154,7 +154,7 @@ def _read_versions_from_files(self) -> Dict: file_versions[file_path] = matches.group("version") return file_versions - def _verify_version(self, file_versions: Dict) -> str: + def _verify_version(self, file_versions: Dict[str, str]) -> str: last_version = "" last_file_name = "" for file_name, version in file_versions.items(): diff --git a/tests/version/commands/test_java.py b/tests/version/commands/test_java.py index da0a08291..6bd5a867f 100644 --- a/tests/version/commands/test_java.py +++ b/tests/version/commands/test_java.py @@ -28,6 +28,10 @@ { "path": "README.md", "line": 3 + }, + { + "path": "src/application.properties", + "line": 2 } ] } @@ -52,6 +56,10 @@ ## starting the local """ +TEMPLATE_UPGRADE_VERSION_WITH_VERSION_PROPERTIES = """# application +sentry.release={} +server.port=8080 +""" class GetCurrentJavaVersionCommandTestCase(unittest.TestCase): def test_getting_version(self): @@ -122,6 +130,11 @@ def test_verify_version(self): TEMPLATE_UPGRADE_VERSION_MARKDOWN.format(version), encoding="utf-8", ) + properties_file_path = Path("src/application.properties") + properties_file_path.write_text( + TEMPLATE_UPGRADE_VERSION_WITH_VERSION_PROPERTIES.format(version), + encoding="latin-1", + ) JavaVersionCommand(SemanticVersioningScheme).verify_version( SemanticVersioningScheme.parse_version(version) @@ -129,6 +142,7 @@ def test_verify_version(self): version_file_path.unlink() readme_file_path.unlink() + properties_file_path.unlink() def test_verify_version_does_not_match(self): exp_err_msg = (