From 1c92551caf13f3930eacd053305cc121f3dbd2b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=B3pez=20Barr=C3=B3n?= Date: Sun, 8 Dec 2024 15:51:12 +1100 Subject: [PATCH] cover last graph tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian López Barrón --- grill/views/_graph.py | 4 ---- tests/test_views.py | 47 +++++++++++++++++++++++++------------------ 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/grill/views/_graph.py b/grill/views/_graph.py index 14700fc7..0e4639a5 100644 --- a/grill/views/_graph.py +++ b/grill/views/_graph.py @@ -444,7 +444,6 @@ def wheelEvent(self, event): modifiers = event.modifiers() if modifiers == QtCore.Qt.ControlModifier: - raise RuntimeError zoom_factor = 1.2 if event.angleDelta().y() > 0 else 0.8 self.scale(zoom_factor, zoom_factor) elif modifiers == QtCore.Qt.AltModifier: @@ -537,7 +536,6 @@ def __init__(self, graph: nx.DiGraph = None, parent=None): self.url_id_prefix = "" def _graph_url_changed(self, *_, **__): - raise RuntimeError sender = self.sender() key = next((k for k, v in self._nodes_map.items() if v==sender), None) if key is None: @@ -772,7 +770,6 @@ def setDotPath(self, path): self._threadpool.start(dot2svg) def _on_dot_error(self, message): - raise RuntimeError self._error_view.setVisible(True) self._graph_view.setVisible(False) self._error_view.setText(message) @@ -814,7 +811,6 @@ def url_id_prefix(self): return "_node_id_" def _graph_url_changed(self, url: QtCore.QUrl): - raise RuntimeError node_uri = url.toString() node_uri_stem = node_uri.split("/")[-1] if node_uri_stem.startswith(self.url_id_prefix): diff --git a/tests/test_views.py b/tests/test_views.py index 913dba1c..eb20c424 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -284,14 +284,7 @@ class MiniAsset(names.UsdAsset): widget = create.TaxonomyEditor() # GraphView capabilities are tested elsewhere, so mock 'view' here. widget._graph_view.view = lambda indices: None - # if isinstance(widget._graph_view, _graph.GraphView): - # with self.assertRaisesRegex(LookupError, "Could not find sender"): - # invalid_uril = QtCore.QUrl(f"{widget._graph_view.url_id_prefix}not_a_digit") - # widget._graph_view._graph_url_changed(invalid_uril) - # else: - # with self.assertRaisesRegex(RuntimeError, "'graph' attribute not set yet"): - # invalid_uril = QtCore.QUrl(f"{widget._graph_view.url_id_prefix}not_a_digit") - # widget._graph_view._graph_url_changed(invalid_uril) + widget.setStage(stage) widget._amount.setValue(3) # TODO: create 10 assets, clear tmp directory @@ -663,17 +656,20 @@ def test_stats(self): def test_graph_views(self): viewer = _graph.GraphView() - for invalid_node_data, error_message in ( - (dict(shape='record'), "'label' must be supplied"), - (dict(shape='record', label='no record'), "a record 'label' in the form of"), - (dict(shape='record', label='{1}'), "a record 'label' in the form of"), - (dict(shape='record', label='{<0>1}', plugs={'first': 1, 'second': 2}), "record 'shape' and 'ports' are mutually exclusive"), - (dict(shape='none'), "A label must be provided"), + with ( + mock.patch(f"grill.views._graph.drawing.nx_pydot.graphviz_layout", new=lambda graph, **__: dict.fromkeys(graph.nodes, (0,0))), ): - invalid_graph = _graph.nx.MultiDiGraph() - invalid_graph.add_nodes_from([(1, invalid_node_data)]) - with self.assertRaisesRegex(ValueError, error_message): - viewer.graph = invalid_graph + for invalid_node_data, error_message in ( + (dict(shape='record'), "'label' must be supplied"), + (dict(shape='record', label='no record'), "a record 'label' in the form of"), + (dict(shape='record', label='{1}'), "a record 'label' in the form of"), + (dict(shape='record', label='{<0>1}', plugs={'first': 1, 'second': 2}), "record 'shape' and 'ports' are mutually exclusive"), + (dict(shape='none'), "A label must be provided"), + ): + invalid_graph = _graph.nx.MultiDiGraph() + invalid_graph.add_nodes_from([(1, invalid_node_data)]) + with self.assertRaisesRegex(ValueError, error_message): + viewer.graph = invalid_graph viewer = _graph.GraphView() viewer.view(tuple()) @@ -794,7 +790,19 @@ def _test_positions(graph, prog): for cls in _graph.GraphView, _graph._GraphSVGViewer: for pixmap_enabled in ((True, False) if cls == _graph._GraphSVGViewer else (False,)): _graph._USE_SVG_VIEWPORT = pixmap_enabled + child = cls(parent=widget) + + if isinstance(child, _graph.GraphView): + with self.assertRaisesRegex(LookupError, "Could not find sender"): + invalid_uril = QtCore.QUrl(f"{child.url_id_prefix}not_a_digit") + child._graph_url_changed(invalid_uril) + else: + with self.assertRaisesRegex(RuntimeError, "'graph' attribute not set yet"): + invalid_uril = QtCore.QUrl(f"{child.url_id_prefix}not_a_digit") + child._graph_url_changed(invalid_uril) + child._on_dot_error("nothing set yet") + if cls == _graph._GraphSVGViewer and not pixmap_enabled: # QWebEngineView in use, no need to test its 'load' method child._graph_view.load = lambda fp: None @@ -846,8 +854,6 @@ def _test_positions(graph, prog): child.view(graph.nodes) def test_zoom(self): - return - """Zoom is triggered by ctrl + mouse wheel""" view = _graph._GraphicsViewport() @@ -869,6 +875,7 @@ def test_zoom(self): # Assert that the scale has changed according to the zoom logic self.assertGreater(zoomed_in_scale, initial_scale) + angleDelta_zoomOut = QtCore.QPoint(-120, 0) # ZOOM OUT