Skip to content

Simplify the Features infrastructure and add AnnotatorManager#96

Merged
cmalinmayor merged 34 commits into2-feature-infrastructurefrom
94-features-refactor
Oct 23, 2025
Merged

Simplify the Features infrastructure and add AnnotatorManager#96
cmalinmayor merged 34 commits into2-feature-infrastructurefrom
94-features-refactor

Conversation

@cmalinmayor
Copy link
Copy Markdown
Contributor

Closes #94

This comprehensive refactor improves test maintainability and reduces code
duplication across the test suite while maintaining 100% test coverage
(181 tests passing).

## Test Infrastructure Improvements

### Added Feature Constants (conftest.py)
- FEATURES_WITH_SEG = ["pos", "area", "iou"]
- FEATURES_NO_SEG = ["pos"]
- SOLUTION_FEATURES_WITH_SEG = ["pos", "area", "iou", "tracklet_id"]
- SOLUTION_FEATURES_NO_SEG = ["pos", "tracklet_id"]
- Ensures consistency across all test files and eliminates magic lists

### Added Factory Fixtures
- get_tracks(ndim, with_seg, is_solution): Unified tracks creation
  - Automatically selects correct graph and segmentation fixtures
  - Automatically applies appropriate feature constants
  - Deep copies graphs to prevent fixture pollution
- get_graph(ndim, with_features): Simplified graph selection
  - with_features options: "clean", "position", "computed"
  - Eliminates 15+ instances of manual graph fixture selection
- get_segmentation(ndim): Simplified segmentation selection
  - Eliminates 12+ instances of conditional segmentation logic

## Test File Updates

### Refactored with Factory Fixtures
- All action tests (test_add_delete_edge, test_add_delete_nodes, etc.)
- All annotator tests (43 tests across 4 test files)
- All user action tests
- Import/export tests (test_export_to_geff, test_internal_format)
- Data model tests (test_solution_tracks, test_tracks)

### Code Patterns Eliminated
- "seg = segmentation_2d if ndim == 3 else segmentation_3d" (12+ instances)
- Manual graph fixture selection based on ndim (15+ instances)
- Inconsistent existing_features specifications

## Source Code Changes
- Fixed edge case in add_delete_edge.py for proper edge removal handling
- Added validation in add_delete_node.py for node attribute consistency

## Impact
- Improved test readability and maintainability
- Reduced code duplication by ~100 lines
- Centralized test configuration in conftest.py
- Easier to add new tests following established patterns
- All 181 tests passing, 6 skipped (intentional)
Refactor test suite with factory fixtures and feature constants
@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 23, 2025

Codecov Report

❌ Patch coverage is 92.10526% with 27 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.59%. Comparing base (2e708b4) to head (a4613aa).
⚠️ Report is 55 commits behind head on 2-feature-infrastructure.

Files with missing lines Patch % Lines
src/funtracks/annotators/_annotator_manager.py 94.11% 5 Missing ⚠️
src/funtracks/annotators/_track_annotator.py 75.00% 5 Missing ⚠️
src/funtracks/data_model/tracks.py 83.87% 5 Missing ⚠️
src/funtracks/annotators/_edge_annotator.py 85.00% 3 Missing ⚠️
src/funtracks/annotators/_regionprops_annotator.py 92.10% 3 Missing ⚠️
src/funtracks/import_export/export_to_geff.py 78.57% 3 Missing ⚠️
src/funtracks/actions/add_delete_node.py 85.71% 1 Missing ⚠️
src/funtracks/features/_regionprops_features.py 90.90% 1 Missing ⚠️
src/funtracks/import_export/import_from_geff.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@                     Coverage Diff                      @@
##           2-feature-infrastructure      #96      +/-   ##
============================================================
- Coverage                     91.37%   90.59%   -0.79%     
============================================================
  Files                            35       39       +4     
  Lines                          1554     1659     +105     
============================================================
+ Hits                           1420     1503      +83     
- Misses                          134      156      +22     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cmalinmayor cmalinmayor merged commit 073d659 into 2-feature-infrastructure Oct 23, 2025
14 of 15 checks passed
@cmalinmayor cmalinmayor deleted the 94-features-refactor branch October 23, 2025 17:37
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.

1 participant