populse_mia.tests.run_mia_test

This module is dedicated to populse_mia unit tests.

It defines the TestMIACase class, which serves as a base class for all unit test classes in the populse_mia project. This class provides common setup and teardown functionality, as well as utility methods to facilitate testing of Mia’s features.

Functions

add_to_syspath(path[, position, name])

Add a directory to sys.path if it exists and isn't already there.

qt_message_handler(mode, context, message)

Custom Qt message handler that filters out or cleans specific unwanted messages.

Classes

LogCapture()

Custom logging handler to capture log records for inspection during tests.

TestMIACase([methodName])

Parent class for the test classes of Mia.

TestMIADataBrowser([methodName])

Tests for the data browser tab (DataBrowser).

TestMIAMainWindow([methodName])

Tests for the main window class (MainWindow).

TestMIANodeController([methodName])

Tests for the node controller, part of the pipeline manager tab.

TestMIAPipelineEditor([methodName])

Tests for the pipeline editor, part of the pipeline manager tab.

TestMIAPipelineManagerTab([methodName])

Tests the pipeline manager tab class, part of the homonym tab.

Test_Z_MIAOthers([methodName])

Tests for other parts of the MIA software that do not relate much with the other classes.

populse_mia.tests.run_mia_test.add_to_syspath(path: Path, position: int = 1, name: str = '')[source]

Add a directory to sys.path if it exists and isn’t already there.

Parameters:
  • path – (Path) The directory path to be added to sys.path.

  • position – (int) The index at which to insert the path. Defaults to 1.

  • name – (str) The name of the package.

populse_mia.tests.run_mia_test.qt_message_handler(mode, context, message)[source]

Custom Qt message handler that filters out or cleans specific unwanted messages.

This function is used to suppress known, irrelevant Qt warnings during tests or execution. If a message exactly matches an unwanted message, it is ignored. If it contains an unwanted substring, that part is removed and the cleaned message is printed to stderr (if anything remains).

Parameters:
  • mode – The Qt message type (ignored here).

  • context – The context of the message (ignored here).

  • message – (str) The Qt debug/warning message to filter and display.

class populse_mia.tests.run_mia_test.LogCapture[source]

Bases: Handler

Custom logging handler to capture log records for inspection during tests.

This handler stores emitted log records in a list, allowing assertions on log content, level, or message during unit tests.

Contains:

Methods:

  • clear: Clears all captured log records.

  • emit: Appends a log record to the internal list.

__init__()[source]

Initializes the LogCapture handler.

Sets up an empty list to store log records.

clear()[source]

Clears all captured log records.

emit(record)[source]

Appends a log record to the internal list.

Parameters:

record – (logging.LogRecord) The log record to store.

class populse_mia.tests.run_mia_test.TestMIACase(methodName='runTest')[source]

Bases: TestCase

Parent class for the test classes of Mia.

Contains:

Methods:

  • add_visualized_tag: selects a tag to display with the “Visualized tags” pop-up.

  • capture_logs: context manager to temporarily capture log records.

  • clean_uts_packages: deleting the package added during the UTs or old one still existing.

  • create_mock_jar: creates a mocked java (.jar) executable.

  • execute_QDialogAccept: accept (close) a QDialog instance.

  • find_item_by_data: looks for a QModelIndex whose contents correspond to the argument data.

  • get_new_test_project: create a temporary project that can be safely modified.

  • proclibview_nipype_state: give the state of nipype in the process.

  • proclibview_nipype_reset_state: reset nipype to its initial state (before the start of the current test) in the process library view.

  • restart_Mia: restarts Mia within a unit test.

  • setUp: called automatically before each test method.

  • setUpClass: called before tests in the individual class.

  • suppress_all_output: Context manager to suppress all output during tests.

  • tearDown: cleans up after each test method.

  • tearDownClass: called after tests in the individual class.

add_visualized_tag(widget, tag, timeout=5000)[source]

Selects a tag to display from the “Visualized tags” pop-up.

This method waits for the tag selection dialog to become available within the given timeout period, locates the specified tag in the tag list, selects it, and confirms the dialog.

Parameters:
  • widget – The input filter containing the dialog with visualized tags.

  • tag – (str) The tag name to select and visualize.

  • timeout – (int) Maximum time to wait for the dialog to appear, in milliseconds. Defaults to 5000 ms.

Raises:
  • RuntimeError – If the dialog or visualized tags widget is not found.

  • ValueError – If the specified tag is not found in the list.

capture_logs(logger_name, level=20)[source]

Context manager to temporarily capture log records from a specific logger.

Attaches a LogCapture handler to the specified logger and yields it, allowing inspection of emitted log records during the context block. Restores the logger’s original state after the block is executed.

Capture a priority levels (default: INFO) and all higher priority levels (default: WARNING, ERROR, CRITICAL), but not lower priority levels. The logging levels have this hierarchy (from lowest to highest priority):

  • NOTSET (level 0) - Captures everything

  • DEBUG (10) - Lowest priority

  • INFO (20)

  • WARNING (30)

  • ERROR (40)

  • CRITICAL (50) - Highest priority

Parameters:
  • logger_name – (str) The name of the logger to capture logs from.

  • level – (int) The logging level to use during capture (default: 20; INFO).

Yields:

(LogCapture) A custom log handler with a records attribute containing captured LogRecord entries.

clean_uts_packages(proc_lib_view)[source]

Remove all packages added specifically for unit tests from the given process library view.

This includes:

  • Any package whose name contains ‘UTs_processes’

  • The ‘Unit_test_pipeline’ entry within ‘User_processes’, if present

The method simulates user confirmation for deletion and triggers a Delete key press event to invoke the removal mechanism.

Parameters:

proc_lib_view – The process library view containing the package items. Expected to implement to_dict(), selectionModel(), and keyPressEvent().

create_mock_jar(path)[source]

Create a mock Java executable (.jar) for testing.

Parameters:

path – (str) Full path to the output .jar file.

Returns:

(int) 0 if creation succeeded, 1 otherwise.

execute_QDialogAccept()[source]

Accept (close) a QDialog window.

find_item_by_data(q_tree_view: QTreeView, data: str) QModelIndex | None[source]

Search for the first QModelIndex in the given QTreeView whose data matches the specified value.

Parameters:
  • q_tree_view – (QTreeView) The tree view to search within.

  • data – (str) The target data to match.

Returns:

(QModelIndex | None) The matching index if found; otherwise, None.

get_new_test_project(name='test_project', light=False)[source]

Copies a test project where it can be safely modified.

The new project is created in the /tmp (/Temp) folder.

Parameters:
  • name – (str) Name of the directory containing the project.

  • light – (bool) True to copy a project with few documents.

proclibview_nipype_state(proc_lib_view)[source]

Determine the state of the Nipype process library view.

This method inspects the provided process library view and returns a string describing the loading state of the Nipype modules.

Parameters:

proc_lib_view – The process library view object.

Returns:

(str or None) A string representing the current state:

  • ‘nipype’: Nipype is present, but ‘interfaces’ is not.

  • ‘nipype.interfaces’: ‘interfaces’ is present, but ‘DataGrabber’ is not.

  • ‘process_enabled’: ‘nipype.interfaces.DataGrabber’ is present.

  • None: No processes loaded, or Nipype is not present.

proclibview_nipype_reset_state(main_window, ppl_manager, init_state)[source]

Resets the Nipype process library view in the package library popup to a specified initial state.

Parameters:
  • main_window – (QMainWindow) The main window containing the package library popup.

  • ppl_manager – (PipelineManager) The pipeline manager handling the process library.

  • init_state

    (str or None) The desired reset state of the Nipype process view:

    • None: The library is either empty or ‘nipype’ is not loaded.

    • ’nipype’: Only ‘nipype’ is loaded.

    • ’nipype.interfaces’: ‘nipype.interfaces’ is loaded but not ‘DataGrabber’.

    • ’process_enabled’: ‘nipype.interfaces.DataGrabber’ is already loaded.

restart_Mia()[source]

Restarts Mia within a unit test.

Can be used to restart MIA after changing the controller version in Mia preferences.

setUp()[source]

Called before each test

classmethod setUpClass()[source]

Called once at the beginning of the class

suppress_all_output()[source]

Cross-platform suppression of all standard output and error, including C-level and OS-level messages.

tearDown()[source]

Cleans up after each test to ensure test isolation and prevent state leakage.

This method performs the following actions:
  • Closes and deletes the main window if it exists.

  • Clears the list of opened projects in the application config.

  • Closes and deletes all top-level Qt widgets.

  • Uses a safer event loop approach with exception handling.

  • Resets internal references to ensure proper garbage collection.

classmethod tearDownClass()[source]

Called once at the end of the class

_classSetupFailed = False
_class_cleanups = []
class populse_mia.tests.run_mia_test.TestMIADataBrowser(methodName='runTest')[source]

Bases: TestMIACase

Tests for the data browser tab (DataBrowser).

Contains:

Methods:

  • assert_scans_present: Asserts that all expected scan names are present in the given list.

  • get_cell_text: Returns the text of the QLabel inside a cell widget.

  • get_db_and_databrowser_value: Returns current, initial DB values and UI value for a given tag.

  • get_visible_scans: Returns the list of scan names currently visible in the table.

  • suppress_item_changed_signal: Temporarily disconnects and reconnects the itemChanged signal.

  • test_add_path: Tests the popup to add a path.

  • test_add_tag: Tests the pop up adding a tag.

  • test_advanced_search: Tests the advanced search widget.

  • test_brick_history: Tests the brick history popup.

  • test_clear_cell: Tests the method clearing cells.

  • test_clone_tag: Tests the pop up cloning a tag.

  • test_count_table: Tests the count table popup.

  • test_mia_preferences: Tests the Mia preferences popup.

  • test_mini_viewer: Selects scans and display them in the mini viewer.

  • test_modify_table: Tests the modify table module.

  • test_multiple_sort: Tests the multiple sort popup.

  • test_multiple_sort_appendix: Adds and removes tags in the data browser.

  • test_openTagsPopUp: Opens a pop-up to select the legend of the thumbnails.

  • test_open_project: Tests project opening.

  • test_project_filter: Tests project filter opening.

  • test_project_properties: Tests saved projects addition and removal.

  • test_proj_remov_from_cur_proj: Tests that the projects are removed from the list of current projects.

  • test_rapid_search: Tests the rapid search bar.

  • test_remove_scan: Tests scans removal in the DataBrowser.

  • test_remove_tag: Tests the popup removing user tags.

  • test_reset_cell: Tests the method resetting the selected cells.

  • test_reset_column: Tests the method resetting the columns selected.

  • test_reset_row: Tests row reset.

  • test_save_project: Tests opening & saving of a project.

  • test_send_doc_to_pipeline_manager: Tests the popup sending documents to the pipeline manager.

  • test_set_value: Tests the values modifications.

  • test_show_brick_history: Opens the history pop-up for scans with history related to a brick.

  • test_sort: Tests the sorting in the DataBrowser.

  • test_table_data_add_columns: Adds tag columns to the table data window.

  • test_table_data_appendix: Opens a project and tests miscellaneous methods of the table data view, in the data browser.

  • test_table_data_context_menu: Right clicks a scan to show the context menu table, and choses one option.

  • test_undo_redo_databrowser: Tests data browser undo/redo.

  • test_unnamed_proj_soft_open: Tests unnamed project creation at software opening.

  • test_update_default_value: Updates the values when a list of default values is created.

  • test_utils: Tests the utils functions.

  • test_visualized_tags: Tests the popup modifying the visualized tags.

assert_scans_present(scans, expected_subset)[source]

Asserts that all expected scan names are present in the given list.

Parameters:
  • scans – (list) List of scan names to check.

  • expected_subset – (list) List of expected scan names that should be present in the scans list.

Raises:

AssertionError – If any expected scan name is missing from scans.

get_cell_text(table, row, column, label_index=0)[source]

Utility method to retrieve the text of the QLabel inside a cell widget.

Parameters:
  • table – (QTableWidget) The table containing the cell.

  • row – (int) The row index.

  • column – (int) The column index.

  • label_index – (int) If multiple labels are present, which one to return. Default is 0 (first QLabel found).

Returns:

(str) The text of the QLabel, or fails the test if not found.

get_db_and_databrowser_value(main_window, row_nb, tag)[source]

Fetches the current and initial values of a given tag from the database, along with the corresponding value and item from the data browser UI.

Parameters:
  • main_window – (QMainWindow) The main application window containing the project and data browser.

  • row_nb – (int) The row index in the data browser table.

  • tag – (str) The name of the tag (column) to retrieve.

Returns:

(tuple) A 4-tuple containing:

  • value (Any): The current value from the database (COLLECTION_CURRENT).

  • value_initial (Any): The initial value from the database (COLLECTION_INITIAL).

  • value_ui (str | None): The value displayed in the data browser UI, or None if not available.

  • item (QTableWidgetItem | None): The table item corresponding to the tag, or None if not found.

get_visible_scans()[source]

Returns the list of scan names currently visible in the table.

suppress_item_changed_signal(table_data)[source]

Temporarily disables the itemChanged signal to prevent unwanted slot execution during programmatic updates to the table data.

Parameters:

table_data – (QTableWidget) The data browser’s table widget whose itemChanged signal is to be suppressed.

Yields:

(None) The context block is executed with the signal disconnected, and it is reconnected automatically afterward.

test_add_path()[source]

Tests importing a document into the project via the DataBrowser UI.

  • Verifies behavior of DataBrowser.add_path() and PopUpAddPath.

  • Mocks QFileDialog.getOpenFileNames and QMessageBox.show.

  • Checks:
    • Handling of empty or invalid fields.

    • Successful addition of a valid document.

    • Duplicate document addition behavior.

test_add_tag()[source]

Test the add tag functionality in the data browser.

This test verifies that:
  • Empty tag names are properly rejected

  • Duplicate tag names are properly rejected

  • Invalid default values for the selected type are rejected

  • Valid string tags are successfully added to the database and UI

  • List-type tags (Integer List) are properly created and displayed

Tests the advanced search widget.

test_brick_history()[source]

Tests the brick history popup.

test_clear_cell()[source]

Tests clearing a cell and ensuring value is removed from database.

test_clone_tag()[source]

Tests the pop-up for cloning a tag.

test_count_table()[source]

Tests the count table popup.

test_mia_preferences(mock_qmsgbox)[source]

Test the MIA preferences dialog and verify that configuration changes are correctly saved or discarded.

The test checks that:

  • enabling and disabling Auto Save updates the configuration file,

  • cancelling the preferences dialog leaves the configuration unchanged,

  • project-related settings can be read and modified,

  • default values for external tool settings are correct,

  • display and behavior settings have the expected defaults, and

  • the MRI conversion path is initially unset.

Parameters:

mock_qmsgbox – (MagicMock) Mocked QMessageBox used to prevent modal dialogs from blocking the test.

test_mini_viewer()[source]

Tests MiniViewer functionality.

  • Displays scan information in the mini viewer box.

  • Verifies slider behavior and checkbox states.

test_modify_table()[source]

Test ModifyTable behavior with valid and invalid field types.

test_multiple_sort()[source]

Test the multiple sort popup functionality and resulting order.

test_multiple_sort_appendix()[source]

Test adding and removing tags in the multiple sort popup.

test_openTagsPopUp()[source]

Tests opening the tags selection popup in the MiniViewer.

  • Verifies integration between MiniViewer.openTagsPopUp and PopUpSelectTag.

  • Confirms filtering behavior in the tag selection list.

  • Ensures correct handling of tag selection and dialog interaction.

  • Tests: MiniViewer.openTagsPopUp

  • Indirectly tests: PopUpSelectTag

  • Mocks: PopUpSelectTag.exec_ using unittest.mock.patch

test_open_project()[source]

Tests that the project opens correctly, including expected UI title and document presence in the current and initial collections.

test_project_filter()[source]

Tests saving and applying a project filter.

  • Verifies:
    • DataBrowser.open_popup behavior

    • Project.save_current_filter functionality

  • Uses scoped mocks:
    • QMessageBox.exec (to bypass dialogs)

    • QInputDialog.getText (to simulate user input)

test_project_properties()[source]

Tests saved projects addition and removal.

  • Ensures that saved project paths are tracked properly.

  • Mocks SavedProjects.loadSavedProjects only within scope.

test_proj_remov_from_cur_proj()[source]

Tests that the current project is correctly removed from the list of opened projects after closing or switching.

  • Verifies that the current project path is listed in the opened projects.

Tests the rapid search bar behavior in the DataBrowser.

Steps:
  • Load a project with 9 scans.

  • Verify all scans are initially visible.

  • Filter scans using the search bar (e.g., “G1”).

  • Verify the filtered results.

  • Clear the filter using the cross button.

  • Verify all scans are shown again.

  • Test filtering using NOT_DEFINED_VALUE.

test_remove_scan()[source]

Tests the removal of scans from the database via the PipelineManagerTab.

  • Covered:
    • PipelineManagerTab.remove_scan

    • PopUpRemoveScan

  • Mocks:
    • PopUpRemoveScan.exec

test_remove_tag()[source]

Tests the tag removal popup in the data browser.

  • Verifies:
    • Tag is added correctly.

    • Tag list remains unchanged when removal popup is confirmed without selection.

    • Tag is removed when explicitly selected and confirmed.

test_reset_cell()[source]

Tests the method resetting the selected cells.

test_reset_column()[source]

Test that edit_table_data_values() properly updates column values, and reset_column() reverts them to their initial state.

test_reset_row()[source]

Tests row reset.

test_save_project()[source]

Test creating, saving, switching, and reopening a project, while mocking dialogs and preventing UI blocking.

test_send_doc_to_pipeline_manager()[source]

Test that documents (scans) can be sent from the data browser to the pipeline manager.

This includes:
  • Sending all scans (cancel and confirm cases)

  • Sending a manual selection of scans

  • Sending filtered scans using the search bar

All popup interactions are mocked to avoid GUI side effects.

test_set_value()[source]

Test modification of cell values in the data browser table.

This test verifies that both list values (BandWidth) and string values (Type) can be properly modified through the UI and that changes persist correctly in both the database and table display.

This test is redundant with the first part of test_reset_cell.

test_show_brick_history()[source]

Tests that the brick history pop-up opens correctly and allows navigation between scans through its interface.

Covers:
  • TableDataBrowser.show_brick_history()

  • PopUpShowHistory

Verifies:
  • Brick history pop-up is created on click.

  • Input scan button in the pop-up correctly selects the scan.

test_sort()[source]

Test sorting functionality in the DataBrowser table.

This test verifies that the DataBrowser table can be properly sorted by the BandWidth column in both ascending and descending order.

test_table_data_add_columns()[source]

Adds tag columns to the table data window.

  • Tests TableDataBrowser.add_columns.

test_table_data_appendix()[source]

Test various behaviors of the table data view in the data browser.

This includes verifying correct interaction with:
  • TableDataBrowser.on_cell_changed

  • TableDataBrowser.section_moved

  • TableDataBrowser.selectColumn

The test:
  • Opens a test project

  • Adds a scan via the add_path dialog

  • Mocks user interactions (dialogs)

  • Checks that editing cells updates or preserves values correctly

  • Tests column selection and header section movement

test_table_data_context_menu()[source]

Test that context menu actions correctly call their respective methods on the data table.

This covers both:

  • Confirm actions (that trigger a QMessageBox before executing)

  • Direct actions (executed immediately)

QMessageBox is auto-accepted by simulating a click on the OK button.

test_undo_redo_databrowser()[source]

Test undo and redo functionality in the DataBrowser across several operations.

This test verifies that user actions such as modifying a tag value, removing scans, adding/removing/cloning tags are correctly recorded in the project’s undo/redo stacks, and that the database and GUI reflect the expected changes after each undo/redo operation.

Tested operations include:
  1. Modifying a tag value (“BandWidth”) of a scan and undoing/redoing the change.

  2. Attempting to undo the deletion of a scan (should have no effect).

  3. Adding a new tag (“Test”) and verifying undo/redo toggles it properly.

  4. Removing an existing tag and checking undo/redo consistency.

  5. Cloning an existing tag (“FOV”) to create a new one (“Test”), verifying values in both the database and DataBrowser.

Ensures:
  • Undo/redo stacks (project.undos and project.redos) are updated appropriately.

  • DataBrowser UI and internal database states remain synchronized.

  • Non-reversible operations (e.g., scan deletion) behave as expected.

test_unnamed_proj_soft_open()[source]

Test that an unnamed project is correctly initialized at software startup.

Verifies that:
  • The project instance is created and named “Unnamed project”.

  • The default tags in the ‘current’ collection are correctly set.

  • No documents exist in ‘current’ and ‘initial’ collections.

  • All expected collections are present.

  • The main window title reflects the unnamed project.

test_update_default_value()[source]

Test the update of default tag values for various input types via the DefaultValueListCreation mechanism.

This test verifies:
  • Table behavior for different input formats (empty string, non-empty string, valid list).

  • Addition, removal, and resizing of list elements.

  • Update behavior across multiple field types.

  • Error handling for invalid input types.

test_utils()[source]

Test utility functions for type checking and conversion from UI table strings to correctly typed Python values for various field types.

Functions tested:
  • check_value_type: validates if a string value matches a given field type.

  • table_to_database: converts a string value from the UI into a typed value suitable for storage in the database.

test_visualized_tags()[source]

Validate the tag visibility management system and its impact on the DataBrowser UI.

This test simulates user interaction with the tag visibility popup and verifies:

  • Default visible tags are correctly initialized.

  • UI column headers match backend tag visibility.

  • System tags (e.g., checksum, history) remain hidden.

  • Filename tag is always visible and in the first column.

  • Tags can be hidden and re-shown via the interface.

_classSetupFailed = False
_class_cleanups = []
class populse_mia.tests.run_mia_test.TestMIAMainWindow(methodName='runTest')[source]

Bases: TestMIACase

Tests for the main window class (MainWindow).

Contains:

Methods:

  • test_check_database: checks if the database has changed since the scans were first imported

  • test_create_project_pop_up: tries to create a new project with a project already open.

  • test_files_in_project: tests whether or not a given file is part of the project.

  • test_import_data: opens a project and simulates importing a file from the MriConv java executable

  • test_open_project_pop_up: creates a test project and opens a project, including unsaved modifications.

  • test_open_recent_project: creates 2 test projects and opens one by the recent projects action.

  • test_package_library_dialog_add_pkg: creates a new project folder, opens the processes library and adds a package.

  • test_package_library_dialog_del_pkg: creates a new project folder, opens the processes library and deletes a package.

  • test_package_library_dialog_rmv_pkg: creates a new project folder, opens the processes library and removes a package.

  • test_package_library_others: Creates a new project folder, opens the processes library and adds a package.

  • test_popUpDeletedProject: adds a deleted projects to the projects list and launches mia.

  • test_popUpDeleteProject: creates a new project and deletes it.

  • test_see_all_projects: creates 2 projects and tries to open them through the all projects pop-up.

  • test_software_preferences_pop_up: opens the preferences pop up and changes parameters.

  • test_software_preferences_pop_up_config_file: opens the preferences pop up and changes parameters.

  • test_software_preferences_pop_up_modules_config: changes the configuration of AFNI, ANTS, FSL, SPM, mrtrix and MATLAB.

  • test_software_preferences_pop_up_validate: opens the preferences pop up for AFNI, ANTS, FSL, SPM, mrtrix and MATLAB.

  • test_switch_project: create project and switches to it.

  • test_tab_changed: switches between data browser, data viewer and pipeline manager.

test_check_database()[source]

Test detection of changes in the project’s database after file removal.

This test verifies that the application correctly identifies changes to the database, such as a missing file after import.

test_create_project_pop_up()[source]

Test project creation popup behavior under various conditions.

Verifies the MainWindow.create_project_pop_up method handles:
  • Project creation with unsaved modifications (triggers quit popup)

  • Project creation without configured projects folder (shows error)

  • Normal project creation flow with proper configuration

Components tested:

MainWindow.create_project_pop_up, PopUpNewProject

Mocked components:

PopUpQuit.exec, QMessageBox.exec, PopUpNewProject.exec

test_files_in_project()[source]

Test MainWindow.project.files_in_project method.

Verifies that the method correctly identifies which files belong to the project, handling invalid inputs and files both inside and outside the project directory.

test_import_data()[source]

Test importing data via the mocked MRI conversion process.

This test simulates opening a project, setting up a mock Java executable for MRI conversion, and importing a scan file into the project.

It verifies:
  • The integration with read_log (from data_loader.py)

  • Proper behavior of ImportProgress

Mocks within this test:
  • ImportWorker.start to prevent actual threading

  • ImportProgress.exec to run the worker directly

test_open_project_pop_up()[source]

Test the behavior of MainWindow.open_project_pop_up under different project state conditions, including:

  • No project save directory set

  • Project opened successfully

  • Project with unsaved modifications

Mocks the following components:
  • QMessageBox.exec

  • PopUpOpenProject.exec

  • PopUpQuit.exec

test_open_recent_project()[source]

Test opening a recent project via the ‘recent projects’ action.

This includes switching between two projects, saving one, verifying its presence in the recent projects list, and reopening it.

  • Tests: MainWindow.open_recent_project

test_package_library_dialog_add_pkg()[source]

Test adding and installing packages through the PackageLibraryDialog.

This test verifies the following:
  • Opening the package library dialog and adding a standard package.

  • Handling invalid or non-existent packages.

  • Installing a process package from a directory.

  • Validating error handling for invalid directories and import errors.

  • Saving and reloading a new pipeline using the installed process.

Mocks:
test_package_library_dialog_del_pkg()[source]

Test the behavior of the PackageLibraryDialog when deleting packages.

This test covers:
  • Adding and removing a known package (nipype.interfaces.DataGrabber)

  • Ensuring deletion confirmations are handled correctly

  • Ensuring packages that can’t be deleted show proper warnings

  • Adding and deleting a user-defined process package (Unit_test_2)

Mocks:
  • QMessageBox.exec

  • QMessageBox.question

test_package_library_dialog_rmv_pkg()[source]

Test removing a package from the package library dialog.

This test:
  • Creates a new project.

  • Opens the process library and ensures a test package is installed.

  • Attempts to remove nonexistent and unspecified packages.

  • Removes a real package through the UI simulation.

  • Resets the library state and saves the configuration.

Mocks:
test_package_library_others()[source]

Test the behavior of the Package Library Manager dialog.

This test:
  • Creates a new light project.

  • Opens the Package Library Manager dialog via the main window.

  • Mocks a package tree structure and populates it into the library.

  • Closes the dialog after setup.

Targets:
  • PackageLibraryDialog behavior

test_popUpDeletedProject()[source]

Test that the application handles deleted projects properly.

This test:
  • Configures a custom project save directory.

  • Adds a non-existent (deleted) project path to saved_projects.yml.

  • Verifies the path is handled correctly by PopUpDeletedProject.

  • Ensures the project is removed from the saved projects list.

Target:
  • PopUpDeletedProject behavior

test_popUpDeleteProject()[source]

Test the project deletion flow, including dialog behavior and config updates.

This test:
  • Creates a new test project and switches to it.

  • Attempts to delete the project without a configured save path (to test error handling).

  • Sets a valid save path and ensures the project is properly deleted.

  • Simulates user interaction with confirmation dialogs (e.g., “Yes to All”).

Targets:
  • MainWindow.delete_project

  • PopUpDeleteProject

Notes: Not to be confused with test_popUpDeletedProject.

test_see_all_projects()[source]

Test the ‘See All Projects’ feature with two saved projects.

Validates:
  • Displaying projects in PopUpSeeAllProjects

  • Proper handling of missing project folders

  • Opening a selected existing project

Mocks:
  • PopUpSeeAllProjects.exec

  • QMessageBox.exec

test_software_preferences_pop_up()[source]

Test the software preferences pop-up window behavior.

This test covers:
  • The opening and interaction with the preferences dialog.

  • The reflection of config changes (e.g., enabling tools, setting paths).

  • Admin mode switching and password validation.

  • UI updates based on configuration flags.

Mocked methods:
  • QFileDialog.getOpenFileName

  • QFileDialog.getExistingDirectory

  • QInputDialog.getText

  • QDialog.exec

  • QMessageBox.exec

  • SettingsEditor.update_gui

  • capsul.api.capsul_engine

  • Config.set_capsul_config

test_software_preferences_pop_up_config_file()[source]

Test the behavior of the software preferences pop-up when modifying the config file and Capsul configuration.

This test verifies:
  • PopUpPreferences.edit_config_file

  • PopUpPreferences.findChar

  • PopUpPreferences.edit_capsul_config

Mocks:
  • QDialog.exec to simulate user interaction

  • SettingsEditor.update_gui to bypass GUI refresh

  • Config.set_capsul_config to simulate failure during config update

test_software_preferences_pop_up_modules_config()[source]

Tests the software module configuration via the Preferences pop-up.

This test verifies the proper behavior of the preferences configuration dialog for AFNI, ANTS, FSL, mrtrix, SPM, and MATLAB modules, including handling of valid and invalid executable paths.

tests: PopUpPreferences.validate_and_save

mocks: QMessageBox.show

test_software_preferences_pop_up_validate()[source]

Validates configuration changes via the software preferences pop-up.

This test simulates user interactions in the software preferences window without and with confirming via the ‘OK’ button. It verifies correct saving of settings related to:

  • Standalone modules (AFNI, ANTS, FSL, SPM, MRtrix, MATLAB, freesurfer)

  • UI and behavioral options (auto-save, radio view, admin/clinical mode)

Tests:
  • PopUpPreferences.validate_and_save

  • PopUpPreferences.ok_clicked

Mocks:
  • PopUpPreferences.show

  • PopUpPreferences.wrong_path

  • QMessageBox.show

test_switch_project()[source]

Tests switching to various project states using MainWindow.switch_project.

This test covers:
  • Switching to a valid Mia project

  • Handling non-existent project paths

  • Preventing switching to already-open projects

  • Ignoring invalid or malformed Mia projects

  • Tests: MainWindow.switch_project

  • Mocks: QMessageBox.exec (to bypass dialog confirmations)

test_tab_changed()[source]

Tests tab switching behavior in the main window.

Verifies that switching between Data browser, Data viewer and Pipeline manager tabs, proceeds as expected, including handling unsaved changes via a confirmation dialog.

Tests: MainWindow.tab_changed Mocks: QMessageBox.exec

_classSetupFailed = False
_class_cleanups = []
class populse_mia.tests.run_mia_test.TestMIANodeController(methodName='runTest')[source]

Bases: TestMIACase

Tests for the node controller, part of the pipeline manager tab.

Contains:

Methods:

  • create_mock_exec: create a mock function for PopUpSelectTagCountTable.exec_() that simulates user tag selection behavior.

  • test_attributes_filter: displays an attributes filter and modifies it.

  • test_capsul_node_controller: adds, changes and deletes processes using the capsul node controller.

  • test_display_filter: displays node parameters and a plug filter.

  • test_filter_widget: opens up the “FilterWidget()” to modify its parameters.

  • test_node_controller: adds, changes and deletes processes to the node controller.

  • test_plug_filter: displays a plug filter and modifies it

  • test_update_node_name: displays node parameters and updates its name.

create_mock_exec(tag_name)[source]

Create a mock function for PopUpSelectTagCountTable.exec_() that simulates user tag selection behavior.

This function returns a mock implementation that programmatically selects a specific tag from the popup’s list widget and triggers the OK action, simulating the user workflow without requiring actual UI interaction.

Parameters:

tag_name – (str) The name of the tag to select from the list. This should match the text of one of the items in the popup’s list widget.

Returns:

A mock function that can be used to replace exec_() method.

test_attributes_filter()[source]

Tests the display and modification of the attributes filter in the CapsulNodeController GUI.

This test performs the following:
  • Opens a test project and switches to it.

  • Adds a ‘Smooth’ process node to the pipeline editor.

  • Exports unconnected mandatory plugs for the new node.

  • Displays parameters of the ‘inputs’ node.

  • Opens the attributes filter dialog, selects a row, and confirms.

  • Reopens the dialog, performs a failed search, and confirms without selection.

Target:
  • CapsulNodeController.filter_attributes

  • AttributesFilter dialog interactions

test_capsul_node_controller()[source]

Validates the behavior of the CapsulNodeController for process management within a pipeline editor GUI.

This test simulates a realistic sequence of user interactions and verifies the following capabilities:

  • Adding two ‘Rename’ nodes to the pipeline (‘rename_1’ and ‘rename_2’)

  • Displaying and interacting with node parameters

  • Attempting to rename ‘rename_2’ to an existing name (should fail)

  • Renaming ‘rename_2’ to a new unique name (‘rename_3’) successfully

  • Deleting an existing node (‘rename_3’)

  • Exporting unconnected mandatory input plugs for a node

  • Setting input plug values using a test document

  • Executing the pipeline and expecting an error due to unexported output

  • Opening the attributes filter dialog, selecting a row, and confirming

  • Releasing and updating the process associated with the controller

Methods tested:
  • CapsulNodeController.update_node_name

  • CapsulNodeController.display_parameters

  • CapsulNodeController.filter_attributes

  • CapsulNodeController.release_process

  • CapsulNodeController.update_parameters

  • PipelineEditor.export_unconnected_mandatory_inputs

  • PipelineManager.runPipeline

Notes

  • The test assumes that running the pipeline raises an error because the output plug is not exported, which is intentional.

  • A QDialog.exec() mock is used to simulate dialog confirmation during pipeline execution.

test_display_filter()[source]

Tests the display and modification of node parameters and plug filters in the CapsulNodeController V1 interface.

Steps:
  • Ensures the GUI uses the V1 node controller.

  • Adds a ‘Threshold’ process to the pipeline.

  • Exports input plugs and sets the ‘synchronize’ input to 2.

  • Displays and validates the plug filter editor for ‘synchronize’.

  • Restores original GUI controller version after the test.

test_filter_widget()[source]

Tests the FilterWidget class used for filtering input data within a Capsul pipeline node.

This test:
  • Switches to the V1 node controller (if not already active)

  • Adds an Input_Filter process to the pipeline

  • Feeds in documents from a test project

  • Opens the filter widget for the added node

  • Performs various filtering actions:
    • Searching for documents by name

    • Toggling tag visibility

    • Filtering by a specific tag (mocking user interaction)

The FilterWidget is GUI-independent and works in both V1 and V2 node controller UIs. Only the V1 GUI is exercised here.

Mocks: PopUpSelectTagCountTable.exec_()

test_node_controller()[source]
Tests the behavior of the V1 NodeController interface for:
  • Adding, renaming, and deleting nodes

  • Displaying and updating process parameters

  • Interacting with plug filters and values

Workflow:
  • Switches to V1 node controller mode if not already enabled

  • Opens a test project and adds two Rename processes as “rename_1” and “rename_2”

  • Attempts renaming “rename_2” to an existing name (fails) then to a unique one

  • Deletes the renamed node

  • Exports input/output plugs and tests plug interaction

  • Displays parameters and plug filters

  • Updates plug values with and without providing new values

  • Releases and refreshes the process

  • Restores the original node controller mode after testing

test_plug_filter()[source]

Tests plug filtering in the Node Controller V1 interface.

This test covers:
  • Switching to Node Controller V1 if not already enabled

  • Opening a test project and retrieving documents

  • Adding and configuring a ‘Smooth’ node in the pipeline

  • Displaying and modifying a plug filter

  • Searching and filtering table rows

  • Modifying visible tag columns

  • Verifying plug value assignment from filtered selections

test_update_node_name()[source]

Tests renaming of nodes in the pipeline and verifies the correct update or rejection of name changes based on naming conflicts.

This test ensures:
  • A node name can be changed via the NodeController interface.

  • Duplicate names are not accepted.

  • Node renaming preserves the connections (links) between nodes.

_classSetupFailed = False
_class_cleanups = []
class populse_mia.tests.run_mia_test.TestMIAPipelineEditor(methodName='runTest')[source]

Bases: TestMIACase

Tests for the pipeline editor, part of the pipeline manager tab.

Contains:

Methods:

  • test_add_tab: Adds tabs to the PipelineEditorTabs.

  • test_close_tab: Closes a tab in the PipelineEditorTabs.

  • test_drop_process: Adds a Nipype SPM Smooth process to the pipeline editor.

  • test_export_plug: Exports plugs and mocks dialog boxes.

  • test_save_pipeline: Creates a pipeline and tries to save it.

  • test_update_plug_value: Displays node parameters and updates a plug value.

  • test_z_check_modif: Opens a pipeline, modifies it and check the modifications.

  • test_z_get_editor: Gets the instance of an editor.

  • test_z_get_filename: Gets the relative path to a previously saved pipeline file.

  • test_z_get_index: Gets the index of an editor.

  • test_z_get_tab_name: Gets the tab name of the editor.

  • test_z_load_pipeline: Loads a pipeline.

  • test_z_open_sub_pipeline: Opens a sub_pipeline.

  • test_z_set_current_editor: Sets the current editor.

  • test_zz_del_pack: Deletes a brick created during UTs.

test_add_tab()[source]

Test the addition of new tabs in the PipelineEditorTabs.

Ensures that:
  • A new tab increases the tab count.

  • Tabs are named incrementally as ‘New Pipeline’, ‘New Pipeline 1’, etc.

test_close_tab()[source]

Tests the PipelineEditor.close_tab() method under various conditions.

This method indirectly tests the behavior of the PopUpClosePipeline dialog when attempting to close tabs that are either unmodified or modified.

Scenarios covered:
  • Closing an unmodified tab (no dialog shown)

  • Closing a modified tab and choosing:
    • “Save As”

    • “Do Not Save”

    • “Cancel”

test_drop_process()[source]

Tests the addition of a Nipype SPM ‘Smooth’ process to the pipeline editor.

Verifies that dropping the ‘nipype.interfaces.spm.Smooth’ process at a specific position in the pipeline editor results in the creation of a node named ‘smooth_1’.

test_export_plug()[source]

Tests the export of plugs in the pipeline editor.

This test verifies:
  • Exporting a plug with no parameters.

  • Exporting a plug when a node is added.

  • Behavior when a plug is exported multiple times with overwrite confirmation.

  • Behavior when overwriting is denied and a new name is entered.

test_save_pipeline()[source]

Creates a pipeline and verifies various scenarios when saving it.

This test covers:
  • Saving an empty pipeline (should return None).

  • Saving with user cancellation (should return None).

  • Saving with filenames starting with a digit (should return None).

  • Saving without an extension (‘.py’ should be added automatically).

  • Saving with an incorrect extension (should be corrected to ‘.py’).

  • Handling restricted user mode where saving is not allowed.

  • Saving using an explicitly provided filename.

Targeted methods:
  • PipelineEditor.save_pipeline

  • PipelineEditorTabs.save_pipeline

  • save_pipeline function in pipeline_editor.py

Mocked:
  • QMessageBox.exec

  • QFileDialog.getSaveFileName

test_update_plug_value()[source]

Tests updating plug values through the node controller UI.

This test verifies that:
  • A process node (“threshold_1”) can be added and its parameters displayed.

  • Input and output plugs (“synchronize” and “_activation_forced”) can be updated through the GUI.

  • The internal pipeline state reflects these updated plug values.

  • Exported input plugs can also be modified and reflected correctly.

  • The test maintains the original node controller configuration (V1/V2).

Tested methods:
  • NodeController.get_index_from_plug_name

  • NodeController.update_plug_value

  • PipelineEditor.export_node_all_unconnected_inputs

  • ProcessNode.get_plug_value

Notes: This test specifically targets NodeController V1 behavior.

test_z_check_modif()[source]

Tests plug modification propagation when a pipeline is opened as a sub-process.

This test performs the following steps:
  • Loads a user-defined pipeline from a .py file, ensuring it contains a “smooth_1” node.

  • Opens a new tab and adds the above pipeline as a process (“test_pipeline_1_1”).

  • Adds two “Smooth” nodes and links them to form a processing chain.

  • Verifies correct connections between nodes.

  • Exports plugs from the original pipeline in the first tab and saves it.

  • Re-checks the second tab for updated plugs via check_modifications().

  • Asserts that the new plug (“fwhm”) is now present in “test_pipeline_1_1”.

Tested features:
  • Pipeline loading

  • Process instantiation from library

  • Node linking

  • Plug export and save

  • Detection of modifications in sub-pipeline processes

test_z_get_editor()[source]

Verify that editor instances in PipelineEditorTabs are correctly retrieved using various access methods.

Tests the following methods:
  • get_editor_by_index

  • get_current_editor

  • get_editor_by_tab_name

  • get_editor_by_file_name

test_z_get_filename()[source]

Tests retrieval of the filename associated with a pipeline editor tab.

Verifies:
  • PipelineEditorTabs.get_filename_by_index returns the correct absolute path for a loaded pipeline in a given tab index.

  • PipelineEditorTabs.get_filename_by_index returns None for a tab without a file.

  • PipelineEditorTabs.get_current_filename returns the correct absolute path of the currently selected tab’s pipeline.

Target methods:
  • PipelineEditorTabs.get_filename_by_index

  • PipelineEditorTabs.get_current_filename

test_z_get_index()[source]

Verifies that editor tab indices can be correctly retrieved by tab name, filename, and editor instance.

Tests:
  • PipelineEditorTabs.get_index_by_tab_name

  • PipelineEditorTabs.get_index_by_filename

  • PipelineEditorTabs.get_index_by_editor

The test performs the following steps:
  1. Loads a saved pipeline file into a new tab.

  2. Creates an additional empty pipeline in a second tab.

  3. Retrieves and checks tab indices using:
    • the tab name

    • the full file path

    • the editor instance

  4. Confirms that querying with an invalid name, path, or editor returns None.

test_z_get_tab_name()[source]

Verify that the tab names of pipeline editors are correctly retrieved.

This test checks both direct index-based retrieval and the currently selected tab name.

Tests:
  • PipelineEditorTabs.get_tab_name_by_index

  • PipelineEditorTabs.get_current_tab_name

test_z_load_pipeline()[source]

Loads a pipeline file into the editor and verifies its content.

Tests:
  • PipelineEditorTabs.load_pipeline

  • PipelineEditorTabs.get_current_pipeline

Verifies:
  • The pipeline is loaded correctly.

  • The node ‘smooth_1’ exists in the loaded pipeline.

test_z_open_sub_pipeline()[source]

Tests the ability to open a sub-pipeline in a new editor tab.

This test:
  • Adds the “Test_pipeline_1” process from the “User_processes” module.

  • Simulates a user click to insert the process into the current pipeline.

  • Opens the sub-pipeline associated with the inserted process.

  • Verifies that a new editor tab is created and named correctly.

Tests:
  • PipelineEditorTabs.open_sub_pipeline

  • PipelineEditorTabs.get_filename_by_index

test_z_set_current_editor()[source]

Tests setting the current editor using different criteria.

Validates that the active tab can be correctly switched using:
  • Tab name

  • Pipeline file name

  • Editor instance

Targets the following methods:
  • PipelineEditorTabs.set_current_editor_by_tab_name

  • PipelineEditorTabs.set_current_editor_by_file_name

  • PipelineEditorTabs.set_current_editor_by_editor

test_zz_del_pack()[source]

Deletes the ‘Test_pipeline_1’ brick from the package library and verifies its removal.

This test ensures that:
  • The brick ‘Test_pipeline_1’ exists before deletion.

  • The delete_package method removes it correctly.

  • The internal package tree reflects the deletion.

It also implicitly covers the functionality related to package removal.

_classSetupFailed = False
_class_cleanups = []
class populse_mia.tests.run_mia_test.TestMIAPipelineManagerTab(methodName='runTest')[source]

Bases: TestMIACase

Tests the pipeline manager tab class, part of the homonym tab.

Contains:

Methods:

  • test_add_plug_value_to_database_list_type: Adds a list type plug value to the database.

  • test_add_plug_value_to_database_non_list_type: Adds a non list type plug value to the database.

  • test_add_plug_value_to_database_several_inputs: Exports a non list type input plug and with several possible inputs.

  • test_ask_iterated_pipeline_plugs: Tests the iteration dialog for each plug of a Rename process.

  • test_build_iterated_pipeline: Mocks methods and builds an iterated pipeline.

  • test_check_requirements: Checks the requirements for a given node.

  • test_cleanup_older_init: Tests the cleaning of old initialisations.

  • test_complete_pipeline_parameters: Tests the pipeline parameters completion.

  • test_delete_processes: Deletes a process and makes the undo/redo.

  • test_end_progress: Creates a progress object and tries to end it.

  • test_garbage_collect: Collects the garbage of a pipeline.

  • test_get_capsul_engine: Gets the capsul engine of the pipeline.

  • test_get_missing_mandatory_parameters: Tries to initialize the pipeline with missing mandatory parameters.

  • test_get_pipeline_or_process: Gets a pipeline and a process from the pipeline_manager.

  • test_initialize: Mocks objects and initializes the workflow.

  • test_register_completion_attributes: Mocks methods of the pipeline manager and registers completion attributes.

  • test_register_node_io_in_database: Sets input and output parameters and registers them in database.

  • test_remove_progress: Removes the progress of the pipeline.

  • test_run: Creates a pipeline manager progress object and attempts to execute it in various cases.

  • test_savePipeline: Tries to save the pipeline over several conditions.

  • test_save_pipeline_as: Saves a pipeline under another name.

  • test_set_anim_frame: Runs the ‘rotatingBrainVISA.gif’ animation.

  • test_show_status: Shows the status of pipeline execution.

  • test_stop_execution: Shows the status window of the pipeline manager.

  • test_undo_redo: Tests the undo/redo feature.

  • test_update_auto_inheritance: Updates the job’s auto inheritance dict.

  • test_update_inheritance: Updates the job’s inheritance dict.

  • test_update_node_list: Initializes a workflow and adds a process to the “pipline_manager.node_list”.

  • test_z_init_pipeline: Initializes the pipeline.

  • test_z_runPipeline: Adds a process and runs a pipeline.

  • test_zz_del_pack: Deletion of the brick created during UTs.

test_add_plug_value_to_database_list_type()[source]

Tests adding a list-type plug value to the database from a process node.

This test:
  • Opens a test project.

  • Adds a ‘CAT12Segment’ process to the pipeline.

  • Exports its input/output plugs.

  • Assigns a list of files as input to the ‘in_files’ plug.

  • Simulates metadata attributes.

  • Calls add_plug_value_to_database() to register the plug values.

  • Verifies that both documents and their metadata are stored in the database.

Tests: PipelineManagerTab(QWidget).add_plug_value_to_database()

test_add_plug_value_to_database_non_list_type()[source]

Tests the behavior of add_plug_value_to_database() when handling a non-list input plug value in different contexts.

Scenarios covered:
  • Plug value is outside the project directory (should not be indexed)

  • Plug value is inside the project directory (should be indexed)

  • Plug value is already in the database (logs an info message)

  • Plug values with different file extensions (.nii.gz, .mat, .txt)

  • Handling of parent_files via auto_inheritance_dict and inheritance_dict

  • Adding and removing tags based on the inheritance information

Tests: PipelineManagerTab(QWidget).add_plug_value_to_database()

test_add_plug_value_to_database_several_inputs()[source]

Test add_plug_value_to_database under various inheritance and input conditions.

This test covers:
  • Identical parent file mappings in inheritance.

  • Distinct parent file mappings triggering inheritance pop-ups.

  • Predefined inheritance key using node name.

  • Predefined inheritance key using node name + plug value.

Also validates PopUpInheritanceDict interactive behavior across all buttons.

tested:
  • PipelineManagerTab.add_plug_value_to_database

  • PopUpInheritanceDict interaction

test_ask_iterated_pipeline_plugs()[source]

Test the iteration dialog invocation on exported plugs of a pipeline.

This test:
  • Adds a ‘Rename’ process to the current pipeline editor.

  • Exports the mandatory input and output plugs of the ‘rename_1’ node.

  • Mocks the iteration dialog to simulate user rejection (dialog closed without acceptance).

  • Verifies that ask_iterated_pipeline_plugs returns None when the dialog is rejected.

Covers:
  • PipelineManagerTab.ask_iterated_pipeline_plugs

test_build_iterated_pipeline()[source]

Test ‘PipelineManagerTab.build_iterated_pipeline’.

Simulates building an iterated pipeline from a ‘Select’ process:
  • Adds a ‘Select’ process in the current pipeline editor.

  • Exports mandatory inputs and outputs for the node.

  • Mocks methods to simulate pipeline retrieval, user iteration choices, and process activation updates.

  • Verifies that the resulting pipeline is correctly built and mocks are invoked as expected.

Note: ‘update_nodes_and_plugs_activation’ may not exist on the process, hence ‘create=True’ is used to safely mock it.

The test allows an expected exception message to be printed during execution.

test_check_requirements()[source]

Test the ‘PipelineManagerTab.check_requirements’ method.

This test simulates adding a ‘Select’ process to the current pipeline, appending the corresponding node’s process to the node list, and verifying that the requirements check returns the expected configuration.

Steps:
  • Add a ‘Select’ process as a node (‘select_1’) in the pipeline.

  • Append the process of ‘select_1’ to the pipeline manager’s node list.

  • Call ‘check_requirements’ to retrieve the configuration.

  • Assert the returned configuration is a dictionary containing the expected keys.

Raises:

AssertionError – If the configuration is not a dictionary or does not contain the expected keys.

test_cleanup_older_init()[source]

Test ‘PipelineManagerTab.cleanup_older_init’.

This test verifies that:
  • The brick list is properly processed for cleanup.

  • The relevant methods for deleting data and cleaning up orphan files are called exactly once.

  • The ‘brick_list’ and ‘node_list’ are emptied after cleanup.

Steps:
  1. Append a mock brick ID and mock node to the pipeline manager.

  2. Mock dependent methods on the data browser and project.

  3. Call the method under test.

  4. Assert expected method calls and post-conditions.

test_complete_pipeline_parameters()[source]

Mocks a method of pipeline manager and completes the pipeline parameters.

Tests: PipelineManagerTab.complete_pipeline_parameters

test_delete_processes()[source]

Test deletion of a process node and verification of undo/redo functionality.

This test creates a pipeline with three connected ‘Smooth’ processes (smooth_1 -> smooth_2 -> smooth_3), deletes the middle node, and verifies:

  • The node is properly removed from the pipeline

  • Connected links are cleaned up

  • Undo operation restores the node and its connections

  • Redo operation removes the node again

test_end_progress()[source]

Tests RunProgress.end_progress under different worker execution states.

This test:
  • Initializes a RunProgress instance from the current pipeline manager.

  • Calls end_progress() when no exec_id is set on the worker.

  • Mocks exec_id and raise_for_status on the engine to validate success handling.

  • Mocks raise_for_status to raise WorkflowExecutionError to verify error handling.

test_garbage_collect()[source]

Tests ‘PipelineManagerTab.garbage_collect’ both in integrated and isolated contexts.

Integrated test: Verifies that invoking ‘garbage_collect’ sets the pipeline editor’s ‘initialized’ attribute to False.

Isolated test: In addition to the ‘initialized’ reset, verifies that dependent methods are called exactly once:

  • postprocess_pipeline_execution

  • update_user_buttons_states

test_get_capsul_engine()[source]

Tests ‘PipelineManagerTab.get_capsul_engine’ in both integrated and isolated contexts.

Integrated test: Ensures that calling ‘get_capsul_engine’ returns an instance of ‘CapsulEngine’.

Isolated test: Mocks ‘pipelineEditorTabs.get_capsul_engine’ to verify that it is called exactly once when invoked via ‘PipelineManagerTab.get_capsul_engine’.

test_get_missing_mandatory_parameters()[source]

Tests ‘PipelineManagerTab.get_missing_mandatory_parameters’.

This test simulates adding a ‘Rename’ process to the pipeline, exporting its mandatory input and output plugs, and checking for missing mandatory parameters at different stages.

Steps:
  1. Add ‘Rename’ process to the pipeline.

  2. Export the required input and output plugs.

  3. Initialize the pipeline and check that two mandatory parameters are initially missing.

  4. Set a value for one mandatory parameter (‘format_string’) and verify that only one mandatory parameter remains missing (‘in_file’).

test_get_pipeline_or_process()[source]

Test retrieving either a pipeline or a process from the pipeline manager.

  • Verifying that the pipeline is returned when no process node is selected.

  • Adding a ‘Rename’ process node and verifying that the method returns the corresponding NipypeProcess when a process is selected.

Tests: PipelineManagerTab.get_pipeline_or_process

test_initialize()[source]

Tests the initialize method of PipelineManagerTab.

This method:
  • Adds a Rename process to the pipeline editor.

  • Exports its mandatory input and output plugs.

  • Sets required parameters for the node.

  • Mocks the init_pipeline method to prevent segmentation faults.

  • Checks that initialization resets internal flags and dictionaries.

  • Induces an exception path by setting init_pipeline to None.

Tests: PipelineManagerTab.initialize

test_register_completion_attributes()[source]

Test the registration of completion attributes in the pipeline manager.

This method tests the behavior of the pipeline manager when registering completion attributes with and without provided attributes. It performs the following steps:

  1. Adds a Select process to the current pipeline.

  2. Exports mandatory input and output plugs.

  3. Sets plug values for input and output files.

  4. Mocks ‘get_capsul_engine’ to prevent errors during completion.

  5. Mocks ‘get_attribute_values().export_to_dict’ to return custom attributes.

  6. Calls ‘register_completion_attributes’ both without and with mocked attributes.

  7. Asserts the expected behavior in both scenarios.

test_register_node_io_in_database()[source]

Tests the registration of node input/output data in the project database for different types of process nodes.

Steps:
  1. Opens a new project and switches to it.

  2. Adds a Rename process node to the current pipeline.

  3. Exports mandatory inputs/outputs for the process.

  4. Sets plug values for the process and output nodes.

  5. Creates a workflow and job for the pipeline.

  6. Tests _register_node_io_in_database with:
    • NipypeProcess instance

    • ProcessNode instance

    • PipelineNode instance

    • Switch instance

    • Process with no outputs

Verifies:
  • Output file is correctly added to COLLECTION_CURRENT.

  • Output file is removed when expected.

  • Unsupported process types do not incorrectly register outputs.

Raises:

AssertionError – If any database check fails.

test_remove_progress()[source]

Verify that PipelineManagerTab.remove_progress correctly deletes the progress attribute.

This test creates a temporary RunProgress instance in the pipeline manager, invokes remove_progress, and ensures the attribute no longer exists.

tests: PipelineManagerTab.remove_progress

test_run()[source]

Tests the standard execution of a pipeline with mixed node types (process, sub-pipeline, switch).

This test verifies:
  • The pipeline runs correctly with valid nodes.

  • Expected INFO log messages are emitted during execution.

  • Error handling and interruption scenarios are covered.

Test Cases:
  1. Normal run: Validates INFO logs for pipeline execution.

  2. Mocked error: Simulates a post-processing error and checks warning logs.

  3. Interruption: Ensures interruption is logged correctly.

tests: RunWorker.run

test_savePipeline()[source]

Test the behavior of PipelineManagerTab.savePipeline under different conditions by mocking dependent methods.

This test simulates saving a pipeline in various scenarios:
  • Saving with no filename set (unchecked option).

  • Mocks ppl_edt_tabs.save_pipeline() to return a string.

  • Saving with a valid filename (unchecked option).

  • Aborting save via a QMessageBox (‘Abort’ clicked).

  • Confirming save via a QMessageBox (‘Yes’ clicked).

test_save_pipeline_as()[source]

Verify that saving a pipeline under a new name works correctly by mocking the underlying save_pipeline method.

This test ensures:
  • When no filename is provided, PipelineManagerTab.save_pipline_as completes without error and the status bar displays a warning.

  • When save_pipeline returns a non-empty filename, the method handles the renamed pipeline and the status bar confirms success.

Raises:

AssertionError – If the displayed status bar messages do not match the expected content.

test_set_anim_frame()[source]

Verify that _set_anim_frame updates the pipeline status action icon with the current frame of the animated GIF.

This test ensures that:
  1. The rotatingBrainVISA.gif file exists and can be loaded as a QMovie.

  2. The QMovie produces a valid first frame (non-null QPixmap).

  3. Calling _set_anim_frame sets the action’s icon.

  4. The resulting QAction icon matches the movie frame in size.

test_show_status()[source]

Tests the behavior of the pipeline status display in the PipelineManagerTab.

Indirectly validates:
  • StatusWidget.__init__

  • StatusWidget.toggle_soma_workflow

The test verifies that:
  • Initially, no status widget is present.

  • Calling show_status creates the widget with the checkbox unchecked and no associated swf_widget.

  • Toggling the checkbox enables/disables Soma-Workflow monitoring, creating and hiding the swf_widget accordingly.

test_stop_execution()[source]

Verify that stopping execution in the pipeline manager behaves as expected.

This test ensures that:
  • A RunProgress worker is created without an interrupt request.

  • Calling stop_execution logs both a “CANCEL” message and a “Pipeline execution interrupted” message at the INFO level.

  • The worker’s interrupt request flag is set to True after stopping.

Related test: PipelineManagerTab.test_show_status

test_undo_redo()[source]

Test the consistency and correctness of undo/redo operations in the pipeline editor.

This test verifies that the pipeline editor’s undo/redo stack correctly handles:

  • Node creation, deletion, and renaming

  • Plug export, removal, and value updates

  • Link creation, deletion, and restoration

  • Document deletion (in-memory only; disk behavior is not tested)

The test is robust and designed to prevent random crashes. It ensures that all operations are reversible and that the editor’s state remains consistent after each undo/redo cycle.

test_update_auto_inheritance()[source]

Test that PipelineManagerTab.update_auto_inheritance correctly sets the auto_inheritance_dict attribute of a job under different scenarios.

This test covers:
  • Adding a process and verifying that the job’s auto_inheritance_dict is created with the expected key/value mapping.

  • Handling multiple candidate inputs (ensuring correct key/value selection when outputs cannot be inferred automatically).

  • Behavior when the node lacks a project (the attribute should not exist).

  • Behavior when the node is not a valid Process (the attribute should not exist).

Raises:

AssertionError – If expectations about the existence, type, or contents of auto_inheritance_dict are not met.

test_update_inheritance()[source]

Verify that PipelineManagerTab.update_inheritance correctly updates a job’s inheritance dictionary based on the associated node.

This test covers multiple scenarios of inheritance updating:
  • Ensures that jobs do not initially have inheritance_dict attribute

  • Validates update when the node name does not contain “Pipeline”.

  • Validates update when the node name contains “Pipeline”.

  • Validates update when the node’s inheritance history is recorded in the project.

tests: PipelineManagerTab.update_inheritance

test_update_node_list()[source]

Test that adding a process updates the PipelineManagerTab node list.

This test performs the following steps:
  1. Adds a Rename process to the pipeline editor.

  2. Exports the mandatory inputs and outputs for the process.

  3. Initializes the workflow from the pipeline.

  4. Verifies that the node_list is initially empty.

  5. Calls update_node_list and checks that the process is added.

Raises:

AssertionError – If the node list is not updated as expected.

test_z_init_pipeline()[source]

Verify initialization behavior of a pipeline in PipelineManagerTab.

This test covers several scenarios of pipeline initialization:
  • Creating a pipeline with a Rename process and verifying node setup.

  • Checking initialization when mandatory parameters are missing.

  • Handling initialization with mocked requirements and external package dependencies.

  • Simulating a ValueError raised by workflow_from_pipeline.

Target:

PipelineManagerTab.init_pipeline

test_z_runPipeline()[source]

Test running and interrupting a pipeline in PipelineManagerTab.

This test performs the following steps:
  1. Creates a new project folder and adds a sample document.

  2. Switches to the Pipeline Manager tab and adds a Rename process.

  3. Exports mandatory plugs and sets required plug values.

  4. Runs the pipeline while patching dialogs and worker execution.

  5. Verifies that the pipeline completes successfully and resources are released.

  6. Simulates a manual interruption before execution and verifies cleanup.

Components covered:
  • PipelineManagerTab.runPipeline

  • PipelineManagerTab.finish_execution

  • RunProgress

  • RunWorker

test_zz_del_pack()[source]

Ensure that a test package can be removed from the package library.

This test deletes the temporary brick created during previous unit tests (Test_pipeline_1 in User_processes) and verifies that the deletion logic in PackageLibraryDialog.delete_package works as expected.

_classSetupFailed = False
_class_cleanups = []
class populse_mia.tests.run_mia_test.Test_Z_MIAOthers(methodName='runTest')[source]

Bases: TestMIACase

Tests for other parts of the MIA software that do not relate much with the other classes.

Contains:

Methods:

  • _mock_mouse_event: Mocks QMouseEvent for a right-click at position (0, 0).

  • test_check_setup: Checks that Mia’s configuration control is working correctly.

  • test_iteration_table: Plays with the iteration table.

  • test_process_library: Installs the brick_test and then removes it.

  • test_verify_processes: Checks that Mia’s processes control is working correctly.

  • test_z_open_shell: Opens Qt console and kill it afterwards.

_mock_mouse_event()[source]

Returns a mock QMouseEvent for a right-click at position (0, 0).

test_check_setup(mock_exec)[source]

Check that Mia’s configuration control is working correctly.

Tests: utils.verify_setup()

test_iteration_table(mock_exec, mock_pop_up)[source]

Opens a new project, initializes the pipeline iteration and changes its parameters.

Tests: IterationTable behavior without asynchronous dialogs.

Mocks: the execution of a PopUpSelectTagCountTable and a QDialog

test_process_library(mock_msgbox_exec, mock_msgbox_question, mock_menu_exec)[source]

Test editing and context-menu operations in the process library tree.

This test exercises the process library widget displayed in the left panel of the Pipeline Manager tab, which contains the list of available processes and packages.

The following behaviors are verified:
  • insertion of a new package node,

  • MIME data generation for drag-and-drop,

  • renaming of a package,

  • deletion via the Delete key,

  • context-menu action: remove package,

  • context-menu action: delete package with confirmation dialog.

All user interactions involving Qt dialogs or menus are mocked to allow automated execution without GUI blocking.

Parameters:
  • mock_msgbox_exec – Mock for QMessageBox.exec to prevent actual execution of modal dialogs.

  • mock_msgbox_question – Mock for QMessageBox.question used to simulate user confirmation (returns QMessageBox.Yes).

  • mock_menu_exec – Mock for QMenu.exec_ to simulate context menu selection without displaying a GUI menu.

test_verify_processes()[source]

Check that Mia’s processes control is working correctly

Tests: utils.verify_processes()

test_z_open_shell()[source]

Test that MainWindow.open_shell() correctly opens an in-process QtConsole with an IPython kernel.

This test verifies:
  • A RichJupyterWidget is returned

  • The in-process kernel can execute code

  • Application internals are available in the kernel namespace

  • Multiple consoles can coexist safely

_classSetupFailed = False
_class_cleanups = []