A comprehensive test suite has been added to the IMAP Backup project, covering all major functionality including the recently added improvements for error handling, retry logic, progress tracking, and memory optimization.
Files Created:
pytest.ini- Pytest configurationrequirements-dev.txt- Development and testing dependenciestests/directory with comprehensive test suite
Test Files:
tests/conftest.py- Shared fixtures and test configurationtests/test_spinner.py- Progress tracking tests (8 tests)tests/test_retry_logic.py- Network retry mechanism tests (11 tests)tests/test_batch_processing.py- Memory optimization tests (12 tests)tests/test_imapbackup.py- Core functionality tests (29 tests)tests/README.md- Comprehensive testing documentationtests/__init__.py- Package initialization
Total: 60 tests covering critical functionality
GitHub Actions Workflow:
.github/workflows/ci-tests.yml- Automated testing pipeline
Features:
- ✅ Multi-version Python testing (3.8, 3.9, 3.10, 3.11, 3.12)
- ✅ Multi-OS testing (Ubuntu, macOS)
- ✅ Automated test execution on push and PR
- ✅ Code coverage reporting
- ✅ Code quality checks (flake8, pylint)
- ✅ Integration with Codecov
✅ Initialization with and without progress tracking ✅ Progress updates and percentage calculations ✅ Terminal output formatting ✅ nospinner mode behavior ✅ Progress message format validation
✅ Successful operation on first attempt ✅ Recovery from network errors ✅ Exponential backoff timing ✅ Maximum retry limit enforcement ✅ Socket timeout handling ✅ IMAP error handling ✅ Non-network error propagation
✅ Batch size configuration ✅ Single batch processing ✅ Multiple batch processing ✅ Batch range calculation ✅ Memory cleanup (gc.collect) ✅ Large mailbox handling (10,000+ messages)
✅ Utility functions (pretty_byte_count, string_from_file) ✅ Message ID regex and parsing ✅ IMAP LIST response parsing ✅ File scanning (scan_file) ✅ Folder operations (get_names) ✅ Configuration parsing ✅ Directory creation ✅ Exception handling (SkipFolderException)
============================= test session starts ==============================
platform linux -- Python 3.12.3, pytest-8.4.2, pluggy-1.6.0
rootdir: /home/user/stage/chris2k20/imapbackup
configfile: pytest.ini
plugins: cov-7.0.0, mock-3.15.1
collected 60 items
tests/test_batch_processing.py ............ [ 20%]
tests/test_imapbackup.py ............................. [ 68%]
tests/test_retry_logic.py ........... [ 86%]
tests/test_spinner.py ........ [100%]
============================== 60 passed in 3.19s ==============================
All 60 tests passed successfully! ✅
# Install test dependencies
pip install -r requirements-dev.txt
# Run all tests
pytest
# Run with coverage
pytest --cov=imapbackup --cov-report=term-missing# Run only unit tests
pytest -m unit
# Run only integration tests
pytest -m integration
# Run specific test file
pytest tests/test_spinner.py
# Run specific test
pytest tests/test_spinner.py::TestSpinner::test_spinner_initialization# Generate HTML coverage report
pytest --cov=imapbackup --cov-report=html
# Open in browser
open htmlcov/index.htmlProgress Tracking:
- Spinner correctly displays "(current/total, percentage%)" format
- Progress updates work correctly
- 100% completion is properly displayed
Retry Logic:
- Network errors trigger automatic retries
- Exponential backoff works correctly
- Non-network errors don't trigger unnecessary retries
- Maximum retry limits are respected
Batch Processing:
- Large mailboxes are processed in chunks (1000 messages at a time)
- Memory is properly cleaned up between batches (gc.collect)
- Batch ranges are calculated correctly
- Progress tracking works across multiple batches
- File and folder operations work correctly
- IMAP protocol handling is proper
- Configuration parsing is accurate
- Message ID handling is robust
Current test coverage focuses on:
- Critical functions: High priority functions have comprehensive test coverage
- New features: All recently added features (retry, batching, progress) are fully tested
- Edge cases: Boundary conditions and error scenarios are covered
Tests run automatically on:
- Every push to main/master/develop branches
- Every pull request
- Manual trigger via GitHub Actions
CI Pipeline includes:
- Install dependencies
- Run unit tests
- Run integration tests
- Generate coverage report
- Run code quality checks (flake8, pylint)
- Upload coverage to Codecov
Comprehensive testing documentation is available in:
tests/README.md- Complete testing guideTESTING.md- This file (summary)
✅ Confidence in code changes ✅ Catch regressions early ✅ Document expected behavior ✅ Easier refactoring
✅ Improved reliability ✅ Fewer bugs in production ✅ Better stability
✅ Clear contribution guidelines ✅ Automated validation ✅ Faster review process
When adding new features:
- Write tests first (TDD)
- Place tests in appropriate file
- Use pytest markers (
@pytest.mark.unitor@pytest.mark.integration) - Run tests:
pytest - Check coverage:
pytest --cov=imapbackup
import pytest
import imapbackup
@pytest.mark.unit
class TestMyFeature:
"""Tests for my feature"""
def test_feature_works(self):
"""Test that feature works correctly"""
# Arrange
input_data = "test"
# Act
result = imapbackup.my_function(input_data)
# Assert
assert result == expected_output# Run with verbose output
pytest -v
# Show print statements
pytest -s
# Drop into debugger on failure
pytest --pdb
# Show local variables
pytest -lTest dependencies are defined in requirements-dev.txt:
pytest>=7.4.0 # Testing framework
pytest-cov>=4.1.0 # Coverage plugin
pytest-mock>=3.11.1 # Mocking utilities
pytest-timeout>=2.1.0 # Test timeouts
coverage>=7.3.0 # Coverage reporting
pylint>=2.17.0 # Code linting
flake8>=6.1.0 # Style checking
black>=23.7.0 # Code formatting
mypy>=1.5.0 # Type checking
- See
tests/README.mdfor detailed testing guide - See
.github/workflows/ci-tests.ymlfor CI configuration - See
pytest.inifor pytest configuration - See
conftest.pyfor shared test fixtures
To contribute tests:
- Fork the repository
- Create a feature branch
- Add your tests
- Ensure all tests pass:
pytest - Check coverage:
pytest --cov=imapbackup - Submit a pull request
CI will automatically run all tests on your PR.
Potential test improvements:
- Add more S3 integration tests
- Add more GPG encryption tests
- Add performance benchmarks
- Increase coverage to 90%+
- Add mutation testing
- Add property-based testing (hypothesis)
Questions or issues with tests?
- Open an issue: https://github.com/chris2k20/imapbackup/issues
- See documentation:
tests/README.md - Check CI logs: GitHub Actions tab
Tests implemented by: Claude Code Assistant Date: October 10, 2025 Status: ✅ All 60 tests passing