|
| 1 | +from pathlib import Path |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +pytestmark = pytest.mark.architecture |
| 6 | + |
| 7 | + |
| 8 | +EXPECTED_EXTENSION_DEFAULT_CONSTANT_CONSUMERS = ( |
| 9 | + "hyperbrowser/client/managers/async_manager/extension.py", |
| 10 | + "hyperbrowser/client/managers/extension_create_utils.py", |
| 11 | + "hyperbrowser/client/managers/extension_operation_metadata.py", |
| 12 | + "hyperbrowser/client/managers/sync_manager/extension.py", |
| 13 | + "tests/test_extension_create_metadata_usage.py", |
| 14 | + "tests/test_extension_operation_metadata.py", |
| 15 | + "tests/test_extension_operation_metadata_usage.py", |
| 16 | + "tests/test_file_message_default_constant_import_boundary.py", |
| 17 | + "tests/test_file_message_default_constant_usage.py", |
| 18 | +) |
| 19 | + |
| 20 | +EXPECTED_SESSION_DEFAULT_CONSTANT_CONSUMERS = ( |
| 21 | + "hyperbrowser/client/managers/session_operation_metadata.py", |
| 22 | + "hyperbrowser/client/managers/session_upload_utils.py", |
| 23 | + "tests/test_file_message_default_constant_import_boundary.py", |
| 24 | + "tests/test_file_message_default_constant_usage.py", |
| 25 | + "tests/test_session_operation_metadata.py", |
| 26 | + "tests/test_session_upload_metadata_usage.py", |
| 27 | +) |
| 28 | + |
| 29 | + |
| 30 | +def _discover_modules_with_text(fragment: str) -> list[str]: |
| 31 | + discovered_modules: list[str] = [] |
| 32 | + for module_path in sorted(Path("hyperbrowser").rglob("*.py")): |
| 33 | + module_text = module_path.read_text(encoding="utf-8") |
| 34 | + if fragment not in module_text: |
| 35 | + continue |
| 36 | + discovered_modules.append(module_path.as_posix()) |
| 37 | + for module_path in sorted(Path("tests").glob("test_*.py")): |
| 38 | + module_text = module_path.read_text(encoding="utf-8") |
| 39 | + if fragment not in module_text: |
| 40 | + continue |
| 41 | + discovered_modules.append(module_path.as_posix()) |
| 42 | + return discovered_modules |
| 43 | + |
| 44 | + |
| 45 | +def test_extension_default_message_constants_are_centralized(): |
| 46 | + discovered_modules = _discover_modules_with_text("EXTENSION_DEFAULT_") |
| 47 | + assert discovered_modules == list(EXPECTED_EXTENSION_DEFAULT_CONSTANT_CONSUMERS) |
| 48 | + |
| 49 | + |
| 50 | +def test_session_default_message_constants_are_centralized(): |
| 51 | + discovered_modules = _discover_modules_with_text("SESSION_DEFAULT_UPLOAD_") |
| 52 | + assert discovered_modules == list(EXPECTED_SESSION_DEFAULT_CONSTANT_CONSUMERS) |
0 commit comments