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 27, 2023
1 parent 22cee71 commit 20e6ac3
Showing 1 changed file with 51 additions and 17 deletions.
68 changes: 51 additions & 17 deletions tests/version/commands/test_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def test_getting_version(self):
version = "2023.9.3"
readme_file_path = Path("README.md")
readme_file_path.write_text(
TEMPLATE_UPGRADE_VERSION_MARKDOWN.format(version), encoding="utf-8"
TEMPLATE_UPGRADE_VERSION_MARKDOWN.format(version),
encoding="utf-8"
)

result_version = JavaVersionCommand(
Expand All @@ -77,7 +78,8 @@ def test_verify_version(self):
version = "2023.9.3"
readme_file_path = Path("README.md")
readme_file_path.write_text(
TEMPLATE_UPGRADE_VERSION_MARKDOWN.format(version), encoding="utf-8"
TEMPLATE_UPGRADE_VERSION_MARKDOWN.format(version),
encoding="utf-8"
)

JavaVersionCommand(
Expand All @@ -93,56 +95,80 @@ def test_update_version(self):
with temp_directory(change_into=True):
version_file_path = Path("upgradeVersion.json")
version_file_path.write_text(
TEMPLATE_UPGRADE_VERSION_JSON, encoding="utf-8"
TEMPLATE_UPGRADE_VERSION_JSON,
encoding="utf-8"
)

version = "2023.9.3"
readme_file_path = Path("README.md")
readme_file_path.write_text(
TEMPLATE_UPGRADE_VERSION_MARKDOWN.format(version), encoding="utf-8"
TEMPLATE_UPGRADE_VERSION_MARKDOWN.format(version),
encoding="utf-8"
)

new_version = "2023.9.4"
updated_version_obj = JavaVersionCommand(
SemanticVersioningScheme
).update_version(SemanticVersioningScheme.parse_version(new_version))

self.assertEqual(updated_version_obj.previous, SemanticVersioningScheme.parse_version(version))
self.assertEqual(updated_version_obj.new, SemanticVersioningScheme.parse_version(new_version))
self.assertEqual(
updated_version_obj.previous,
SemanticVersioningScheme.parse_version(version)
)
self.assertEqual(
updated_version_obj.new,
SemanticVersioningScheme.parse_version(new_version)
)
self.assertEqual(
updated_version_obj.changed_files, [Path("README.md")]
)

content = readme_file_path.read_text(encoding="UTF-8")
self.assertEqual(content, TEMPLATE_UPGRADE_VERSION_MARKDOWN.format(new_version))
self.assertEqual(
content,
TEMPLATE_UPGRADE_VERSION_MARKDOWN.format(new_version)
)

version_file_path.unlink()
readme_file_path.unlink()

def test_no_update_version(self):
with temp_directory(change_into=True):
version_file_path = Path("upgradeVersion.json")
version_file_path.write_text(
TEMPLATE_UPGRADE_VERSION_JSON, encoding="utf-8"
TEMPLATE_UPGRADE_VERSION_JSON,
encoding="utf-8"
)

version = "2023.9.3"
readme_file_path = Path("README.md")
readme_file_path.write_text(
TEMPLATE_UPGRADE_VERSION_MARKDOWN.format(version), encoding="utf-8"
TEMPLATE_UPGRADE_VERSION_MARKDOWN.format(version),
encoding="utf-8"
)

updated_version_obj = JavaVersionCommand(
SemanticVersioningScheme
).update_version(SemanticVersioningScheme.parse_version(version))

self.assertEqual(updated_version_obj.previous, SemanticVersioningScheme.parse_version(version))
self.assertEqual(updated_version_obj.new, SemanticVersioningScheme.parse_version(version))
self.assertEqual(
updated_version_obj.changed_files, []
updated_version_obj.previous,
SemanticVersioningScheme.parse_version(version)
)
self.assertEqual(
updated_version_obj.new,
SemanticVersioningScheme.parse_version(version)
)
self.assertEqual(
updated_version_obj.changed_files,
[]
)

content = readme_file_path.read_text(encoding="UTF-8")
self.assertEqual(content, TEMPLATE_UPGRADE_VERSION_MARKDOWN.format(version))
self.assertEqual(
content,
TEMPLATE_UPGRADE_VERSION_MARKDOWN.format(version)
)

version_file_path.unlink()
readme_file_path.unlink()
Expand All @@ -151,21 +177,29 @@ def test_forced_update_version(self):
with temp_directory(change_into=True):
version_file_path = Path("upgradeVersion.json")
version_file_path.write_text(
TEMPLATE_UPGRADE_VERSION_JSON, encoding="utf-8"
TEMPLATE_UPGRADE_VERSION_JSON,
encoding="utf-8"
)

version = "2023.9.3"
readme_file_path = Path("README.md")
readme_file_path.write_text(
TEMPLATE_UPGRADE_VERSION_MARKDOWN.format(version), encoding="utf-8"
TEMPLATE_UPGRADE_VERSION_MARKDOWN.format(version),
encoding="utf-8"
)

updated_version_obj = JavaVersionCommand(
SemanticVersioningScheme
).update_version(SemanticVersioningScheme.parse_version(version), force=True)

self.assertEqual(updated_version_obj.previous, SemanticVersioningScheme.parse_version(version))
self.assertEqual(updated_version_obj.new, SemanticVersioningScheme.parse_version(version))
self.assertEqual(
updated_version_obj.previous,
SemanticVersioningScheme.parse_version(version)
)
self.assertEqual(
updated_version_obj.new,
SemanticVersioningScheme.parse_version(version)
)
self.assertEqual(
updated_version_obj.changed_files, [Path("README.md")]
)
Expand Down

0 comments on commit 20e6ac3

Please sign in to comment.