Skip to content

Commit

Permalink
add test for a single session
Browse files Browse the repository at this point in the history
  • Loading branch information
the-praxs committed Nov 21, 2024
1 parent 2371269 commit 9120be9
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,47 @@ def test_safe_get_session_with_multiple_sessions(self, mock_req):
session = Client()._safe_get_session()
assert session is None

def test_get_analytics(self, mock_req):
# Arrange
session = agentops.start_session()
session.add_tags(["test-session-analytics-tag"])
assert session is not None

# Record some events to increment counters
session.record(ActionEvent("llms"))
session.record(ActionEvent("tools"))
session.record(ActionEvent("actions"))
session.record(ActionEvent("errors"))
time.sleep(0.1)

# Act
response = session._get_response()
analytics = session.get_analytics(response)

# Assert
assert isinstance(analytics, dict)
assert all(key in analytics for key in [
"LLM calls", "Tool calls", "Actions", "Errors", "Duration", "Cost"
])

# Check specific values
assert analytics["LLM calls"] == 1
assert analytics["Tool calls"] == 1
assert analytics["Actions"] == 1
assert analytics["Errors"] == 1

# Check duration format
assert isinstance(analytics["Duration"], str)
assert "s" in analytics["Duration"]

# Check cost format (mock returns token_cost: 5)
assert analytics["Cost"] == "5.000000"

# End session and cleanup
session.end_session(end_state="Success")
time.sleep(0.15)
agentops.end_all_sessions()


class TestMultiSessions:
def setup_method(self):
Expand Down

0 comments on commit 9120be9

Please sign in to comment.