Skip to content

test: add comprehensive unit tests achieving 99.83% coverage#9

Merged
lipnelz merged 4 commits into
mainfrom
copilot/add-unit-tests-coverage
Mar 14, 2026
Merged

test: add comprehensive unit tests achieving 99.83% coverage#9
lipnelz merged 4 commits into
mainfrom
copilot/add-unit-tests-coverage

Conversation

Copilot AI commented Mar 14, 2026

Copy link
Copy Markdown
Contributor

No test suite existed. Adds 295 unit tests covering all source modules with 99.83% code coverage (requirement: ≥90%), runnable in CI — zero source files modified.

Test infrastructure

  • pytest.inipythonpath=src, asyncio_mode=auto
  • .github/workflows/tests.yml — runs on every push/PR, enforces --cov-fail-under=90

Coverage by module

Module Coverage
config.py, jrequests.py 100%
services/history.py 100%
services/http_client.py 100%
services/massa_rpc.py, price_api.py 100%
services/system_monitor.py 100%
services/docker_manager.py 100%
services/plotting.py 100%
handlers/common.py, node.py, price.py, system.py 100%
handlers/scheduler.py 99%
main.py 99%

The 2 uncovered lines are inherently untestable: the if __name__ == '__main__': guard and a dead-code branch in the scheduler.

Test approach

All external I/O is mocked — no network calls, no Docker socket, no real filesystem writes outside tmp_path. Telegram handler tests use AsyncMock for coroutine methods; conftest.py provides shared mock_update/mock_context fixtures and forces the Agg matplotlib backend.

Documentation

  • test_plan.md — 696-line document describing every test case in depth, organized by file and class, including the scenario each test exercises and a consolidated mocking strategy summary.
Original prompt

Rajoute un maximum de tests unitaires pour chaque fonctions afin de tester exhaustivement toutes les fonctions. Je veux que tout ces tests puissent tourner en CI.
Je ne veux pas que ces tests modifient le code source actuel.
Je veux une couverture de code de 90%

Custom agent used: T800
Code maintainer and reviewer that develop the best application possible.


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Copilot AI added 2 commits March 14, 2026 05:54
- Add pytest.ini with asyncio_mode=auto and pythonpath=src
- Add tests/__init__.py and tests/conftest.py with shared fixtures
- Add test_config.py: 100% coverage of config constants and types
- Add test_services_history.py: 100% coverage of all history functions
- Add test_services_http_client.py: 100% coverage of safe_request
- Add test_services_massa_rpc.py: 100% coverage of RPC functions
- Add test_services_price_api.py: 100% coverage of price API functions
- Add test_services_system_monitor.py: 100% coverage of get_system_stats
- Add test_services_docker_manager.py: 100% coverage of docker helpers
- Add test_services_plotting.py: 100% coverage of all plot functions
- Add test_handlers_common.py: 100% coverage of auth decorator and error handler
- Add test_handlers_node.py: core node handler tests
- Add test_handlers_node_docker.py: docker conversation handler tests (100%)
- Add test_handlers_price.py: 100% coverage of btc and mas handlers
- Add test_handlers_system.py: 100% coverage of hi/temperature/perf handlers
- Add test_handlers_scheduler.py: scheduler and run_coroutine_in_loop tests
- Add test_handlers_scheduler_extra.py: run_async_func and report-hour tests
- Add test_jrequests.py: 100% coverage of backward-compat facade
- Add test_main.py: 99% coverage of main.py (excluding entry-point guard)
- Add test_coverage_gaps.py: targeted tests for remaining coverage gaps
- Add test_final_gaps.py: tests for legacy year-rollback and outer exceptions
- Add .github/workflows/tests.yml: CI workflow with --cov-fail-under=90

Total: 295 tests passing, 99% overall coverage (1199 stmts, 2 missed)
Copilot AI changed the title [WIP] Add unit tests to achieve 90% code coverage test: add comprehensive unit tests achieving 99.83% coverage Mar 14, 2026
Copilot AI requested a review from lipnelz March 14, 2026 06:00
@lipnelz lipnelz marked this pull request as ready for review March 14, 2026 06:09
@lipnelz

lipnelz commented Mar 14, 2026

Copy link
Copy Markdown
Owner

@copilot add a test_plan.md to explain the details in depth of each test

Co-authored-by: lipnelz <174376617+lipnelz@users.noreply.github.com>

Copilot AI commented Mar 14, 2026

Copy link
Copy Markdown
Contributor Author

@copilot add a test_plan.md to explain the details in depth of each test

Added test_plan.md at the repository root (commit e2932e6). It covers 696 lines organized by test file and class, with a table for every individual test describing the scenario being exercised, plus a summary of the mocking strategy used for each external dependency.

@lipnelz lipnelz merged commit d37413c into main Mar 14, 2026
5 checks passed
@lipnelz lipnelz deleted the copilot/add-unit-tests-coverage branch March 14, 2026 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants