-
Notifications
You must be signed in to change notification settings - Fork 0
🧪 QA: Add unit test for log_event function #326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: staging
Are you sure you want to change the base?
Changes from all commits
eab7b54
b106a0b
7934571
932211a
cb5f965
2679c8d
3990b81
7573285
0c2810e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import unittest | ||
| import os | ||
| import tempfile | ||
| import json | ||
| import worker | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
SuggestionPrefer an absolute/relative package import so the test runs reliably under CI runners invoked from the repo root. from workflow import worker
# or, if `workflow` is a package:
from . import workerReply with "@CharlieHelps yes please" if you’d like me to add a commit with this change. |
||
|
|
||
| class TestWorker(unittest.TestCase): | ||
| def setUp(self): | ||
| self.fd, self.temp_path = tempfile.mkstemp() | ||
| self.original_log_path = worker.LOG_PATH | ||
| worker.LOG_PATH = self.temp_path | ||
|
|
||
|
Comment on lines
+9
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
SuggestionClose the def setUp(self):
self.fd, self.temp_path = tempfile.mkstemp()
os.close(self.fd)
self.fd = None
self.original_log_path = worker.LOG_PATH
worker.LOG_PATH = self.temp_path
def tearDown(self):
worker.LOG_PATH = self.original_log_path
if self.fd is not None:
os.close(self.fd)
os.remove(self.temp_path)Reply with "@CharlieHelps yes please" if you’d like me to add a commit with this suggestion. |
||
| def tearDown(self): | ||
| worker.LOG_PATH = self.original_log_path | ||
| os.close(self.fd) | ||
| os.remove(self.temp_path) | ||
|
|
||
| def test_log_event(self): | ||
| worker.log_event("evt_123", "test message") | ||
| with open(self.temp_path, "r") as f: | ||
| lines = f.readlines() | ||
| self.assertEqual(len(lines), 1) | ||
| data = json.loads(lines[0]) | ||
| self.assertEqual(data["event_id"], "evt_123") | ||
| self.assertEqual(data["message"], "test message") | ||
| self.assertIn("timestamp", data) | ||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: This test file is outside the configured pytest testpaths ("tests" and "ai/core/tests"), so it won’t be collected or run in CI. Move it under the tests/ hierarchy or update pytest testpaths to include workflow/ so the coverage actually runs.
Prompt for AI agents