Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/test_orchestrator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import unittest
from unittest.mock import patch
import io

from agents import Orchestrator

Expand All @@ -13,6 +15,17 @@ def test_run_returns_summary(self):
expected = data.strip()[:50]
self.assertEqual(result, expected)

def test_logger_outputs_messages(self):
data = "Capture the logs"
orchestrator = Orchestrator()
with patch('sys.stdout', new_callable=io.StringIO) as mock_stdout:
orchestrator.run(data)
lines = mock_stdout.getvalue().strip().splitlines()
self.assertGreaterEqual(len(lines), 3)
self.assertEqual(lines[0], "[LOG] Parsing data")
self.assertEqual(lines[1], "[LOG] Summarizing data")
self.assertEqual(lines[2], "[LOG] Optimizing summary")
Comment on lines +24 to +27

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Instead of asserting equality on specific log messages, it would be more robust to assert that the log messages contain certain key phrases or patterns. This approach makes the test less brittle to changes in the exact wording of the log messages.1

self.assertIn("Parsing data", mock_stdout.getvalue())
self.assertIn("Summarizing data", mock_stdout.getvalue())
self.assertIn("Optimizing summary", mock_stdout.getvalue())

Style Guide References

Footnotes

  1. When testing log output, it is more robust to assert that the log messages contain certain key phrases or patterns, rather than asserting equality on the entire log message. (link)



if __name__ == "__main__":
unittest.main()