Files
microsoft--agent-lightning/tests/instrumentation/test_agentops.py
T
wehub-resource-sync 85742ab165
Deploy Documentation / deploy (push) Has been cancelled
CPU Test / Test (Utilities, legacy, Python 3.10) (push) Has been cancelled
CPU Test / Test (LLM proxy, stable, Python 3.11) (push) Has been cancelled
CPU Test / Test (Others, stable, Python 3.11) (push) Has been cancelled
CPU Test / Test (Store, stable, Python 3.11) (push) Has been cancelled
CPU Test / Test (Utilities, stable, Python 3.11) (push) Has been cancelled
CPU Test / Test (Weave, stable, Python 3.11) (push) Has been cancelled
CPU Test / Test (AgentOps, stable, Python 3.12) (push) Has been cancelled
CPU Test / Test (LLM proxy, stable, Python 3.12) (push) Has been cancelled
CPU Test / Test (Others, stable, Python 3.12) (push) Has been cancelled
CPU Test / Test (Weave, latest, Python 3.13) (push) Has been cancelled
Dashboard / Chromatic (push) Has been cancelled
CPU Test / Lint - fast (push) Has been cancelled
CPU Test / Lint - next (push) Has been cancelled
CPU Test / Lint - slow (push) Has been cancelled
CPU Test / Lint - JavaScript (push) Has been cancelled
CPU Test / Build documentation (push) Has been cancelled
CPU Test / Test (AgentOps, legacy, Python 3.10) (push) Has been cancelled
CPU Test / Test (LLM proxy, legacy, Python 3.10) (push) Has been cancelled
CPU Test / Test (Others, legacy, Python 3.10) (push) Has been cancelled
CPU Test / Test (Store, legacy, Python 3.10) (push) Has been cancelled
CPU Test / Test (Weave, legacy, Python 3.10) (push) Has been cancelled
CPU Test / Test (AgentOps, stable, Python 3.11) (push) Has been cancelled
CPU Test / Test (Store, stable, Python 3.12) (push) Has been cancelled
CPU Test / Test (Utilities, stable, Python 3.12) (push) Has been cancelled
CPU Test / Test (Weave, stable, Python 3.12) (push) Has been cancelled
CPU Test / Test (AgentOps, latest, Python 3.13) (push) Has been cancelled
CPU Test / Test (LLM proxy, latest, Python 3.13) (push) Has been cancelled
CPU Test / Test (Others, latest, Python 3.13) (push) Has been cancelled
CPU Test / Test (Store, latest, Python 3.13) (push) Has been cancelled
CPU Test / Test (Utilities, latest, Python 3.13) (push) Has been cancelled
CPU Test / Test (JavaScript) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:44:17 +08:00

74 lines
2.7 KiB
Python

# Copyright (c) Microsoft. All rights reserved.
# FIXME: This file will have side-effects on other tests if the tests failed and agentops service is not disabled.
from unittest.mock import MagicMock, patch
import pytest
from opentelemetry.sdk.metrics.export import MetricExportResult
from opentelemetry.sdk.trace.export import SpanExportResult
from agentlightning.instrumentation.agentops import (
BypassableAuthenticatedOTLPExporter,
BypassableOTLPMetricExporter,
BypassableOTLPSpanExporter,
enable_agentops_service,
)
@pytest.mark.agentops
def test_switchable_authenticated_exporter():
switchable_authenticated_exporter = BypassableAuthenticatedOTLPExporter(endpoint="http://dummy", jwt="dummy")
with patch.object(
switchable_authenticated_exporter.__class__.__bases__[-1], "export", return_value=SpanExportResult.SUCCESS
) as mock_export:
enable_agentops_service()
result = switchable_authenticated_exporter.export([])
assert result == SpanExportResult.SUCCESS
mock_export.assert_called_once()
enable_agentops_service(False)
result = switchable_authenticated_exporter.export([])
assert result == SpanExportResult.SUCCESS
assert mock_export.call_count == 1
@pytest.mark.agentops
def test_switchable_otlp_metric_exporter():
switchable_otlp_metric_exporter = BypassableOTLPMetricExporter()
with patch.object(
switchable_otlp_metric_exporter.__class__.__bases__[-1], "export", return_value=MetricExportResult.SUCCESS
) as mock_export:
enable_agentops_service()
result = switchable_otlp_metric_exporter.export(metrics_data=MagicMock())
assert result == MetricExportResult.SUCCESS
mock_export.assert_called_once()
enable_agentops_service(False)
result = switchable_otlp_metric_exporter.export(metrics_data=MagicMock())
assert result == MetricExportResult.SUCCESS
assert mock_export.call_count == 1
@pytest.mark.agentops
def test_switchable_otlp_span_exporter():
switchable_otlp_span_exporter = BypassableOTLPSpanExporter()
with patch.object(
# BypassableOTLPSpanExporter is a subclass of LightningStoreOTLPExporter, which is a subclass of OTLPSpanExporter
switchable_otlp_span_exporter.__class__.__bases__[-1].__bases__[0],
"export",
return_value=SpanExportResult.SUCCESS,
) as mock_export:
enable_agentops_service()
result = switchable_otlp_span_exporter.export([])
assert result == SpanExportResult.SUCCESS
mock_export.assert_called_once()
enable_agentops_service(False)
result = switchable_otlp_span_exporter.export([])
assert result == SpanExportResult.SUCCESS
assert mock_export.call_count == 1