|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import os |
| 4 | +import sys |
| 5 | +import zipfile |
| 6 | +from pathlib import Path |
| 7 | + |
| 8 | +import pytest |
| 9 | + |
| 10 | + |
| 11 | +sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) |
| 12 | + |
| 13 | +from check_otel_wheel_dependencies import check_otel_wheel_dependencies |
| 14 | + |
| 15 | + |
| 16 | +def _write_wheel(tmp_path: Path, requirements: tuple[str, ...]) -> Path: |
| 17 | + wheel = tmp_path / "aws_durable_execution_sdk_python_otel-1.0.0-py3-none-any.whl" |
| 18 | + metadata = [ |
| 19 | + "Metadata-Version: 2.4", |
| 20 | + "Name: aws-durable-execution-sdk-python-otel", |
| 21 | + "Version: 1.0.0", |
| 22 | + *(f"Requires-Dist: {requirement}" for requirement in requirements), |
| 23 | + "", |
| 24 | + ] |
| 25 | + with zipfile.ZipFile(wheel, "w") as archive: |
| 26 | + archive.writestr( |
| 27 | + "aws_durable_execution_sdk_python_otel-1.0.0.dist-info/METADATA", |
| 28 | + "\n".join(metadata), |
| 29 | + ) |
| 30 | + return wheel |
| 31 | + |
| 32 | + |
| 33 | +def test_accepts_layer_provided_dependencies_with_standalone_extra( |
| 34 | + tmp_path: Path, |
| 35 | +) -> None: |
| 36 | + wheel = _write_wheel( |
| 37 | + tmp_path, |
| 38 | + ( |
| 39 | + "aws-durable-execution-sdk-python>=1.8.0", |
| 40 | + "OpenTelemetry_API>=1.20.0; extra == 'standalone'", |
| 41 | + "opentelemetry.sdk>=1.20.0; extra == 'standalone'", |
| 42 | + "OpenTelemetry-Propagator_AWS-XRay; extra == 'standalone'", |
| 43 | + ), |
| 44 | + ) |
| 45 | + |
| 46 | + check_otel_wheel_dependencies(wheel) |
| 47 | + |
| 48 | + |
| 49 | +def test_rejects_default_opentelemetry_dependency(tmp_path: Path) -> None: |
| 50 | + wheel = _write_wheel( |
| 51 | + tmp_path, |
| 52 | + ( |
| 53 | + "aws-durable-execution-sdk-python>=1.8.0", |
| 54 | + "opentelemetry-sdk>=1.20.0", |
| 55 | + "opentelemetry-api>=1.20.0; extra == 'standalone'", |
| 56 | + "opentelemetry-sdk>=1.20.0; extra == 'standalone'", |
| 57 | + "opentelemetry-propagator-aws-xray; extra == 'standalone'", |
| 58 | + ), |
| 59 | + ) |
| 60 | + |
| 61 | + with pytest.raises(ValueError, match="installs OpenTelemetry dependencies"): |
| 62 | + check_otel_wheel_dependencies(wheel) |
| 63 | + |
| 64 | + |
| 65 | +def test_rejects_noncanonical_default_opentelemetry_dependency( |
| 66 | + tmp_path: Path, |
| 67 | +) -> None: |
| 68 | + wheel = _write_wheel( |
| 69 | + tmp_path, |
| 70 | + ( |
| 71 | + "aws-durable-execution-sdk-python>=1.8.0", |
| 72 | + "OpenTelemetry_SDK>=1.20.0", |
| 73 | + "opentelemetry-api>=1.20.0; extra == 'standalone'", |
| 74 | + "opentelemetry-sdk>=1.20.0; extra == 'standalone'", |
| 75 | + "opentelemetry-propagator-aws-xray; extra == 'standalone'", |
| 76 | + ), |
| 77 | + ) |
| 78 | + |
| 79 | + with pytest.raises(ValueError, match="installs OpenTelemetry dependencies"): |
| 80 | + check_otel_wheel_dependencies(wheel) |
| 81 | + |
| 82 | + |
| 83 | +def test_rejects_incomplete_standalone_extra(tmp_path: Path) -> None: |
| 84 | + wheel = _write_wheel( |
| 85 | + tmp_path, |
| 86 | + ( |
| 87 | + "aws-durable-execution-sdk-python>=1.8.0", |
| 88 | + "opentelemetry-api>=1.20.0; extra == 'standalone'", |
| 89 | + "opentelemetry-sdk>=1.20.0; extra == 'standalone'", |
| 90 | + ), |
| 91 | + ) |
| 92 | + |
| 93 | + with pytest.raises( |
| 94 | + ValueError, match="standalone OpenTelemetry dependencies must be" |
| 95 | + ): |
| 96 | + check_otel_wheel_dependencies(wheel) |
0 commit comments