Skip to content

Commit 0e26b05

Browse files
committed
Tests for llmobs_enabled.
1 parent 6a2163f commit 0e26b05

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/test_wrapper.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,3 +862,41 @@ def lambda_handler(event, context):
862862

863863
assert response == expected_response
864864
assert len(Profiler_start_calls) == 1
865+
866+
867+
@patch("datadog_lambda.config.Config.llmobs_enabled", True)
868+
def test_llmobs_enabled(monkeypatch):
869+
importlib.reload(wrapper)
870+
871+
original_LLMObs_enable = wrapper.LLMObs.enable
872+
LLMObs_enable_calls = []
873+
874+
def LLMObs_enable(*args, **kwargs):
875+
LLMObs_enable_calls.append((args, kwargs))
876+
return original_LLMObs_enable(*args, **kwargs)
877+
878+
original_LLMObs_flush = wrapper.LLMObs.flush
879+
LLMObs_flush_calls = []
880+
881+
def LLMObs_flush(*args, **kwargs):
882+
LLMObs_flush_calls.append((args, kwargs))
883+
return original_LLMObs_flush(*args, **kwargs)
884+
885+
monkeypatch.setattr('datadog_lambda.wrapper.is_new_sandbox', lambda: True)
886+
monkeypatch.setattr("datadog_lambda.wrapper.LLMObs.enable", LLMObs_enable)
887+
monkeypatch.setattr("datadog_lambda.wrapper.LLMObs.flush", LLMObs_flush)
888+
889+
expected_response = {
890+
"statusCode": 200,
891+
"body": "This should be returned",
892+
}
893+
894+
@wrapper.datadog_lambda_wrapper
895+
def lambda_handler(event, context):
896+
return expected_response
897+
898+
response = lambda_handler({}, get_mock_context())
899+
900+
assert response == expected_response
901+
assert len(LLMObs_enable_calls) == 1
902+
assert len(LLMObs_flush_calls) == 1

0 commit comments

Comments
 (0)