Skip to content

Conversation

@C-Achard
Copy link
Collaborator

@C-Achard C-Achard commented Jan 30, 2026

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)

    • Comprehensive tests for some core modules, including Assembler/Assembly
    • Introduces hypothesis-based testing to improve utility and robustness of tests
  • 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 includes several improvements and updates across the codebase and CI configuration. The main themes are: adding pre-commit hooks for code quality, updating the test workflow and coverage reporting, and refactoring the dlclive/core/inferenceutils.py file for code clarity and modern Python standards.

Continuous Integration and Code Quality:

  • Added a .pre-commit-config.yaml file to configure pre-commit hooks for docstring checks, whitespace cleanup, setup.cfg formatting, and Ruff linter/formatter.
  • Updated the GitHub Actions workflow in .github/workflows/testing.yml to use newer action versions, streamline dependency installation, and add code coverage reporting with Codecov. [1] [2] [3]

Refactoring and Modernization of dlclive/core/inferenceutils.py:

  • Replaced deprecated or less strict built-in types and zip behavior with Python 3.10+ features (e.g., tuple[float, float] instead of Tuple[float, float], zip(..., strict=False) for safer iteration). [1] [2] [3] [4] [5] [6] [7]
  • Simplified and reformatted warning messages to use the stacklevel parameter for better tracebacks and improved readability of multi-line code blocks. [1] [2] [3]
  • Refactored several code blocks to use more compact and readable list comprehensions and function calls, reducing code duplication and improving maintainability. [1] [2] [3] [4] [5] [6] [7] [8] [9]

Documentation and Comments:

  • Added a note at the top of dlclive/core/inferenceutils.py indicating that the file is a duplicate of the original DeepLabCut codebase, with author and date.

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

Move test helpers into tests/conftest.py and introduce a suite of reusable pytest fixtures for assembler testing (headless_display_env, assembler graph/paf fixtures, scene factories, assembler/assembly/joint/link factories, and various canned dataset variants). Refactor tests/tests_core/test_assembler.py and tests/tests_core/test_assembly.py to consume the new fixtures, remove duplicated setup code, and simplify assertions. Also adjust serialization test filenames and tidy up identity/affinity-related test logic.
Replace handcrafted FakeTk/Label/PhotoImage classes with unittest.mock MagicMocks in the headless_display_env fixture. The fixture now returns a SimpleNamespace with mock constructors/instances (tk, label, photo) and sets display module attributes with monkeypatch (raising=False). Update tests to use the env mocks, assert on mock calls (title, pack, configure, update, destroy), mock ImageDraw.Draw with a MagicMock, and make colormap sampling deterministic for assertions. This simplifies test setup and enables precise call-based assertions instead of inspecting custom fake object state.
Replace tuple-based assembler fixtures with SimpleNamespace objects (providing .data, .graph, .paf_inds) and update all tests to access those attributes. Add Hypothesis to dev dependencies and introduce property-based tests for Assembly (from_array invariants and extent/area checks)
Introduce property-based tests for assembler utilities using Hypothesis: add test_condensed_index_properties for _conv_square_to_condensed_indices, a composite coords_and_conf strategy, test_flatten_detections_counts to validate _flatten_detections output counts, and a property test for extract_best_links (greedy) that asserts affinity, confidence-product (pcutoff) and disjointness invariants. Add Hypothesis imports, settings and numpy-array strategies. Also adjust test_assembly to ensure rows containing any NaN are set fully to NaN so the test matches Assembly.from_array behavior.
@C-Achard
Copy link
Collaborator Author

C-Achard commented Feb 2, 2026

Thanks again @sneakers-the-rat for the feedback, I've tried to integrate it best as I could. I also checked out other tools to help with robustness such as hypothesis, which I think integrates nicely here.
(Also I may have gone a bit overboard in the fixtures with SimpleNamespace, I like the dot access syntax but not sure if it's more readable as a result ?)

@C-Achard C-Achard marked this pull request as ready for review February 2, 2026 14:47
@C-Achard C-Achard requested a review from deruyter92 February 2, 2026 14:49
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