62 lines
1.8 KiB
Python
62 lines
1.8 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_doc_code_sync",
|
|
REPO_ROOT / "scripts" / "check_doc_code_sync.py",
|
|
)
|
|
|
|
|
|
class DocCodeSyncAssessmentTests(unittest.TestCase):
|
|
def test_classifies_python_scripts_as_code(self):
|
|
self.assertEqual(MODULE.classify("scripts/check_doc_code_sync.py"), "code")
|
|
|
|
def test_classifies_app_paths_as_code(self):
|
|
self.assertEqual(MODULE.classify("apps/web/package.json"), "code")
|
|
|
|
def test_classifies_env_example_as_config(self):
|
|
self.assertEqual(MODULE.classify(".env.example"), "config")
|
|
|
|
def test_extract_status_paths_preserves_first_character(self):
|
|
self.assertEqual(
|
|
MODULE.extract_status_paths([" M apps/api/package.json"]),
|
|
["apps/api/package.json"],
|
|
)
|
|
|
|
def test_strict_mode_blocks_code_without_doc_updates(self):
|
|
assessment = MODULE.assess_changes(
|
|
docs=[],
|
|
code=["src/app.ts"],
|
|
tests=[],
|
|
config=[],
|
|
other=[],
|
|
strict=True,
|
|
)
|
|
self.assertTrue(assessment["blocking"])
|
|
|
|
def test_doc_and_code_changes_together_do_not_block(self):
|
|
assessment = MODULE.assess_changes(
|
|
docs=["design/02-architecture/system-architecture.md"],
|
|
code=["src/app.ts"],
|
|
tests=[],
|
|
config=[],
|
|
other=[],
|
|
strict=True,
|
|
)
|
|
self.assertFalse(assessment["blocking"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|