Skip to content

Add comprehensive unit test suite (100 tests, 54% coverage)#235

Draft
daedalist wants to merge 5 commits intobohdan-s:mainfrom
daedalist:add-unit-tests
Draft

Add comprehensive unit test suite (100 tests, 54% coverage)#235
daedalist wants to merge 5 commits intobohdan-s:mainfrom
daedalist:add-unit-tests

Conversation

@daedalist
Copy link
Copy Markdown
Contributor

Summary

Implements a complete unit testing infrastructure for SunGather with 100 tests achieving 54% overall code coverage
across export modules and core functionality.

Testing Infrastructure

  • pytest: Test framework with fixtures and parameterization
  • pytest-mock: Mocking library for isolating components
  • pytest-cov: Coverage reporting (HTML and terminal output)
  • pytest.ini: Configuration for test discovery and coverage settings

GitHub Workflow

  • .github/workflows/test.yml: CI pipeline running on push/PR
  • Tests run on Python 3.9, 3.10, 3.11, and 3.12
  • Automatic coverage reporting in PR comments
  • Prevents merging if tests fail

Test Coverage by Module

Module Coverage Tests
console.py 100% 11
webserver.py 99% 20
influxdb.py 98% 19
mqtt.py 93% 24
pvoutput.py 84% 21
hassio.py 6% 1 (documents broken state)
sungather.py 0% 4 (AST-based tests)

Overall: 54% coverage, 100 tests

Test Organization

  • tests/exports/: Export module tests (console, webserver, mqtt, influxdb, pvoutput, hassio)
  • tests/test_sungather.py: Main module tests using AST parsing
  • tests/conftest.py: Shared fixtures and test configuration
  • tests/README.md: Documentation for running and writing tests

Notable Test Patterns

  • Mock-based testing for external dependencies (MQTT, InfluxDB, HTTP servers)
  • AST parsing for testing sungather.py (module has sys.exit() at top level)
  • Exception-based testing for hassio.py (documents known bug)
  • Coverage of both success and error paths

Known Issues Documented

  • hassio.py has a bug: line 12 defines api_base, but lines 13-16 use undefined url_base
  • Test expects AttributeError and will fail when bug is fixed as a reminder to add proper functional tests

Development Workflow

# Install dev dependencies
pip install -r requirements-dev.txt

# Run tests
pytest

# Run with coverage
pytest --cov=SunGather --cov-report=html

# View coverage report
open htmlcov/index.html

Files Changed

- .github/workflows/test.yml - CI/CD test pipeline
- pytest.ini - pytest configuration
- requirements-dev.txt - development dependencies
- tests/README.md - testing documentation
- tests/conftest.py - shared test fixtures
- tests/test_sungather.py - main module tests
- tests/exports/test_*.py - export module tests (6 files)

Benefits

- ✅ Automated testing on every push/PR
- ✅ Prevents regressions in export modules
- ✅ Documents expected behavior
- ✅ Makes refactoring safer
- ✅ Improves code quality and maintainability

---
🤖 Coded with https://claude.com/claude-code assistance

@codecov-commenter
Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

daedalist and others added 3 commits October 19, 2025 15:37
Implements a complete unit testing infrastructure for SunGather with 100 tests
achieving 54% overall code coverage across export modules and core functionality.

Testing Infrastructure:
- pytest: Test framework with fixtures and parameterization
- pytest-mock: Mocking library for isolating components
- pytest-cov: Coverage reporting (HTML and terminal output)
- pytest.ini: Configuration for test discovery and coverage settings

GitHub Workflow:
- .github/workflows/test.yml: CI pipeline running on push/PR
- Tests run on Python 3.9, 3.10, 3.11, and 3.12
- Automatic coverage reporting in PR comments
- Prevents merging if tests fail

Test Coverage by Module:
- console.py:     100% coverage (11 tests)
- webserver.py:    99% coverage (20 tests)
- influxdb.py:     98% coverage (19 tests)
- mqtt.py:         93% coverage (24 tests)
- pvoutput.py:     84% coverage (21 tests)
- hassio.py:        6% coverage (1 test - documents broken state)
- sungather.py:     0% coverage (4 AST-based tests)

Test Organization:
- tests/exports/: Export module tests (console, webserver, mqtt, influxdb, pvoutput, hassio)
- tests/test_sungather.py: Main module tests using AST parsing
- tests/conftest.py: Shared fixtures and test configuration
- tests/README.md: Documentation for running and writing tests

Notable Test Patterns:
- Mock-based testing for external dependencies (MQTT, InfluxDB, HTTP servers)
- AST parsing for testing sungather.py (module has sys.exit() at top level)
- Exception-based testing for hassio.py (documents known bug)
- Coverage of both success and error paths

Known Issues Documented:
- hassio.py has a bug (line 12 defines api_base, lines 13-16 use undefined url_base)
- Test expects AttributeError; will fail when bug is fixed as a reminder to add proper tests

Development Workflow:
- Run tests: pytest
- Run with coverage: pytest --cov=SunGather --cov-report=html
- View coverage: open htmlcov/index.html
- Install dev dependencies: pip install -r requirements-dev.txt

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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