159 lines
6.8 KiB
Python
159 lines
6.8 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
from tools.checks.release_integration import (
|
|
SOURCE_COUPLED_CORE_TESTS,
|
|
InstalledModuleArtifact,
|
|
artifact_contract_issues,
|
|
filter_test_suite,
|
|
release_package_names,
|
|
run_module_release_tests,
|
|
)
|
|
|
|
|
|
def _named_test(test_id: str) -> unittest.TestCase:
|
|
class NamedTest(unittest.TestCase):
|
|
def id(self) -> str:
|
|
return test_id
|
|
|
|
def runTest(self) -> None:
|
|
return None
|
|
|
|
return NamedTest()
|
|
|
|
|
|
class ReleaseIntegrationTests(unittest.TestCase):
|
|
def test_release_requirement_parser_selects_only_immutable_module_refs(self) -> None:
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
requirements = Path(temp_dir) / "requirements-release.txt"
|
|
requirements.write_text(
|
|
"\n".join(
|
|
(
|
|
"../govoplan-core[server]",
|
|
"govoplan-idm @ git+ssh://git@example.test/GovOPlaN/govoplan-idm.git@v0.1.8",
|
|
"govoplan-campaign @ git+ssh://git@example.test/GovOPlaN/govoplan-campaign.git@v0.1.8",
|
|
"govoplan-idm @ git+ssh://git@example.test/GovOPlaN/govoplan-idm.git@v0.1.8",
|
|
"other-package==1.0",
|
|
)
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
self.assertEqual(
|
|
release_package_names(requirements),
|
|
("govoplan-idm", "govoplan-campaign"),
|
|
)
|
|
|
|
def test_artifact_contracts_compare_distribution_entry_point_and_discovery_versions(self) -> None:
|
|
artifacts = (
|
|
InstalledModuleArtifact("govoplan-access", "0.1.8", "access", "0.1.8"),
|
|
InstalledModuleArtifact("govoplan-idm", "0.1.8", "idm", "0.1.7"),
|
|
InstalledModuleArtifact("govoplan-shadow-idm", "0.1.8", "idm", "0.1.8"),
|
|
)
|
|
|
|
issues = artifact_contract_issues(
|
|
artifacts,
|
|
release_packages=("govoplan-access", "govoplan-idm", "govoplan-shadow-idm", "govoplan-campaign"),
|
|
available_manifest_versions={"access": "0.1.8", "idm": "0.1.6"},
|
|
)
|
|
|
|
self.assertEqual(len(issues), 5)
|
|
self.assertTrue(any("metadata version '0.1.8' does not match" in issue for issue in issues))
|
|
self.assertTrue(any("does not publish a govoplan.modules entry point" in issue for issue in issues))
|
|
self.assertTrue(any("multiple release packages" in issue for issue in issues))
|
|
|
|
def test_release_suite_excludes_only_named_source_coupled_tests(self) -> None:
|
|
retained_id = "tests.test_core_events.CoreEventTests.test_event_delivery"
|
|
nested = unittest.TestSuite(
|
|
(
|
|
unittest.TestSuite(_named_test(test_id) for test_id in SOURCE_COUPLED_CORE_TESTS),
|
|
unittest.TestSuite((_named_test(retained_id),)),
|
|
)
|
|
)
|
|
|
|
filtered, removed = filter_test_suite(nested, tuple(SOURCE_COUPLED_CORE_TESTS))
|
|
|
|
self.assertEqual(set(removed), set(SOURCE_COUPLED_CORE_TESTS))
|
|
self.assertEqual([test.id() for test in filtered], [retained_id])
|
|
self.assertEqual(len(SOURCE_COUPLED_CORE_TESTS), 4)
|
|
|
|
def test_release_entrypoint_uses_artifact_checks_and_filtered_core_suite(self) -> None:
|
|
meta_root = Path(__file__).resolve().parents[1]
|
|
script = (meta_root / "tools" / "checks" / "check-release-integration.sh").read_text(encoding="utf-8")
|
|
|
|
artifact_check = script.index('"$META_ROOT/tools/checks/release_integration.py" artifacts')
|
|
core_tests = script.index('"$META_ROOT/tools/checks/release_integration.py" core-tests')
|
|
module_tests = script.index('run_step "Run cloned module backend tests"')
|
|
|
|
self.assertLess(artifact_check, core_tests)
|
|
self.assertLess(core_tests, module_tests)
|
|
self.assertNotIn("unittest discover", script)
|
|
self.assertNotIn('"$PYTHON" -m unittest \\\n tests.test_module_system', script)
|
|
|
|
def test_tagged_module_runner_executes_pytest_functions_from_module_root(self) -> None:
|
|
with tempfile.TemporaryDirectory(prefix="govoplan-release-module-tests-") as temp_dir:
|
|
module_root = Path(temp_dir)
|
|
tests_root = module_root / "tests"
|
|
tests_root.mkdir()
|
|
marker = module_root / "pytest-function-ran"
|
|
(tests_root / "test_probe.py").write_text(
|
|
"""from pathlib import Path
|
|
import os
|
|
|
|
|
|
def test_pytest_style_function():
|
|
expected_root = Path(os.environ[\"GOVOPLAN_TEST_MODULE_ROOT\"])
|
|
assert Path.cwd() == expected_root
|
|
Path(os.environ[\"GOVOPLAN_TEST_MARKER\"]).write_text(\"ran\", encoding=\"utf-8\")
|
|
""",
|
|
encoding="utf-8",
|
|
)
|
|
with patch.dict(
|
|
os.environ,
|
|
{
|
|
"GOVOPLAN_TEST_MODULE_ROOT": str(module_root),
|
|
"GOVOPLAN_TEST_MARKER": str(marker),
|
|
},
|
|
):
|
|
status = run_module_release_tests(module_root)
|
|
|
|
self.assertEqual(status, 0)
|
|
self.assertEqual(marker.read_text(encoding="utf-8"), "ran")
|
|
|
|
def test_tagged_module_runner_skips_missing_test_tree(self) -> None:
|
|
with tempfile.TemporaryDirectory(prefix="govoplan-release-module-tests-") as temp_dir:
|
|
self.assertEqual(run_module_release_tests(Path(temp_dir)), 0)
|
|
|
|
def test_module_matrix_uses_artifact_aware_core_suite(self) -> None:
|
|
meta_root = Path(__file__).resolve().parents[1]
|
|
script = (meta_root / "tools" / "checks" / "check-module-matrix.sh").read_text(encoding="utf-8")
|
|
|
|
artifact_check = script.index('"$META_ROOT/tools/checks/release_integration.py" artifacts')
|
|
core_tests = script.index('"$META_ROOT/tools/checks/release_integration.py" core-tests')
|
|
|
|
self.assertLess(artifact_check, core_tests)
|
|
self.assertIn('--requirements "$META_ROOT/requirements-release.txt"', script)
|
|
self.assertIn('--core-root "$ROOT"', script)
|
|
self.assertNotIn('"$PYTHON" -m unittest tests.test_module_system', script)
|
|
|
|
def test_release_workflow_installs_tagged_source_test_harness(self) -> None:
|
|
meta_root = Path(__file__).resolve().parents[1]
|
|
workflow = (meta_root / ".gitea" / "workflows" / "release-integration.yml").read_text(encoding="utf-8")
|
|
requirements = (meta_root / "requirements-release-tests.txt").read_text(encoding="utf-8")
|
|
|
|
install = workflow.index("pip install -r requirements-release-tests.txt")
|
|
checks = workflow.index("bash tools/checks/check-release-integration.sh")
|
|
|
|
self.assertLess(install, checks)
|
|
self.assertIn("pytest>=9.0.3,<10", requirements)
|
|
self.assertNotIn("requirements-release-tests.txt", (meta_root / "requirements-release.txt").read_text(encoding="utf-8"))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|