| 5 |
| from release_caption import CAPTION_BUDGET, read_gradle_property, render_test_caption |
| 6 |
| 7 |
| 8 | class ReleaseCaptionTest(unittest.TestCase): |
| 9 | def test_renders_conventional_commit_with_link_and_escaping(self): |
| 10 | caption = render_test_caption( |
| 11 | "feat(ci): improve <test> notification", |
| 12 | "12.9.0", |
| 13 | "6966", |
| 14 | "abcdef123456", |
| 15 | "https://github.com/NextAlone/Nagram", |
| 16 | ) |
| 17 |
| 18 | self.assertIn( |
| 19 | "🧪 <b>Nagram Test</b> <code>12.9.0</code> <i>(6966)</i>", caption |
| 20 | ) |
| 21 | self.assertIn("✨ <b>Features</b>", caption) |
| 22 | self.assertIn( |
| 23 | '<a href="https://github.com/NextAlone/Nagram/commit/abcdef123456">[abcdef1]</a>', |
| 24 | caption, |
| 25 | ) |
| 26 | self.assertIn("improve <test> notification", caption) |
| 27 |
| 28 | def test_uses_merge_and_other_groups_and_stays_within_caption_budget(self): |
| 29 | merge_caption = render_test_caption("Merge branch 'main'", "test", "1") |
| 30 | caption = render_test_caption("release " + "<&>" * 1000, "test", "1") |
| 31 |
| 32 | self.assertIn("🔀 <b>Merge</b>", merge_caption) |
| 33 | self.assertIn("📌 <b>Other</b>", caption) |
| 34 | self.assertLessEqual(len(caption), CAPTION_BUDGET) |
| 35 | self.assertTrue(caption.endswith("…")) |
| 36 |
| 37 | def test_reads_gradle_property(self): |
| 38 | with TemporaryDirectory() as directory: |
| 39 | path = Path(directory) / "gradle.properties" |
| 40 | path.write_text("APP_VERSION_NAME=12.9.0\n", encoding="utf-8") |
| 41 |
| 42 | self.assertEqual("12.9.0", read_gradle_property("APP_VERSION_NAME", path)) |
| 43 | self.assertEqual("Unknown", read_gradle_property("APP_VERSION_CODE", path)) |
| 44 |
| 45 |
| 46 | if __name__ == "__main__": |
| 47 | unittest.main() |
| 48 |