Skip to content

Commit

Permalink
Add test for get_current_version
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanTolksdorf committed Sep 28, 2023
1 parent 157d818 commit c6ef840
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pontos/version/commands/_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -110,20 +110,20 @@ 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(
f"No {version_config_file} config file found. "
"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 = {}
Expand All @@ -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):
Expand All @@ -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():
Expand Down
14 changes: 14 additions & 0 deletions tests/version/commands/test_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
{
"path": "README.md",
"line": 3
},
{
"path": "src/application.properties",
"line": 2
}
]
}
Expand All @@ -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):
Expand Down Expand Up @@ -122,13 +130,19 @@ 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)
)

version_file_path.unlink()
readme_file_path.unlink()
properties_file_path.unlink()

def test_verify_version_does_not_match(self):
exp_err_msg = (
Expand Down

0 comments on commit c6ef840

Please sign in to comment.