Skip to content

test: improve test coverage to 93% (Issue #16) - #18

Merged
KHolodilin merged 35 commits into
mainfrom
feature/issue-2-improve-test-coverage-95
Jan 23, 2026
Merged

test: improve test coverage to 93% (Issue #16)#18
KHolodilin merged 35 commits into
mainfrom
feature/issue-2-improve-test-coverage-95

Conversation

@KHolodilin

Copy link
Copy Markdown
Owner

Description

This PR improves test coverage from 92% to 93% by adding comprehensive tests for email_processor.py.

Changes

  • Added 21 new tests for email_processor.py covering:
    • Blocked attachments handling
    • Attachment error handling (no filename, non-tuple results, False results)
    • UID fetch data errors (AttributeError, IndexError, TypeError)
    • UID save errors after fetch failure and after processing
    • Logout error handling (IMAP error, AttributeError)
    • Archive error handling (dry-run mode, ConnectionError, OSError)
    • File statistics error handling
    • psutil memory error handling and peak updates

Test Coverage

  • email_processor.py: 94% (improved from 87%)
  • Overall project coverage: 93% (improved from 92%)

Related Issue

Fixes #16

Testing

All tests pass:

  • ✅ 21 new tests added
  • ✅ All existing tests still pass
  • ✅ Pre-commit checks pass

Checklist

  • All tests pass
  • Pre-commit checks pass
  • Code committed
  • Branch pushed to remote repository
  • Pull Request created

- Add tests for attachment error handling (non-tuple and False results)
- Add tests for dry-run archive mode
- Add tests for archive error handling (ConnectionError, OSError)
- Add tests for processed UID save errors after processing
- Add tests for file statistics error handling
- Add test for psutil memory peak update

Improves email_processor.py coverage from 92% to 94%
Overall project coverage: 93%
@KHolodilin KHolodilin mentioned this pull request Jan 21, 2026
45 tasks
@codecov-commenter

codecov-commenter commented Jan 21, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 99.41860% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
email_processor/cli/ui.py 95.74% 2 Missing ⚠️
email_processor/__main__.py 99.33% 1 Missing ⚠️
email_processor/cli/commands/config.py 97.67% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

- Add test for mock_mode logging
- Add test for cleanup unexpected error
- Add tests for message_walk errors (AttributeError, TypeError)
- Add test for archive IMAP error

Improves email_processor.py coverage from 94% to 95%
Overall project coverage: 93%
- Add test for platform.system() exception handling
- Add test for Linux getuid when getuid is None (getattr returns None)
- Add test for Linux getuid with UID (works on all platforms)
- Add test for Linux getuid exception (works on all platforms)

Improves fingerprint.py coverage from 87% to 100%
Overall project coverage: 93%
…ix SMTP tests to check info() instead of print() when has_rich=False - Fix UI error tests to properly mock ConfigLoader.load() method - Fix integration tests to handle processed UID file date variations - Make download_attachments() return ProcessingResult for testability - Fix duplicate assignment in test_download_attachments_already_processed - All 707 tests now pass (705 unit + 2 integration tests fixed)
…MTP and UI tests to patch get_imap_password in smtp module instead of auth module - Fix password tests to patch sys.platform in passwords module - Fix test_smtp_send_folder_partial_failure_with_rich_console UI assertion - All 88 tests now pass (15 skipped on Windows for permission checks)
…ests - Use MockPathClass with __new__ to properly mock Path constructor - Add stat.filemode patch inside test context managers - Fix indentation issues in test_set_password_file_permission_warning - Tests should now pass on Linux CI (skipped on Windows as expected)
…ord tests - Replace MockPathClass with path_factory function for better compatibility - Add spec=Path to mock_path for better type checking - Add __str__ and __fspath__ mocks for Path compatibility - Tests should now properly trigger permission warnings on Linux CI
…ts - Ensure Path is properly mocked as callable using MagicMock(side_effect=path_factory) - Add assert_called() checks for mock_path.stat() to verify permission check runs - Tests should now properly trigger permission warnings on Linux CI
…s - Fix indentation error in test_set_password_file_permission_warning_with_rich_console - Rename mock_filemode to mock_filemode_patch in both tests to avoid PLR1704
…Rename mock_filemode to mock_filemode_patch in test_set_password_file_permission_warning - This ensures consistency and avoids PLR1704 linting errors
…s - Remove @patch('stat.filemode') decorator that was patching global stat.filemode - Use only the local patch inside the test context for email_processor.cli.commands.passwords.stat.filemode - This should fix the permission warning tests on Linux CI
…d optional ui parameter to validate_config, load_config, and ConfigLoader methods - Use ui.warn() when UI is available, fallback to print() otherwise - Update all call sites to pass UI instance when available - This ensures consistent output formatting through CLIUI
…ate test_validate_config_file_success to expect ui parameter - Update test_main_custom_config_path to check ui parameter in call args - Update test_validate_config_file_validation_error to expect ui parameter - All config and main tests now pass with new UI parameter
…tat.filemode() calls - Simplify warning message checks - Ensure tests fail with clear error messages if stat.filemode() is not called or warning is not shown
…l_stat_result.st_mode to verify condition - Add octal representation for better debugging - Verify stat.filemode() is called with correct st_mode value
… actual_stat_result.st_mode to verify condition - Add octal representation for better debugging - Verify stat.filemode() is called with correct st_mode value
… in __main__.py as 'from email_processor.cli import CLIUI' - Need to patch 'email_processor.__main__.CLIUI' to ensure mock is used - This fixes permission warning tests where ui.warn() was called but not captured
…Update test_set_password_file_permission_warning_with_rich_console to use __main__.CLIUI patch
…or if statement and return statements in path_factory - This was causing a syntax error
…date test_set_password_file_permission_warning_with_rich_console to use __main__.CLIUI patch - This ensures the mock UI is used when main() creates CLIUI instance
…py with 13 tests for CLI commands end-to-end - Add test_full_cycle_integration.py with 3 tests for full email processing cycle - Cover config init/validate, status, password set/clear, send file/folder, fetch, run commands - Cover full cycle: download attachments -> send via SMTP - Cover error handling: missing/invalid commands, config errors - All 16 integration tests passing
- Added 9 new tests to cover previously uncovered lines:
  - passwords.py: clear_password success, interactive input, no encryption, Unix permission check
  - smtp.py: rich console messages for no new files and skipped files, missing --to error
  - args.py: mutually exclusive verbose/quiet options
  - loader.py: ui.warn() when ui is provided
- Updated CI to use --cov-fail-under=95 to prevent coverage regression
- Coverage improved: 38 uncovered lines (down from 59)
- All 750 tests passing (732 passed, 18 skipped)
@KHolodilin
KHolodilin merged commit 7a7a4ac into main Jan 23, 2026
14 checks passed
@KHolodilin
KHolodilin deleted the feature/issue-2-improve-test-coverage-95 branch January 23, 2026 10: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.

Improve test coverage to 95%+

2 participants