Skip to content

Conversation

@Kahreiru
Copy link
Collaborator

@Kahreiru Kahreiru commented Oct 20, 2025

Fixing the Segfault issue it appears to be a legacy issue which somehow didn't show up in

  • test_stuctures_tab.py
    Where the tests create a MainWindow() object call .show() on it but never close it resulting in a segfault then the open window inevitably gets garbage collected.

Summary by Sourcery

Fix segfault in GUI tests by ensuring windows are closed and garbage collected, refactor UI components for better testability, correct filtering logic, and add extensive unit tests across modules

Bug Fixes:

  • Close and cleanup MainWindow in tests to prevent segfaults
  • Guard ButtonInputBox actions to safely handle missing callbacks
  • Correct handling of empty or falsy filter values in SegmentationListFilter

Enhancements:

  • Refactor SegmentSelectorWidget to remove parent constructor parameter and initialize selected list by default
  • Allow integer check state inputs in SegmentSelectorWidget methods for easier testing
  • Remove redundant parent argument in AutoSegmentWindow instantiation
  • Simplify column filtering logic in SegmentationListFilter

Tests:

  • Add comprehensive unit tests for SegmentSelectorWidget
  • Add tests for AutoSegmentation model workflow and error handling
  • Introduce tests for SavedSegmentDatabase CRUD operations and feedback
  • Expand tests for StyleSheetReader, AutoSegmentationController, AutoSegmentViewState, and SegmentationListFilter
  • Add tests for ButtonInputBox behavior under various configurations

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 20, 2025

Reviewer's Guide

Refactors widget initialization and state management to remove parent dependencies and improve test isolation, adds safe callback guards in dialogs, streamlines data‐filter logic, updates GUI test fixtures to properly close windows and extends overall test coverage with new module tests.

Class diagram for updated SegmentSelectorWidget initialization and state management

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)
}
SegmentSelectorWidget --|> QtWidgets.QWidget
Loading

Class diagram for updated ButtonInputBox safe callback guards

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

Class diagram for updated SegmentationListFilter data-filter logic

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

File-Level Changes

Change Details Files
Refactored SegmentSelectorWidget init and state methods for parent-free instantiation and flexible state handling
  • Removed parent parameter and updated constructor signature with default segmentation_list
  • Initialized _selected_list to an empty list when None is passed
  • Changed super() call to no-arg, removed parent reference
  • Updated _selected_list_add_or_remove and _uniform_selection to accept int or Qt.CheckState and normalize values
src/View/AutoSegmentation/SegmentSelectorWidget.py
src/View/AutoSegmentation/AutoSegmentWindow.py
Added null checks around ButtonInputBox callbacks to prevent missing callback errors
  • Guard _send invocation in _positive_action and return None if absent
  • Guard _close invocation in _negative_action and return None if absent
src/View/AutoSegmentation/ButtonInputBox.py
Streamlined SegmentationListFilter row/column filtering logic
  • Simplified filter_values check using truthiness
  • Replaced try/finally with contextlib.suppress to ignore missing columns
  • Unified output DataFrame return condition
src/Model/AutoSegmentation/SegmentationListFilter.py
Fixed GUI test fixtures to properly close windows and avoid segfaults
  • Changed fixture scope to module and switched to yield for teardown
  • Called main_window.close(), cleared references and invoked gc.collect()
  • Updated test_model_configuration SQL insert ID and error fixture context
test/test_view_structures_tab.py
test/test_model_configuration.py
Expanded and enhanced test coverage across core modules
  • Added end-to-end tests for SegmentSelectorWidget behavior
  • Introduced comprehensive tests for AutoSegmentation, SavedSegmentDatabase, controller and view state
  • Covered StyleSheetReader, SegmentationListFilter and ButtonInputBox edge cases
test/test_view_segment_selector.py
test/test_autosegment_model.py
test/test_saved_segment_database.py
test/test_stylesheet_reader.py
test/test_autosegment_controller.py
test/test_autosegment_view_state.py
test/test_autosegment_list_filter.py
test/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 20, 2025
@Kahreiru Kahreiru reopened this Oct 20, 2025
@Kahreiru Kahreiru closed this Oct 20, 2025
@Kahreiru Kahreiru deleted the fixingSegFault branch October 20, 2025 04:40
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