-
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
Safer video loading from SLP #119
Changes from 3 commits
f314fe6
8c5bac3
d04fea5
b0af70f
8e179ca
e97cfff
c923ddc
0487ebc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -354,3 +354,12 @@ def test_embed_two_rounds(tmpdir, slp_real_data): | |
== "tests/data/videos/centered_pair_low_quality.mp4" | ||
) | ||
assert type(labels3.video.backend) == MediaVideo | ||
|
||
|
||
def test_lazy_video_read(slp_real_data): | ||
labels = read_labels(slp_real_data) | ||
assert type(labels.video.backend) == MediaVideo | ||
assert labels.video.exists() | ||
|
||
labels = read_labels(slp_real_data, open_videos=False) | ||
assert labels.video.backend is None | ||
Comment on lines
+360
to
+366
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enhance test coverage and improve type checking While the test function effectively verifies the behavior of the
Here's a suggested improvement: def test_lazy_video_read(slp_real_data):
# Test default behavior
labels = read_labels(slp_real_data)
assert isinstance(labels.video.backend, MediaVideo)
assert labels.video.exists()
# Test lazy loading behavior
lazy_labels = read_labels(slp_real_data, open_videos=False)
assert lazy_labels.video.backend is None
# Verify that labels are still correctly loaded
assert len(lazy_labels) == len(labels)
assert lazy_labels.skeleton == labels.skeleton
# Add more assertions to verify the integrity of lazy-loaded labels This refactored version improves type checking, clarifies the assertions, and adds a placeholder for additional verification of lazy-loaded labels. 🧰 Tools🪛 Ruff
|
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.
🛠️ Refactor suggestion
Use
isinstance()
for type checkingInstead of using
type(video.backend) == MediaVideo
, it's more pythonic and flexible to useisinstance()
for type checking. This allows for subclass comparisons and is the recommended approach in Python.Apply this change:
Make similar changes for other type checks in this function (e.g., for
HDF5Video
andImageVideo
).📝 Committable suggestion
🧰 Tools
🪛 Ruff