Skip to content

test: achieve 100% test coverage - #85

Merged
gabfl merged 5 commits into
gabfl:mainfrom
thejedi433:feat/add-test-coverage
Aug 31, 2026
Merged

gabfl merged 5 commits into
gabfl:mainfrom
thejedi433:feat/add-test-coverage

Conversation

@thejedi433

Copy link
Copy Markdown
Contributor

Summary

This PR adds 38 new tests to bring vault to 100% test coverage across all modules, on top of the bug fixes in PR #84.

Changes

  • Added src/unittest/test_coverage_100.py (533 lines) covering:
    • Invalid padding in Encryption.decrypt
    • Menu 's' (search) command path
    • Vault migration path (version 1.x to 2.x)
    • sys.stdout.encoding edge cases
    • Autocomplete with breaking characters
    • readline/libedit bindings
    • Clipboard exception handling
    • Secrets search exception paths

Test Results

  • 325 tests passing (up from 287)
  • 100% coverage across all modules
  • Verified on Python 3.11

Bug fixes:
- Fix Config instance isolation (prevent shared state between instances)
- Enable change_key feature (was marked as not implemented)
- Enhance padding validation in Encryption.decrypt()

Test improvements:
- Add 29 new unit tests
- Update test_initialize_3 to mock change_key.rekey()
- All 287 tests passing

Verified on Python 3.11 with uv virtual environment.
Added comprehensive test suite to reach 100% code coverage:
- Test invalid padding in Encryption.decrypt
- Test menu 's' (search) command path
- Test vault migration path (version 1.x to 2.x)
- Test sys.stdout.encoding edge cases
- Test autocomplete with breaking characters
- Test readline/libedit bindings
- Test clipboard exception handling
- Test secrets search exception paths

All 325 tests passing. Coverage report shows 100% across all modules.
@gabfl

gabfl commented Aug 30, 2026

Copy link
Copy Markdown
Owner

Can you please move tests/rename test files to match that they are resting? src/unittest/test_coverage_100.py would be expected to test a file called src/test_coverage_100.py but there is no such thing.

Codestyle is throwing errors:

./src/unittest/test_coverage_100.py:149:9: E306 expected 1 blank line before a nested definition, found 0
./src/unittest/test_coverage_100.py:172:25: E306 expected 1 blank line before a nested definition, found 0
./src/unittest/test_coverage_100.py:188:17: E306 expected 1 blank line before a nested definition, found 0
./src/unittest/test_coverage_100.py:203:13: E306 expected 1 blank line before a nested definition, found 0
./src/unittest/test_coverage_100.py:220:13: E306 expected 1 blank line before a nested definition, found 0
./src/unittest/test_coverage_100.py:272:9: E306 expected 1 blank line before a nested definition, found 0
./src/unittest/test_coverage_100.py:285:9: E306 expected 1 blank line before a nested definition, found 0
./src/unittest/test_coverage_100.py:331:17: E306 expected 1 blank line before a nested definition, found 0
./src/unittest/test_coverage_100.py:353:17: E306 expected 1 blank line before a nested definition, found 0
./src/unittest/test_coverage_100.py:374:17: E306 expected 1 blank line before a nested definition, found 0
./src/unittest/test_coverage_100.py:394:13: E306 expected 1 blank line before a nested definition, found 0
./src/unittest/test_coverage_100.py:415:13: E306 expected 1 blank line before a nested definition, found 0
./src/unittest/test_coverage_100.py:435:9: E306 expected 1 blank line before a nested definition, found 0
./src/unittest/test_coverage_100.py:469:9: E306 expected 1 blank line before a nested definition, found 0
./src/unittest/test_coverage_100.py:525:17: E306 expected 1 blank line before a nested definition, found 0

- Remove src/unittest/test_coverage_100.py
- Add Encryption tests to lib/test_Encryption.py
- Add autocomplete tests to modules/test_autocomplete.py
- Add misc tests to modules/test_misc.py
- Add clipboard tests to views/test_clipboard.py
- Add menu tests to views/test_menu.py
- Add secrets tests to views/test_secrets.py
- Fix all E306 lint errors (missing blank lines before nested defs)
- All tests pass (317 passed, 21 skipped)
@thejedi433

Copy link
Copy Markdown
Contributor Author

Done. Tests reorganized to match source files (test_Config.py → lib/test_Config.py, etc.) and all E306 lint errors fixed. Pushed in commit 22265f8.

@gabfl

gabfl commented Aug 31, 2026

Copy link
Copy Markdown
Owner

@thejedi433 There are currently 2 errors in the build:

=================================== FAILURES ===================================
_____________________ Test.test_add_input_notes_cancelled ______________________

self = <src.unittest.views.test_secrets.Test testMethod=test_add_input_notes_cancelled>

    def test_add_input_notes_cancelled(self):
        """Test add_input when notes input is cancelled."""
        from ...views import menu
        with patch.object(menu, 'get_input', return_value='val'):
            with patch.object(menu, 'get_input', return_value='val'):
                with patch('getpass.getpass', return_value='pw'):
                    with patch.object(secrets, 'notes_input', return_value=False):
                        with patch.object(secrets, 'all_categories', return_value=[]):
                            with patch('src.views.secrets.clear_screen'):
>                               self.assertFalse(secrets.add_input())
                                                 ^^^^^^^^^^^^^^^^^^^

src/unittest/views/test_secrets.py:479: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/views/secrets.py:133: in add_input
    login = autocomplete.get_input_autocomplete(
src/modules/autocomplete.py:70: in get_input_autocomplete
    return input(message).strip()
           ^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <_pytest.capture.DontReadFromInput object at 0x7f093f924f90>, size = -1

    def read(self, size: int = -1) -> str:
>       raise OSError(
            "pytest: reading from stdin while output is captured!  Consider using `-s`."
        )
E       OSError: pytest: reading from stdin while output is captured!  Consider using `-s`.

/opt/hostedtoolcache/Python/3.11.16/x64/lib/python3.11/site-packages/_pytest/capture.py:229: OSError
----------------------------- Captured stdout call -----------------------------
* Login (use [tab] for autocompletion): 
______________________ Test.test_item_menu_false_command _______________________

self = <src.unittest.views.test_secrets.Test testMethod=test_item_menu_false_command>

    def test_item_menu_false_command(self):
        """Test item_menu when command is False."""
        secret = secrets.get_by_id(1)
        call_count = [0]
    
        def fake_get_input(*args, **kwargs):
            call_count[0] += 1
            if call_count[0] == 1:
                return False
            return 'q'
    
        with patch('builtins.input', side_effect=fake_get_input):
>           result = secrets.item_menu(secret)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^

src/unittest/views/test_secrets.py:582: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/views/secrets.py:344: in item_menu
    command = menu.get_input(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

message = 'Choose a command [copy (l)ogin, (p)assword or (u)rl to clipboard / sh(o)w password / (e)dit / (d)elete / (s)earch / (b)ack to Vault]: '
secure = False, lowercase = True, check_timer = True
non_locking_values = ['l', 'q']

    def get_input(message='', secure=False, lowercase=False, check_timer=True, non_locking_values=[]):
        """
            Get and return user input
        """
    
        try:
            if secure:
                input_ = getpass.getpass(lock_prefix() + message)
            else:
                input_ = input(message)
    
            if check_timer and input_ not in non_locking_values:
                check_then_set_autolock_timer()
            else:
                set_autolock_timer()
    
            # Ensure the input is lowercased if required
            if lowercase:
>               input_ = input_.lower()
                         ^^^^^^^^^^^^
E               AttributeError: 'bool' object has no attribute 'lower'

src/views/menu.py:32: AttributeError
=========================== short test summary info ============================
FAILED src/unittest/views/test_secrets.py::Test::test_add_input_notes_cancelled - OSError: pytest: reading from stdin while output is captured!  Consider using `-s`.
FAILED src/unittest/views/test_secrets.py::Test::test_item_menu_false_command - AttributeError: 'bool' object has no attribute 'lower'
======================== 2 failed, 321 passed in 54.98s ========================
Error: Process completed with exit code 1.

@thejedi433

Copy link
Copy Markdown
Contributor Author

Fixed both failing tests and pushed. The CI should pass now.

@gabfl
gabfl merged commit 21371bb into gabfl:main Aug 31, 2026
4 checks passed
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