def test_graph_changed(self): d = {'a':['b'], 'b':['c', 'd'], 'c':[], 'd':[], 'e':['d']} g = graph_from_dict(d) view = GraphView(graph=g, layout='spring') new_d = {'f':['g'], 'g':['h', 'i', 'j'], 'h':[], 'i':[], 'j':[]} new_g = graph_from_dict(new_d) view.graph = new_g self.assertListEqual(view.nodes, new_g.nodes())
def test_graph_changed(self): d = {'a': ['b'], 'b': ['c', 'd'], 'c': [], 'd': [], 'e': ['d']} g = graph_from_dict(d) view = GraphView(graph=g, layout='spring') new_d = {'f': ['g'], 'g': ['h', 'i', 'j'], 'h': [], 'i': [], 'j': []} new_g = graph_from_dict(new_d) view.graph = new_g self.assertListEqual(view.nodes, new_g.nodes())
def test_graph_from_dict(self): d = {'a': ['b'], 'b': ['c', 'd'], 'c': [], 'd': [], 'e': ['d']} g = graph_from_dict(d) for key, value in d.items(): children = g.successors(key) expected_children = value self.assertListEqual(children, expected_children)
def test_graph_from_dict(self): d = {'a':['b'], 'b':['c', 'd'], 'c':[], 'd':[], 'e':['d']} g = graph_from_dict(d) for key, value in d.iteritems(): children = g.successors(key) expected_children = value self.assertListEqual(children, expected_children)
def test_on_hover(self, mock_stdout): view = GraphView(graph=graph_from_dict({'test':['test1']})) hover_tool = view._canvas.tools[-1] hover_tool._last_xy = (0, 0) hover_tool.on_hover() self.assertEqual(mock_stdout.getvalue(), 'hovering over: test\nhovering over: test1\n')
def test_on_hover(self, mock_stdout): view = GraphView(graph=graph_from_dict({'test': ['test1']})) _, hover_tool, _ = view._canvas.tools hover_tool._last_xy = (0, 0) hover_tool.on_hover() self.assertEqual(mock_stdout.getvalue(), 'hovering over: test\nhovering over: test1\n')
def test_draw_not_directed(self): d = {'a': ['b'], 'b': ['c', 'd'], 'c': [], 'd': []} g = graph_from_dict(d) g = g.to_undirected() container = GraphContainer(graph=g) for node in g.nodes(): GraphNodeComponent(container=container, value=node) self.assertPathsAreCreated(container)
def test_on_hover(self): view = GraphView(graph=graph_from_dict({'test': ['test1']})) _, hover_tool, _ = view._canvas.tools hover_tool._last_xy = (0, 0) with mock.patch('sys.stdout', new=StringIO()) as mock_stdout: hover_tool.on_hover() result_value = mock_stdout.getvalue() self.assertIn('hovering over: test\n', result_value) self.assertIn('hovering over: test1\n', result_value)
def test_node_changed(self, mock_stdout): a = DummyHasTraitsObject(label='a') b = DummyHasTraitsObject(label='b') c = DummyHasTraitsObject(label='c') d = {a: [b], b: [c], c: []} g = graph_from_dict(d) view = GraphView(graph=g, layout='spring') a.label = 'test' self.assertEqual(mock_stdout.getvalue(), 'node changed\n')
def create_graph_container(self): """ Utility method to generate a GraphContainer with a simple graph for re-use in several tests herein. """ d = {'a': ['b'], 'b': ['c', 'd'], 'c': [], 'd': []} g = graph_from_dict(d) container = GraphContainer(graph=g) for node in g.nodes(): GraphNodeComponent(container=container, value=node) return container
def test_node_changed(self): a = DummyHasTraitsObject(label='a') b = DummyHasTraitsObject(label='b') c = DummyHasTraitsObject(label='c') d = {a: [b], b: [c], c: []} g = graph_from_dict(d) GraphView(graph=g, layout='spring') with mock.patch('sys.stdout', new=StringIO()) as mock_stdout: a.label = u'test' self.assertEqual(mock_stdout.getvalue(), 'node changed\n')
def test_draw_directed_arrow_direction(self): d = {'a': ['b'], 'b': []} g = graph_from_dict(d) container = GraphContainer(graph=g) for node in g.nodes(): GraphNodeComponent(container=container, value=node) # Node a is to the left of node b container._layout_needed = False container.components[0].x = 0.0 container.components[1].x = 100.0 container.components[0].y = 0.0 container.components[1].y = 0.0 self.assertPathsAreCreated(container) # Node a is to the right of node b container._layout_needed = False container.components[0].x = 100.0 container.components[1].x = 0.0 container.components[0].y = 0.0 container.components[1].y = 0.0 self.assertPathsAreCreated(container) # Node a is above of node b container._layout_needed = False container.components[0].x = 0.0 container.components[1].x = 0.0 container.components[0].y = 0.0 container.components[1].y = 100.0 self.assertPathsAreCreated(container) # Node a is below of node b container._layout_needed = False container.components[0].x = 0.0 container.components[1].x = 0.0 container.components[0].y = 100.0 container.components[1].y = 0.0 self.assertPathsAreCreated(container)
def test_no_nodes(self): container = GraphContainer(graph=graph_from_dict({})) self.assertTrue(container.components == []) result = container.do_layout() self.assertIsNone(result)
def setUp(self): d = {'a':['b'], 'b':['c', 'd'], 'c':[], 'd':[], 'e':['d']} self.g = graph_from_dict(d) self.view = GraphView(graph=self.g, layout='spring')
def setUp(self): d = {'a': ['b'], 'b': ['c', 'd'], 'c': [], 'd': [], 'e': ['d']} self.g = graph_from_dict(d) self.view = GraphView(graph=self.g, layout='spring')