def setUp(self): g = networkx.DiGraph() self.container = GraphContainer(graph=g) self.tool = GraphNodeSelectionTool(component=self.container) self.container.tools.append(self.tool) node = GraphNodeComponent(position=[0, 0]) self.container.components.append(node)
class TestGraphNodeSelectionTool(unittest.TestCase): def setUp(self): g = networkx.DiGraph() self.container = GraphContainer(graph=g) self.tool = GraphNodeSelectionTool(component=self.container) self.container.tools.append(self.tool) node = GraphNodeComponent(position=[0, 0]) self.container.components.append(node) def tearDown(self): del self.container del self.tool def test_normal_left_dclick_in(self): event = BasicEvent(x=0, y=0, handled=False) node = self.container.components[0] node.edit_traits = mock.Mock() self.tool.normal_left_dclick(event) node.edit_traits.assert_called_once_with(kind='livemodal') def test_normal_left_dclick_not_in(self): event = BasicEvent(x=50, y=50, handled=False) node = self.container.components[0] node.edit_traits = mock.Mock() self.tool.normal_left_dclick(event) node.edit_traits.assert_not_called() self.assertFalse(event.handled) def test_traited_node(self): event = BasicEvent(x=0, y=0, handled=False) self.container.components.pop(0) node = GraphNodeComponent(value=TraitedNodeValue(label='traited_node'), position=[0, 0]) self.container.components.append(node) self.tool.normal_left_dclick(event) node.value.edit_traits.assert_called_once_with()
def __canvas_default(self): """ default setter for _canvas """ if self.graph.is_directed(): container = DAGContainer(style=self.layout) else: container = GraphContainer(style=self.layout) container.tools.append(GraphNodeSelectionTool(component=container)) container.tools.append( GraphNodeHoverTool(component=container, callback=self._on_hover)) container.tools.append(GraphNodeDragTool(component=container)) return container
class TestGraphNodeSelectionTool(unittest.TestCase): def setUp(self): g = networkx.DiGraph() self.container = GraphContainer(graph=g) self.tool = GraphNodeSelectionTool(component=self.container) self.container.tools.append(self.tool) node = GraphNodeComponent(position=[0, 0]) self.container.components.append(node) def tearDown(self): del self.container del self.tool def test_normal_left_dclick_in(self): event = BasicEvent(x=0, y=0, handled=False) node = self.container.components[0] node.edit_traits = mock.Mock() self.tool.normal_left_dclick(event) node.edit_traits.assert_called_once_with(kind='livemodal') def test_normal_left_dclick_not_in(self): event = BasicEvent(x=50, y=50, handled=False) node = self.container.components[0] node.edit_traits = mock.Mock() self.tool.normal_left_dclick(event) node.edit_traits.assert_not_called() self.assertFalse(event.handled) def test_traited_node(self): event = BasicEvent(x=0, y=0, handled=False) self.container.components.pop(0) node = GraphNodeComponent( value=TraitedNodeValue(label='traited_node'), position=[0, 0], ) self.container.components.append(node) self.tool.normal_left_dclick(event) node.value.edit_traits.assert_called_once_with()