-
Notifications
You must be signed in to change notification settings - Fork 5
normalize feature cache subdir name; auto-rename legacy dirs #382
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,20 @@ | ||
| """JABS utilities""" | ||
|
|
||
| from .update_checker import check_for_update, is_pypi_install | ||
| from .utilities import get_bool_env_var, hash_file, hide_stderr, to_safe_name | ||
| from .utilities import ( | ||
| get_bool_env_var, | ||
| hash_file, | ||
| hide_stderr, | ||
| pose_file_stem, | ||
| to_safe_name, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "check_for_update", | ||
| "get_bool_env_var", | ||
| "hash_file", | ||
| "hide_stderr", | ||
| "is_pypi_install", | ||
| "pose_file_stem", | ||
| "to_safe_name", | ||
| ] |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| """Unit tests for jabs.core.utils.utilities module.""" | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from jabs.core.utils import pose_file_stem | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("path", "expected"), | ||
| [ | ||
| ("video_pose_est_v6.h5", "video"), | ||
| ("video_pose_est_v2.h5", "video"), | ||
| ("video_pose_est_v12.h5", "video"), | ||
| ("/some/dir/video_pose_est_v6.h5", "video"), | ||
| ("video.mp4", "video"), | ||
| ("video.avi", "video"), | ||
| ("nested_name_pose_est_v8.h5", "nested_name"), | ||
| ("no_suffix.h5", "no_suffix"), | ||
| ("plain_name", "plain_name"), | ||
| ], | ||
| ids=[ | ||
| "pose-v6", | ||
| "pose-v2", | ||
| "pose-v12", | ||
| "pose-with-dir", | ||
| "video-mp4", | ||
| "video-avi", | ||
| "nested-underscore-name", | ||
| "h5-no-pose-suffix", | ||
| "no-extension", | ||
| ], | ||
| ) | ||
| def test_pose_file_stem(path: str, expected: str) -> None: | ||
| """Pose-file suffix is stripped and other names are returned unchanged.""" | ||
| assert pose_file_stem(path) == expected | ||
|
|
||
|
|
||
| def test_pose_file_stem_accepts_path() -> None: | ||
| """``pathlib.Path`` inputs are supported.""" | ||
| assert pose_file_stem(Path("/a/b/video_pose_est_v6.h5")) == "video" | ||
|
|
||
|
|
||
| def test_pose_file_stem_video_and_pose_match() -> None: | ||
| """A video file and its matching pose file produce the same stem. | ||
|
|
||
| This is what guarantees feature-cache directories are consistent whether the | ||
| caller passes the pose file (jabs-classify, jabs-cli compute-features) or the | ||
| video file (jabs-init, GUI). | ||
| """ | ||
| assert pose_file_stem("video.mp4") == pose_file_stem("video_pose_est_v6.h5") |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| """Unit tests for jabs.scripts.classify helpers.""" | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from jabs.scripts.classify import _require_pose_file_name | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "name", | ||
| [ | ||
| "sample_pose_est_v2.h5", | ||
| "sample_pose_est_v6.h5", | ||
| "sample_pose_est_v12.h5", | ||
| "nested_name_pose_est_v8.h5", | ||
| ], | ||
| ) | ||
| def test_require_pose_file_name_accepts_canonical(name: str) -> None: | ||
| """Canonical ``*_pose_est_vN.h5`` filenames pass validation.""" | ||
| _require_pose_file_name(Path("/some/dir") / name) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "name", | ||
| [ | ||
| "sample.mp4", | ||
| "sample.h5", | ||
| "sample_v6.h5", | ||
| "sample_pose_est.h5", | ||
| "sample_pose_est_v6.hdf5", | ||
| "predictions_pose_est_v6.h5.bak", | ||
| ], | ||
| ) | ||
| def test_require_pose_file_name_rejects_invalid(name: str) -> None: | ||
| """Names that do not match ``*_pose_est_vN.h5`` are rejected.""" | ||
| with pytest.raises(ValueError, match="not a valid pose file path"): | ||
| _require_pose_file_name(Path(name)) |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.