Skip to content

Commit edaa5d3

Browse files
committed
Fixed tests
1 parent c88fcc6 commit edaa5d3

File tree

1 file changed

+12
-31
lines changed

1 file changed

+12
-31
lines changed

tests/integrations/anthropic/test_anthropic.py

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async def __call__(self, *args, **kwargs):
4545
except ImportError:
4646
from anthropic.types.content_block import ContentBlock as TextBlock
4747

48-
from sentry_sdk import start_transaction
48+
from sentry_sdk import start_transaction, start_span
4949
from sentry_sdk.consts import OP, SPANDATA
5050
from sentry_sdk.integrations.anthropic import AnthropicIntegration
5151

@@ -656,8 +656,8 @@ async def test_streaming_create_message_with_input_json_delta_async(
656656
if send_default_pii and include_prompts:
657657
assert span["data"][SPANDATA.AI_INPUT_MESSAGES] == messages
658658
assert span["data"][SPANDATA.AI_RESPONSES] == [
659-
{"text": "", "type": "text"}
660-
] # we do not record InputJSONDelta because it could contain PII
659+
{"text": "{'location': 'San Francisco, CA'}", "type": "text"}
660+
]
661661

662662
else:
663663
assert SPANDATA.AI_INPUT_MESSAGES not in span["data"]
@@ -796,41 +796,22 @@ def test_add_ai_data_to_span_with_input_json_delta(sentry_init):
796796
send_default_pii=True,
797797
)
798798

799-
with start_transaction(name="test") as transaction:
800-
span = transaction.start_span()
799+
with start_transaction(name="test"):
800+
span = start_span()
801801
integration = AnthropicIntegration()
802802

803803
_add_ai_data_to_span(
804804
span,
805805
integration,
806806
input_tokens=10,
807807
output_tokens=20,
808-
content_blocks=["{'test': 'data'}", "'more': 'json'"],
808+
content_blocks=["{'test': 'data',", "'more': 'json'}"],
809809
)
810810

811-
assert span.get_data(SPANDATA.AI_RESPONSES) == [
812-
{"type": "text", "text": "{'test': 'data''more': 'json'}"}
811+
assert span._data.get(SPANDATA.AI_RESPONSES) == [
812+
{"type": "text", "text": "{'test': 'data','more': 'json'}"}
813813
]
814-
assert span.get_data("ai.streaming") is True
815-
assert span.get_measurement("ai_prompt_tokens_used")["value"] == 10
816-
assert span.get_measurement("ai_completion_tokens_used")["value"] == 20
817-
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()])
814+
assert span._data.get("ai.streaming") is True
815+
assert span._measurements.get("ai_prompt_tokens_used")["value"] == 10
816+
assert span._measurements.get("ai_completion_tokens_used")["value"] == 20
817+
assert span._measurements.get("ai_total_tokens_used")["value"] == 30

0 commit comments

Comments
 (0)