Skip to content
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

Provide a generic load_poses.from_file() function #107 #110

Merged
merged 14 commits into from
Feb 19, 2024

Conversation

DhruvSkyy
Copy link
Collaborator

@DhruvSkyy DhruvSkyy commented Feb 1, 2024

Description

What is this PR

Creates a generic function from_file() which is identical to:

  • from_dlc_file()
  • from_sleap_file()
  • from_lp_file()

Can be called by specifying source software,

def from_file(
    file_path: Union[Path, str],
    source_software: Literal["DeepLabCut", "SLEAP", "LightningPose"],
    fps: Optional[float] = None
  • Bug fix
  • Addition of a new feature
  • Other

References

Closes #98

Checklist:

  • The code has been tested locally
  • Tests have been added to cover all new functionality
  • The documentation has been updated to reflect any changes
  • The code has been formatted with pre-commit

Copy link

codecov bot commented Feb 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (9ee30c7) 99.12% compared to head (33e09ed) 99.13%.
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #110   +/-   ##
=======================================
  Coverage   99.12%   99.13%           
=======================================
  Files           8        8           
  Lines         458      461    +3     
=======================================
+ Hits          454      457    +3     
  Misses          4        4           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@niksirbi niksirbi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this @DhruvSkyy!

I've left a few comments, but apart from these, let's discuss testing.

When it comes to testing a function like from_file that delegates its operations to other functions (from_dlc_file, from_sleap_file, from_lp_file), which are already thoroughly tested, our primary goal should be to ensure that the delegation logic is correct without necessarily re-testing the functionality of the underlying functions in depth.

I would probably add one more function to the TestLoadPoses class, doing sth akin to the following:

    @pytest.mark.parametrize(
        "source_software",
        ["SLEAP", "DeepLabCut", "LightningPose", "Unknown"]
    )
    @pytest.mark.parametrize("fps", [None, 30, 60.0])
    def test_from_file_delegates_correctly(self, source_software, fps):
        """Test that the from_file() function delegates to the correct
        loader function according to the source_software."""

        software_to_loader = {
            "SLEAP": "movement.io.load_poses.from_sleap_file",
            "DeepLabCut": "movement.io.load_poses.from_dlc_file",
            "LightningPose": "movement.io.load_poses.from_lp_file",
        }

        if source_software == "Unknown":
            with pytest.raises(ValueError):
                load_poses.from_file("some_file", source_software)
        else:
            with patch(software_to_loader[source_software]) as mock_loader:
                load_poses.from_file("some_file", source_software, fps)
                mock_loader.assert_called_with("some_file", fps)

The above test just ensures that the correct underlying loader is called with the right parameters passed to it. We do not actually want to call the underlying functions (because we have tested that already many times), that's why I've used mocking (pretend that we are calling them).

FYI, you would have to from unittest.mock import patch and you would also need to handle the case of unknown software in the implementation of from_file (see one of my comments).

movement/io/load_poses.py Outdated Show resolved Hide resolved
movement/io/load_poses.py Show resolved Hide resolved
movement/io/load_poses.py Outdated Show resolved Hide resolved
niksirbi and others added 2 commits February 7, 2024 10:52
* Bump action versions in upload_pypi workflow step

* reuse the upload_pypi action instead of custom steps
movement/io/load_poses.py Outdated Show resolved Hide resolved
Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Member

@niksirbi niksirbi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for implementing the suggestions @DhruvSkyy !!
I've updated the documentation accordingly. I'll approve and merge this PR now 🎉

@niksirbi niksirbi merged commit b4ec636 into neuroinformatics-unit:main Feb 19, 2024
15 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.

Provide a generic load_poses.from_file() function
2 participants