test: add edge-case tests for FileIdentity#3076
Open
invo-coder19 wants to merge 1 commit intometabrainz:masterfrom
Open
test: add edge-case tests for FileIdentity#3076invo-coder19 wants to merge 1 commit intometabrainz:masterfrom
invo-coder19 wants to merge 1 commit intometabrainz:masterfrom
Conversation
Expand test/test_file_identity.py with 10 new tests targeting uncovered branches in FileIdentity.__eq__ and FileIdentity.__init__: - test_both_missing_equal: verifies two identities for a non-existent path are equal (the 'both non-existent => equal' branch) - test_eq_with_non_fileidentity_raises: documents that comparing with an unrelated object raises AttributeError (no isinstance guard) - test_hash_none_at_init_computed_lazily_during_eq: exercises the lazy hash-computation path (lines 187-190 of file.py) using unittest.mock - test_identity_empty_file_equal: equality for 0-byte files - test_fast_hash_empty_file: _fast_hash returns a stable hex string for an empty file - test_identity_filepath_stored_as_path: _filepath is a pathlib.Path - test_identity_symlink_same_as_target: symlink and target share inode, so they compare equal (Unix only) - test_identity_symlink_after_retarget_not_equal: retargeted symlink detects a different inode (Unix only) - test_windows_inode_zero_same_file_equal: on Windows st_ino==0, equality falls through to size/mtime/hash (Windows only) - test_windows_inode_zero_different_files_same_size_not_equal: hash distinguishes two different files when inode is always 0 (Windows only) New imports: pathlib.Path, unittest.mock.patch All platform-specific tests are gated with @unittest.skipIf/skipUnless.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Expand test/test_file_identity.py by adding 10 new tests that cover currently uncovered branches in FileIdentity.eq and FileIdentity.init.
Add the following tests:
1.test_both_missing_equal
Verifies that two FileIdentity instances created for a non-existent path compare as equal. This covers the branch where both files do not exist → considered equal.
2.test_eq_with_non_fileidentity_raises
Confirms that comparing a FileIdentity instance with an unrelated object raises an AttributeError, since the implementation does not include an isinstance guard.
3.test_hash_none_at_init_computed_lazily_during_eq
Tests the lazy hash computation path (lines 187–190 in file.py).
Use unittest.mock to ensure the hash is calculated only when equality comparison occurs.
4.test_identity_empty_file_equal
Ensures that two identities representing empty (0-byte) files compare as equal.
5.test_fast_hash_empty_file
Verifies that _fast_hash produces a stable hexadecimal hash string for an empty file.
6.test_identity_filepath_stored_as_path
Confirms that the _filepath attribute is stored as a pathlib.Path object, not a plain string.
7.test_identity_symlink_same_as_target (Unix only)
Checks that a symlink and its target compare as equal because they share the same inode.
8.test_identity_symlink_after_retarget_not_equal (Unix only)
Ensures that if a symlink is retargeted to a different file, the resulting identities are not equal due to the changed inode.
9.test_windows_inode_zero_same_file_equal (Windows only)
On Windows, where st_ino == 0, verifies that equality falls back to file size, modification time, and hash, allowing two identities of the same file to compare as equal.
10.test_windows_inode_zero_different_files_same_size_not_equal (Windows only)
Ensures that when inode values are always 0, the hash comparison correctly distinguishes two different files that happen to have the same size.