105 lines
4.4 KiB
Python
105 lines
4.4 KiB
Python
from __future__ import annotations
|
|
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from tools.checks.release_integration import (
|
|
SOURCE_COUPLED_CORE_TESTS,
|
|
InstalledModuleArtifact,
|
|
artifact_contract_issues,
|
|
filter_test_suite,
|
|
release_package_names,
|
|
)
|
|
|
|
|
|
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/add-ideas/govoplan-idm.git@v0.1.8",
|
|
"govoplan-campaign @ git+ssh://git@example.test/add-ideas/govoplan-campaign.git@v0.1.8",
|
|
"govoplan-idm @ git+ssh://git@example.test/add-ideas/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('"$PYTHON" -m unittest \\\n tests.test_module_system', script)
|
|
|
|
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")
|
|
|
|
self.assertIn('"$META_ROOT/tools/checks/release_integration.py" core-tests', script)
|
|
self.assertIn('--core-root "$ROOT"', script)
|
|
self.assertNotIn('"$PYTHON" -m unittest tests.test_module_system', script)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|