41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
import importlib.util
|
|
from pathlib import Path
|
|
import unittest
|
|
|
|
|
|
def load_module(module_name: str, path: Path):
|
|
spec = importlib.util.spec_from_file_location(module_name, path)
|
|
module = importlib.util.module_from_spec(spec)
|
|
assert spec.loader is not None
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parents[1]
|
|
MODULE = load_module(
|
|
"check_commit_message",
|
|
REPO_ROOT / "scripts" / "check_commit_message.py",
|
|
)
|
|
|
|
|
|
class CommitMessageValidationTests(unittest.TestCase):
|
|
def test_accepts_gitmoji_shortcode_with_english_message(self):
|
|
errors = MODULE.validate_message(":sparkles: add local hook templates")
|
|
self.assertEqual(errors, [])
|
|
|
|
def test_accepts_unicode_gitmoji_with_english_message(self):
|
|
errors = MODULE.validate_message("✨ add ci validation for hooks")
|
|
self.assertEqual(errors, [])
|
|
|
|
def test_rejects_message_without_gitmoji_prefix(self):
|
|
errors = MODULE.validate_message("add local hook templates")
|
|
self.assertTrue(any("gitmoji" in error.lower() for error in errors))
|
|
|
|
def test_rejects_non_english_message(self):
|
|
errors = MODULE.validate_message(":sparkles: 添加本地 hook")
|
|
self.assertTrue(any("english" in error.lower() for error in errors))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|