Add unit tests for pipeline.py + fix broken export.py import#259
Merged
Conversation
… error Agent-Logs-Url: https://github.com/conservationtechlab/animl-py/sessions/fd0f522d-2312-44d4-8650-05a866237219 Co-authored-by: tkswanson <4371698+tkswanson@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add comprehensive unittest file for pipeline functions
Add unit tests for pipeline.py + fix broken export.py import
Apr 6, 2026
Agent-Logs-Url: https://github.com/conservationtechlab/animl-py/sessions/4615a4dd-240f-43f2-ae46-2b98ef05132c Co-authored-by: tkswanson <4371698+tkswanson@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
src/animl/export.pytests/test_pipeline.py(29 tests)tests/test_split.py(46 tests) coveringget_animals,get_empty,train_val_testOriginal prompt
Task
Create a comprehensive unittest file at
tests/test_pipeline.pyon thedevbranch forsrc/animl/pipeline.py.Source file to test
src/animl/pipeline.pycontains two public functions:from_paths(image_dir, detector_file, classifier_file, classlist_file, ...)from_config(config)Both functions are orchestration pipelines that call many submodules. All submodule calls must be mocked — do not load real models or real images.
Key dependencies to mock
All of the following must be patched in tests (patch target is the
animl.pipelinenamespace):animl.pipeline.file_management.WorkingDirectoryaniml.pipeline.file_management.build_file_manifestaniml.pipeline.file_management.check_fileaniml.pipeline.file_management.load_dataaniml.pipeline.file_management.save_dataaniml.pipeline.video_processing.extract_framesaniml.pipeline.detection.load_detectoraniml.pipeline.detection.detectaniml.pipeline.detection.parse_detectionsaniml.pipeline.split.get_animalsaniml.pipeline.split.get_emptyaniml.pipeline.classification.load_classifieraniml.pipeline.classification.classifyaniml.pipeline.classification.single_classificationaniml.pipeline.classification.sequence_classificationaniml.pipeline.export.export_foldersaniml.pipeline.visualization.plot_all_bounding_boxesWorkingDirectory mock setup
The
WorkingDirectorymock must have these attributes set asMagicMock()orPath-like objects:filemanifestimageframesdetectionsmdrawpredictionsresultslinkdirvisdirTest data setup (setUpClass)
Create shared test fixtures:
from_pathstests — classTestFromPathsWrite tests using
unittest.mock.patchas context managers or decorators. For each test, mock all dependencies listed above. Thecheck_filemock should returnFalseby default (simulate no cached files).Tests to write:
test_returns_dataframe— returns a pd.DataFrametest_calls_build_file_manifest—build_file_manifestis called oncetest_calls_extract_frames—video_processing.extract_framesis called oncetest_calls_load_detector_for_pt_file—load_detectorcalled withmodel_type="mdv5"for.ptfiletest_calls_load_detector_for_onnx_file—load_detectorcalled with"onnx"for.onnxdetector file. Create a separatedetector_onnxpath for this.test_calls_detect—detection.detectis called oncetest_calls_parse_detections—detection.parse_detectionsis called oncetest_calls_load_classifier—classification.load_classifieris called oncetest_calls_classify—classification.classifyis called oncetest_single_classification_called_by_default—single_classificationcalled whensequence=Falsetest_sequence_classification_called_when_flag_set—sequence_classificationcalled whensequence=Truetest_detect_only_returns_early— whendetect_only=True, returns detections df without calling classifiertest_sort_calls_export_folders— whensort=True,export.export_foldersis calledtest_sort_false_does_not_call_export— whensort=False,export.export_foldersnot calledtest_visualize_calls_plot_bounding_boxes— whenvisualize=True,visualization.plot_all_bounding_boxescalledtest_visualize_false_does_not_plot— whenvisualize=False, plot function not calledtest_save_data_called—file_management.save_datais called once with the final manifesttest_uses_cached_detections_when_check_file_true— whencheck_filereturnsTruefor detections,load_datais called anddetectis NOT calledtest_missing_image_dir_raises— patchWorkingDirectoryto raiseFileNotFoundError, assert it propagatesfrom_configtests — classTestFromConfigCreate a helper `_write_config(tmp...
This pull request was created from Copilot chat.