Skip to content

Conversation

@Kahreiru
Copy link
Collaborator

@Kahreiru Kahreiru commented Oct 16, 2025

Summary by Sourcery

Introduce a comprehensive suite of pytest tests for the AutoSegmentation module’s view widgets, model workflows, database persistence, style sheet reader, view state management, and data filtering utilities, while refactoring core classes to improve testability and robustness.

New Features:

  • Add extensive tests for SegmentSelectorWidget selection behaviors and tree interactions
  • Add tests for AutoSegmentation workflow including DICOM file handling, segmentation execution, conversion, and cleanup
  • Add tests for SavedSegmentDatabase CRUD operations, feedback callbacks, and error handling
  • Add tests for StyleSheetReader platform-specific stylesheet loading, reading, caching, and error cases
  • Add tests for AutoSegmentViewState callback registration and button invocation logic
  • Add tests for SegmentationListFilter filtering logic and read_csv_to_pandas handling of edge cases
  • Add tests for ButtonInputBox positive/negative actions and UI property validations

Bug Fixes:

  • Allow SegmentSelectorWidget methods to accept integer check states and default segmentation list to empty
  • Guard ButtonInputBox positive/negative actions against missing callbacks
  • Fix SegmentationListFilter empty filter_values logic and simplify DataFrame returns

Enhancements:

  • Refactor SegmentSelectorWidget init signature and remove unused parent argument
  • Streamline SegmentationListFilter with contextlib.suppress and concise conditional returns

Tests:

  • Cover all new tests added for views, models, database, styling, view state, filtering, and input box behavior

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 16, 2025

Reviewer's Guide

This PR introduces a comprehensive suite of unit tests across the AutoSegmentation feature set and adjusts several components to improve testability, including parameter handling in widgets and simplification of filtering logic.

Class diagram for updated SegmentSelectorWidget

classDiagram
class SegmentSelectorWidget {
    +__init__(segmentation_list: list[str] = None, data_location: str = "data/csv", update_callback: Callable[[], None] | None = None)
    -_selected_list: list[str]
    -_tree_choices_ref: dict[str, list[QTreeWidgetItem]]
    +_selected_list_add_or_remove(body_text: str, state: Qt.CheckState | int)
    +_uniform_selection(check: Qt.CheckState | int)
    +_child_states(item: QTreeWidgetItem, body_text: str)
}
SegmentSelectorWidget --|> QtWidgets.QWidget
Loading

Class diagram for updated ButtonInputBox

classDiagram
class ButtonInputBox {
    -_send: Callable[[str], None] | None
    -_close: Callable[[], None] | None
    -text: QtWidgets.QLineEdit | None
    -delete_word: str | None
    -typed_text: str | None
    +_positive_action()
    +_negative_action()
}
Loading

Class diagram for updated SegmentationListFilter functions

classDiagram
class SegmentationListFilter {
    +_dict_row_filter(data: pandas.DataFrame, csv_column: str = None, filter_values: dict | list | None = None) pandas.DataFrame
    +_column_filter(data: pandas.DataFrame, column_list: list[str]) pandas.DataFrame
    +_strip_whitespace(data: pandas.DataFrame) pandas.DataFrame
}
Loading

Class diagram for updated AutoSegmentWindow

classDiagram
class AutoSegmentWindow {
    +__init__(view_state: AutoSegmentViewState)
    -_view_state: AutoSegmentViewState
    -_tree_selector: SegmentSelectorWidget
    -_start_button: QtWidgets.QPushButton
    -_progress_text: QtWidgets.QTextEdit
}
AutoSegmentWindow --|> QtWidgets.QWidget
AutoSegmentWindow o-- SegmentSelectorWidget
Loading

File-Level Changes

Change Details Files
Enhanced SegmentSelectorWidget for better testability and flexible state handling
  • Removed parent parameter and defaulted segmentation_list to None
  • Initialized _selected_list to an empty list when no initial list provided
  • Allowed _selected_list_add_or_remove and _uniform_selection to accept int values and map them to Qt.CheckState
  • Added explicit type annotation for _child_states and removed unnecessary super init argument
src/View/AutoSegmentation/SegmentSelectorWidget.py
src/View/AutoSegmentation/AutoSegmentWindow.py
Guarded ButtonInputBox callbacks to handle None safely
  • Wrapped _send invocation in _positive_action with a None check and return None if missing
  • Wrapped _close invocation in _negative_action with a None check
src/View/AutoSegmentation/ButtonInputBox.py
Refactored SegmentationListFilter to streamline filtering logic
  • Replaced explicit None checks with truthiness for filter_values
  • Used contextlib.suppress to ignore missing columns in _column_filter
  • Simplified return logic to default to original DataFrame when no output columns
src/Model/AutoSegmentation/SegmentationListFilter.py
Added end-to-end unit tests covering views, workflows, and utilities
  • Created tests for segment selection widget behaviors and state transitions
  • Added model tests for AutoSegmentation workflow, error handling, and DICOM file operations
  • Implemented database tests for SavedSegmentDatabase CRUD and feedback mechanisms
  • Covered utility classes StyleSheetReader, AutoSegmentViewState, and filter functions
  • Added tests for ButtonInputBox positive/negative actions and UI properties
test/AutoSegment/test_view_segment_selector.py
test/AutoSegment/test_autosegment_model.py
test/AutoSegment/test_saved_segment_database.py
test/test_stylesheet_reader.py
test/AutoSegment/test_autosegment_view_state.py
test/AutoSegment/test_autosegment_list_filter.py
test/AutoSegment/test_button_input_box.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@Kahreiru Kahreiru closed this Oct 16, 2025
@Kahreiru Kahreiru deleted the tests branch October 16, 2025 08:36
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