Skip to content

Commit

Permalink
cover last graph tests
Browse files Browse the repository at this point in the history
Signed-off-by: Christian López Barrón <chris.gfz@gmail.com>
  • Loading branch information
chrizzFTD committed Dec 8, 2024
1 parent 2d7888c commit 1c92551
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
4 changes: 0 additions & 4 deletions grill/views/_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
47 changes: 27 additions & 20 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand All @@ -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
Expand Down

0 comments on commit 1c92551

Please sign in to comment.