Skip to content

Conversation

@C-Achard
Copy link
Collaborator

Expanded testing suite, addressing some missing coverage. Adds coverage reporting to the CI.

  • Focuses on core functionalities testing, and avoids redundancy with main DLC codebase (but pends further centralization)

  • Minor fixes of some missing attributes.

  • Flags code duplication from main DLC codebase (may not be exhaustive yet)

  • Remove CI changes for now

NOTE : Contains some CI/pre-commit changes, these can be removed before targeting main if we want them in a separate PR (but they will be used for formatting)


This pull request introduces a pre-commit configuration and makes a series of code quality, formatting, and workflow improvements, particularly targeting the dlclive/core/inferenceutils.py module and the GitHub Actions testing workflow. The changes focus on code consistency, improved warnings, and enhanced test coverage reporting.

Workflow and Testing Improvements

  • Upgraded the actions/checkout step in .github/workflows/testing.yml from v4 to v6 and removed the --no-cache flag from uv sync to streamline dependency installation. [1] [2]
  • Reorganized test steps: renamed and split test jobs, added coverage reporting using Codecov, and appended coverage summaries to the GitHub Actions job summary.

Code Quality and Formatting

  • Introduced a .pre-commit-config.yaml file to enforce code style and linting using pre-commit hooks (docstring checks, EOF fixer, trailing whitespace, setup-cfg formatting, and Ruff for linting/formatting).
  • Applied various formatting cleanups and line simplifications throughout dlclive/core/inferenceutils.py (e.g., single-line comprehensions, compact function calls, and more concise warnings). [1] [2] [3] [4] [5] [6] [7] [8] [9]

Behavioral and Compatibility Adjustments

  • Added strict=False to zip() calls and dictionary constructions to ensure compatibility with Python 3.10+ and prevent errors when input iterables are of different lengths. [1] [2] [3] [4] [5]
  • Improved warning messages by adding stacklevel=2 for better traceability of the warning origin. [1] [2] [3]

Documentation and Typing

  • Added a note at the top of dlclive/core/inferenceutils.py indicating that the file is duplicated from the original DeepLabCut codebase.
  • Minor typing updates, such as changing Position from Tuple[float, float] to tuple[float, float] and updating imports to use collections.abc.Iterable. [1] [2]

Introduces .pre-commit-config.yaml to automate code formatting, linting, and basic checks using pre-commit hooks for improved code quality and consistency.
Upgraded GitHub Actions to use newer versions and improved test steps by separating model benchmark and unit tests, adding coverage reporting with codecov. Added pytest-cov to dev dependencies and configured Ruff linter settings in pyproject.toml.
Introduces detailed unit tests for the Assembler, Assembly, Joint, and Link classes in dlclive.core.inferenceutils. The new tests cover metadata parsing, detection flattening, link extraction, assembly building, Mahalanobis distance calculation, I/O helpers, and various Assembly operations, improving test coverage and reliability.
Corrects color sampling in Display to avoid zero step and ensures image is always defined in display_frame. Adds comprehensive tests for Display, including headless environment setup, frame display, cutoff logic, window destruction, and color sampling safety.
Removed the --no-cache flag from 'uv sync' in the testing workflow, enhanced pytest coverage reporting, and added a step to summarize coverage in the GitHub Actions job summary. Added a note in dynamic_cropping.py about duplication with another file and referenced existing tests.
Introduces a new 'pose' attribute to the DLCLive class, initialized as None or a numpy ndarray. This prepares the class for storing pose data.
@C-Achard C-Achard self-assigned this Jan 30, 2026
@C-Achard C-Achard added enhancement New feature or request DLC 3.0 🔥 labels Jan 30, 2026
@C-Achard C-Achard marked this pull request as draft January 30, 2026 17:10
Copy link
Collaborator

@sneakers-the-rat sneakers-the-rat left a comment

Choose a reason for hiding this comment

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

Love it love it. We love tests. We love linting. I dont know too much about the code under test but gave a quick skim

return frame


def simple_two_label_scene():
Copy link
Collaborator

Choose a reason for hiding this comment

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

These helpers might be nice to have as fixtures :)

assert "confidence" in asm[0]
assert "costs" in asm[0]

# empty() convenience
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe a separate test? Is empty related to the above parsing behavior?

# --------------------------------------------------------------------------------------


def test_build_assemblies_from_links():
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes yes as you go, if you put the repeated setup steps in fixtures, then the test bodies can contain only the behavior under test. You can parameterize the fixtures by making them closures (function that returns a function) or with pytest's indirect fixture parameterization :)

a2.add_link(l23)

# now they share NO joints → addition should succeed
result = a1 + a2
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh this is a nice behavior!


# now purposely make them share a joint → should raise
a2.add_joint(j0)
with pytest.raises(ArithmeticError):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Haha love the error category choice

pose = np.array([[[5, 5, 0.9]]])

disp.display_frame(frame, pose)
disp.destroy()
Copy link
Collaborator

Choose a reason for hiding this comment

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

These get a little circular, if youre testing that a method is called, you can do so without later risking youre just testing your mocked classes using the MagicMocks and expectations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DLC 3.0 🔥 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants