From a92fca43f702b1671b29a1f6c2ff8c5c3b1445c2 Mon Sep 17 00:00:00 2001 From: Ramon Figueiredo Date: Tue, 29 Oct 2024 09:47:01 -0700 Subject: [PATCH] [cuegui] Fix FrameContextMenu and test_rightClickItem to handle NoneType job attribute (#1561) - Ensure the job attribute is set before triggering the context menu event. - Mock the getLayers method to return an empty list to avoid NoneType errors. --- cuegui/cuegui/FrameMonitorTree.py | 37 +++++++++++++------------- cuegui/tests/FrameMonitorTree_tests.py | 8 +++--- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/cuegui/cuegui/FrameMonitorTree.py b/cuegui/cuegui/FrameMonitorTree.py index 8131b6c2f..46da7ee30 100644 --- a/cuegui/cuegui/FrameMonitorTree.py +++ b/cuegui/cuegui/FrameMonitorTree.py @@ -915,24 +915,25 @@ def __init__(self, widget, filterSelectedLayersCallback, readonly=False): if cuegui.Constants.OUTPUT_VIEWERS: job = widget.getJob() - outputPaths = [] - selectedFrames = widget.selectedObjects() - - layers_dict = {layer.name(): layer for layer in job.getLayers()} - - for frame in selectedFrames: - layer_name = frame.layer() - layer = layers_dict.get(layer_name) - if layer: - outputPaths.extend(cuegui.Utils.getOutputFromFrame(layer, frame)) - - if outputPaths: - for viewer in cuegui.Constants.OUTPUT_VIEWERS: - self.addAction(viewer['action_text'], - functools.partial(cuegui.Utils.viewFramesOutput, - job, - selectedFrames, - viewer['action_text'])) + if job is not None: + outputPaths = [] + selectedFrames = widget.selectedObjects() + + layers_dict = {layer.name(): layer for layer in job.getLayers()} + + for frame in selectedFrames: + layer_name = frame.layer() + layer = layers_dict.get(layer_name) + if layer: + outputPaths.extend(cuegui.Utils.getOutputFromFrame(layer, frame)) + + if outputPaths: + for viewer in cuegui.Constants.OUTPUT_VIEWERS: + self.addAction(viewer['action_text'], + functools.partial(cuegui.Utils.viewFramesOutput, + job, + selectedFrames, + viewer['action_text'])) if self.app.applicationName() == "CueCommander": self.__menuActions.frames().addAction(self, "viewHost") diff --git a/cuegui/tests/FrameMonitorTree_tests.py b/cuegui/tests/FrameMonitorTree_tests.py index 27190fd8d..67d68fc35 100644 --- a/cuegui/tests/FrameMonitorTree_tests.py +++ b/cuegui/tests/FrameMonitorTree_tests.py @@ -131,9 +131,11 @@ def test_rightClickItem(self, execMock): # Ensure the job attribute is set self.frameMonitorTree.setJob(self.job) - self.frameMonitorTree.contextMenuEvent( - qtpy.QtGui.QContextMenuEvent( - qtpy.QtGui.QContextMenuEvent.Reason.Mouse, mouse_position, mouse_position)) + # Mock the getLayers method to return an empty list or a list of mock layers + with mock.patch.object(self.job, 'getLayers', return_value=[]): + self.frameMonitorTree.contextMenuEvent( + qtpy.QtGui.QContextMenuEvent( + qtpy.QtGui.QContextMenuEvent.Reason.Mouse, mouse_position, mouse_position)) execMock.assert_called_with(mouse_position)