Skip to content

Add comprehensive thread-worker unit coverage; harden CSVImportThread ROI field/NaN handling - #209

Merged
tkswanson merged 4 commits into
devfrom
copilot/add-unit-tests-for-thread-workers
Aug 28, 2026
Merged

Add comprehensive thread-worker unit coverage; harden CSVImportThread ROI field/NaN handling#209
tkswanson merged 4 commits into
devfrom
copilot/add-unit-tests-for-thread-workers

Conversation

Copilot AI commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

This PR adds focused unit coverage for previously untested thread workers under matchypatchy/threads, with priority on import_thread.py and animl_thread.py. While building the tests, it also addresses two CSV import edge cases surfaced by coverage (ROI field access mode mismatch and favorite/individual null handling).

  • Import thread test suite (tests/test_threads/test_import_thread.py)
    • Adds class-based tests for:
      • CSVMigrateThread: required-column validation, row processing, ref-dict caching, missing-file skip/error collection, interruption/finish behavior.
      • CSVImportThread: common base-dir detection, filepath grouping behavior, old (bbox1-4) and new (bbox_x/y/w/h) bbox formats, value conversion with None/NaN, ROI/media thumbnail persistence, interruption/finish behavior.
      • FolderImportThread: station/camera extraction by path index, default station creation (station_level=0), interruption and finish semantics.
      • BasePathUpdateThread: update_base_dir invocation semantics and progress/finished signal behavior.
  • ANIML thread test suite (tests/test_threads/test_animl_thread.py)
    • Adds class-based tests for:
      • BuildManifestThread: manifest build call contract and manifest signal payload.
      • VerifyNewBaseDirsThread: hash-diff logic across update tuples and not_in_db / not_in_new_directory / finished signaling.
      • AnimlThread: initialization from DB state, image/video detection flows, ROI bbox updates for unresolved ROIs, thumbnail saves, progress/prompt signaling, detector=None behavior, interruption handling.
  • Test runtime support
    • Extends tests/conftest.py with minimal QThread/pyqtSignal stubs to reliably exercise worker run() paths in headless unit tests.
  • Targeted production hardening in CSVImportThread
    • Adds _roi_value() to support ROI extraction when selected columns are passed as either names or positional indices.
    • Normalizes null semantics:
      • favorite now defaults to 0 when conversion yields None.
      • individual() now returns None for missing/NaN names instead of attempting DB lookup/insert.
def _roi_value(self, roi, column):
    if column == "None" or column is None:
        return None
    if isinstance(column, int):
        return roi[column]
    return getattr(roi, column, None)

def favorite(self, roi):
    if self.selected_columns["favorite"] != "None":
        favorite = self._convert_to_int(self._roi_value(roi, self.selected_columns["favorite"]))
        return favorite if favorite is not None else 0
    return 0

Co-authored-by: tkswanson <4371698+tkswanson@users.noreply.github.com>
Copilot AI changed the title [WIP] Add comprehensive unit tests for matchypatchy thread workers Add comprehensive thread-worker unit coverage; harden CSVImportThread ROI field/NaN handling Aug 28, 2026
Copilot AI requested a review from tkswanson August 28, 2026 19:41
@tkswanson
tkswanson marked this pull request as ready for review August 28, 2026 22:18
Co-authored-by: tkswanson <4371698+tkswanson@users.noreply.github.com>
@tkswanson
tkswanson changed the base branch from main to dev August 28, 2026 22:43
@tkswanson
tkswanson changed the base branch from dev to documentation August 28, 2026 23:16
@tkswanson
tkswanson changed the base branch from documentation to dev August 28, 2026 23:16
@tkswanson
tkswanson merged commit 2438816 into dev Aug 28, 2026
0 of 2 checks passed
@tkswanson
tkswanson deleted the copilot/add-unit-tests-for-thread-workers branch August 28, 2026 23:18
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.

2 participants