-
Notifications
You must be signed in to change notification settings - Fork 0
Add test suite for ddss/output.py #12
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
Changes from all commits
a6a59b4
23821fa
a06b094
513bb28
72495c4
a07d2fe
17b5794
0f3f0f7
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,113 @@ | ||||||||||||||
| import asyncio | ||||||||||||||
| import tempfile | ||||||||||||||
| import pathlib | ||||||||||||||
| import pytest | ||||||||||||||
| import pytest_asyncio | ||||||||||||||
| from ddss.orm import initialize_database, Facts, Ideas | ||||||||||||||
| from ddss.output import main | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| @pytest_asyncio.fixture | ||||||||||||||
| async def temp_db(): | ||||||||||||||
| """Fixture to create a temporary database.""" | ||||||||||||||
| with tempfile.TemporaryDirectory() as tmpdir: | ||||||||||||||
| db_path = pathlib.Path(tmpdir) / "test.db" | ||||||||||||||
| addr = f"sqlite+aiosqlite:///{db_path.as_posix()}" | ||||||||||||||
| engine, session = await initialize_database(addr) | ||||||||||||||
| yield addr, engine, session | ||||||||||||||
| await engine.dispose() | ||||||||||||||
|
||||||||||||||
| await engine.dispose() | |
| try: | |
| await engine.dispose() | |
| except Exception: | |
| # Ignore errors if the engine was already disposed (e.g., by main()). | |
| pass |
Copilot
AI
Dec 22, 2025
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.
The tests rely on timing with asyncio.sleep(0.2) to allow the output loop to process entries. This makes tests non-deterministic and potentially flaky, especially on slower systems or under load. The tests could fail if the system is too slow to process within 200ms, or could waste time if processing completes faster.
Consider using a more reliable synchronization mechanism, such as:
- Adding a callback or event mechanism to
main()for testing - Using a mock/spy on the print function to detect when output occurs
- Polling the output buffer until expected content appears (with a timeout)
Copilot
AI
Dec 22, 2025
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.
'except' clause does nothing but pass and there is no explanatory comment.
Copilot
AI
Dec 22, 2025
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.
'except' clause does nothing but pass and there is no explanatory comment.
Copilot
AI
Dec 22, 2025
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.
'except' clause does nothing but pass and there is no explanatory comment.
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.
Missing pytest-asyncio configuration in pyproject.toml. pytest-asyncio requires explicit configuration to handle async fixtures and tests properly. Without configuration, you may encounter warnings or unexpected behavior.
Add a
[tool.pytest.ini_options]section with asyncio_mode configuration, for example:or
This ensures pytest-asyncio operates in the expected mode.