Skip to content

Commit 1b6f72c

Browse files
committed
fix: add tests for unsupported versions of anthropic
1 parent 834bf35 commit 1b6f72c

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

tests/integrations/anthropic/test_anthropic.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from unittest import mock
22

3+
from sentry_sdk.integrations import DidNotEnable
4+
35
try:
46
from unittest.mock import AsyncMock
57
except ImportError:
@@ -518,9 +520,8 @@ def test_streaming_create_message_with_input_json_delta(
518520
if send_default_pii and include_prompts:
519521
assert span["data"][SPANDATA.AI_INPUT_MESSAGES] == messages
520522
assert span["data"][SPANDATA.AI_RESPONSES] == [
521-
{"text": "", "type": "text"}
522-
] # we do not record InputJSONDelta because it could contain PII
523-
523+
{"text": "{'location': 'San Francisco, CA'}", "type": "text"}
524+
]
524525
else:
525526
assert SPANDATA.AI_INPUT_MESSAGES not in span["data"]
526527
assert SPANDATA.AI_RESPONSES not in span["data"]
@@ -814,3 +815,22 @@ def test_add_ai_data_to_span_with_input_json_delta(sentry_init):
814815
assert span.get_measurement("ai_prompt_tokens_used")["value"] == 10
815816
assert span.get_measurement("ai_completion_tokens_used")["value"] == 20
816817
assert span.get_measurement("ai_total_tokens_used")["value"] == 30
818+
819+
820+
def test_unsupported_anthropic_version(sentry_init):
821+
with mock.patch(
822+
"sentry_sdk.integrations.anthropic.package_version", return_value=(0, 15, 0)
823+
):
824+
with pytest.raises(DidNotEnable):
825+
sentry_init(
826+
integrations=[AnthropicIntegration()],
827+
traces_sample_rate=1.0,
828+
)
829+
830+
831+
def test_no_version_info(sentry_init):
832+
with mock.patch(
833+
"sentry_sdk.integrations.anthropic.package_version", return_value=None
834+
):
835+
with pytest.raises(DidNotEnable):
836+
sentry_init(integrations=[AnthropicIntegration()])

0 commit comments

Comments
 (0)