-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update backend filename when backend isn't created on replace #127
Conversation
WalkthroughThe changes in this pull request involve modifications to the Changes
Possibly related PRs
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
tests/model/test_video.py (1)
118-118
: LGTM! Consider adding more test cases.The new assertion correctly verifies that the
backend_metadata["filename"]
is updated when replacing the filename, even when the file doesn't exist. This aligns well with the PR objectives.To further strengthen the test coverage, consider adding the following test cases:
- Test replacing with an empty string filename.
- Test replacing with a filename containing special characters.
- Test replacing the filename multiple times in succession.
Example:
def test_video_replace_filename_edge_cases(): video = Video.from_filename("initial.mp4") # Test empty string video.replace_filename("") assert video.backend_metadata["filename"] == "" # Test special characters video.replace_filename("file with spaces!@#$.mp4") assert video.backend_metadata["filename"] == "file with spaces!@#$.mp4" # Test multiple replacements video.replace_filename("1.mp4") video.replace_filename("2.mp4") video.replace_filename("3.mp4") assert video.backend_metadata["filename"] == "3.mp4"These additional tests will help ensure the robustness of the
replace_filename
method across various scenarios.sleap_io/model/video.py (1)
Line range hint
1-324
: Ensure consistency across the Video classWhile the change in the
replace_filename
method improves the handling of backend metadata, it's important to ensure consistency across the entireVideo
class. Consider the following recommendations:
Add a test case that verifies the new behavior of
replace_filename
, especially when the backend isn't created.Review the
__attrs_post_init__
method (lines 62-71) to ensure it correctly handles the updatedbackend_metadata
. It might be worth considering whether to updatebackend_metadata["filename"]
here as well for consistency.Double-check the
open
method (lines 235-283) to confirm it interacts correctly with the updatedreplace_filename
method, especially in scenarios where the backend isn't initially created.To implement these suggestions, you might want to:
Add a new test in the appropriate test file (e.g.,
tests/model/test_video.py
) that covers the scenario of replacing a filename when the backend isn't created.Review and potentially update the
__attrs_post_init__
method:def __attrs_post_init__(self): """Post init syntactic sugar.""" self.backend_metadata["filename"] = self.filename # Add this line if self.open_backend and self.backend is None and self.exists(): try: self.open() except Exception as e: # If we can't open the backend, just ignore it for now so we don't # prevent the user from building the Video object entirely. pass
- Verify that the
open
method correctly handles the updatedbackend_metadata
:#!/bin/bash # Description: Check the interaction between open and replace_filename methods # Test: Search for usages of the open method in test files rg --type python 'def test.*:.*video.*open' tests/ # Test: Search for usages of the replace_filename method in test files rg --type python 'def test.*:.*replace_filename' tests/This script will help identify existing tests that might need to be updated or areas where new tests should be added to cover the interaction between
open
andreplace_filename
methods.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- sleap_io/model/video.py (1 hunks)
- tests/model/test_video.py (1 hunks)
🔇 Additional comments (2)
sleap_io/model/video.py (2)
Line range hint
1-324
: Summary and Final RecommendationThe change in the
replace_filename
method successfully addresses the PR objectives by updating the backend metadata when replacing the filename, even when the backend isn't created. This improvement enhances the consistency of the metadata and resolves the issue described in the PR summary.However, to ensure the robustness of this change and its integration with the rest of the
Video
class, I recommend the following actions:
- Implement the suggested minor improvement for consistency with list inputs in the
replace_filename
method.- Add new test cases to verify the updated behavior of
replace_filename
, especially when the backend isn't created.- Review and potentially update the
__attrs_post_init__
andopen
methods to ensure they work correctly with the changes inreplace_filename
.- Run the provided verification scripts to check for any unintended side effects in other parts of the codebase.
Once these recommendations are addressed, this PR should be ready for approval and merging.
Line range hint
309-324
: LGTM! Consider a minor improvement for consistency.The addition of
self.backend_metadata["filename"] = new_filename
addresses the PR objectives by ensuring that the backend metadata is updated when replacing the filename, even if the backend isn't created. This change improves the consistency of the metadata and resolves the issue described in the PR summary.A minor suggestion for improvement:
For consistency, consider updatingself.backend_metadata["filename"]
to always be a string, even whennew_filename
is a list. This ensures thatself.filename
andself.backend_metadata["filename"]
are always of the same type.self.backend_metadata["filename"] = new_filename if isinstance(new_filename, str) else new_filename[0]To ensure this change doesn't introduce any unintended side effects, please run the following verification script:
This script will help identify any other parts of the codebase that might need to be updated to accommodate this change.
✅ Verification successful
Filename Update Consistency Confirmed
The modification to
self.backend_metadata["filename"]
ensures consistency by updating it to a string, aligning with existing usages intests/model/test_video.py
andsleap_io/io/slp.py
. This change prevents potential mismatches and maintains the integrity of filename handling across the codebase.
- Affected Files:
tests/model/test_video.py
sleap_io/io/slp.py
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for any other usages of backend_metadata["filename"] that might be affected by this change. # Test: Search for usages of backend_metadata["filename"] rg --type python 'backend_metadata\["filename"\]' --glob '!sleap_io/model/video.py' # Test: Search for methods or functions that interact with the Video class and might be affected by this change rg --type python 'def.*Video' -g '!sleap_io/model/video.py'Length of output: 209
Script:
#!/bin/bash # Description: Check for any other usages of backend_metadata["filename"] that might be affected by this change. # Test: Search for usages of backend_metadata["filename"] rg --type py 'backend_metadata\["filename"\]' --glob '!sleap_io/model/video.py' # Test: Search for methods or functions that interact with the Video class and might be affected by this change rg --type py 'def .*Video' --glob '!sleap_io/model/video.py'Length of output: 950
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #127 +/- ##
=======================================
Coverage 96.38% 96.38%
=======================================
Files 15 15
Lines 2045 2046 +1
=======================================
+ Hits 1971 1972 +1
Misses 74 74 ☔ View full report in Codecov by Sentry. |
When using
Video.replace_filename
orLabels.replace_filenames
(which calls it), replacing the filename with one that doesn't exist will not create the backend.When the backend doesn't exist, saving to SLP defaults to using the
Video.backend_metadata
dictionary, which was previously not being overwritten with the backend data if the backend wasn't initialized.This PR updates the
"filename"
key in the backend whenever it's replaced.Summary by CodeRabbit
New Features
Bug Fixes
Refactor
replace_filename
method for better code structure.