| 5 |
| from release_caption import ( |
| 6 | CAPTION_BUDGET, |
| 7 | is_changelog_ignored, |
| 8 | read_apk_version, |
| 9 | read_gradle_property, |
| 10 | render_test_caption, |
| 11 | ) |
| 12 |
| 13 |
| 14 | class ReleaseCaptionTest(unittest.TestCase): |
| 15 | def test_renders_conventional_commit_with_link_and_escaping(self): |
| 16 | caption = render_test_caption( |
| 17 | "feat(ci): improve <test> notification", |
| 18 | "12.9.0", |
| 19 | "1241", |
| 20 | "abcdef123456", |
| 21 | "https://github.com/NextAlone/Nagram", |
| 22 | ) |
| 23 |
| 24 | self.assertIn( |
| 25 | "🧪 <b>Nagram</b> <code>12.9.0</code> <i>(1241)</i> · <b>Test Version</b>", |
| 26 | caption, |
| 27 | ) |
| 28 | self.assertIn("✨ <b>Features</b>", caption) |
| 29 | self.assertIn( |
| 30 | '<a href="https://github.com/NextAlone/Nagram/commit/abcdef123456">[abcdef1]</a>', |
| 31 | caption, |
| 32 | ) |
| 33 | self.assertIn("improve <test> notification", caption) |
| 34 |
| 35 | def test_uses_merge_and_other_groups_and_stays_within_caption_budget(self): |
| 36 | merge_caption = render_test_caption("Merge branch 'main'", "test", "1") |
| 37 | caption = render_test_caption("release " + "<&>" * 1000, "test", "1") |
| 38 |
| 39 | self.assertIn("🔀 <b>Merge</b>", merge_caption) |
| 40 | self.assertIn("📌 <b>Other</b>", caption) |
| 41 | self.assertLessEqual(len(caption), CAPTION_BUDGET) |
| 42 | self.assertTrue(caption.endswith("…")) |
| 43 |
| 44 | def test_omits_commit_marked_ignore_from_changelog(self): |
| 45 | commit_message = "chore: regenerate artifacts\n\ninternal only [ignore]" |
| 46 | caption = render_test_caption( |
| 47 | commit_message, |
| 48 | "12.9.0", |
| 49 | "1241", |
| 50 | "abcdef123456", |
| 51 | "https://github.com/NextAlone/Nagram", |
| 52 | ) |
| 53 |
| 54 | self.assertTrue(is_changelog_ignored(commit_message)) |
| 55 | self.assertEqual( |
| 56 | "🧪 <b>Nagram</b> <code>12.9.0</code> <i>(1241)</i> · <b>Test Version</b>", |
| 57 | caption, |
| 58 | ) |
| 59 |
| 60 | def test_reads_gradle_property(self): |
| 61 | with TemporaryDirectory() as directory: |
| 62 | path = Path(directory) / "gradle.properties" |
| 63 | path.write_text("APP_VERSION_NAME=12.9.0\n", encoding="utf-8") |
| 64 |
| 65 | self.assertEqual("12.9.0", read_gradle_property("APP_VERSION_NAME", path)) |
| 66 | self.assertEqual("Unknown", read_gradle_property("APP_VERSION_CODE", path)) |
| 67 |
| 68 | def test_reads_actual_nagram_version_from_apk_filename(self): |
| 69 | path = Path("Nagram-v12.9.0(1241)-arm64-v8a.apk") |
| 70 |
| 71 | self.assertEqual(("12.9.0", 1241), read_apk_version(path)) |
| 72 |
| 73 | with self.assertRaisesRegex(ValueError, "Cannot read version"): |
| 74 | read_apk_version(Path("app.apk")) |
| 75 |
| 76 |
| 77 | if __name__ == "__main__": |
| 78 | unittest.main() |
| 79 |