def test_write(self): correct_output_a = """graph [ directed 1 node [ id 0 label "1" a 1 ] node [ id 1 label "2" ] edge [ source 0 target 1 x "x" ] edge [ source 1 target 0 label "zzzz" ] ]""" correct_output_b = """graph [ directed 1 node [ id 0 label "2" ] node [ id 1 label "1" a 1 ] edge [ source 1 target 0 x "x" ] edge [ source 0 target 1 label "zzzz" ] ]""" out = StringIO() writer = GmlWriter(out) graph = DiGraph() graph.add_node(1, {'a': 1}) graph.add_edge(1, 2, {'x': 'x'}) graph.add_edge(2, 1, "zzzz") writer.write(graph) self.assertIn(out.getvalue(), set([correct_output_a, correct_output_b]))
def test_write(self): correct_output_a = """graph [ directed 1 node [ id 0 label "1" a 1 ] node [ id 1 label "2" ] edge [ source 0 target 1 x "x" ] edge [ source 1 target 0 label "zzzz" ] ]""" correct_output_b = """graph [ directed 1 node [ id 0 label "2" ] node [ id 1 label "1" a 1 ] edge [ source 1 target 0 x "x" ] edge [ source 0 target 1 label "zzzz" ] ]""" out = StringIO() writer = GmlWriter(out) graph = DiGraph() graph.add_node(1, {'a' : 1 }) graph.add_edge(1, 2, {'x' : 'x'}) graph.add_edge(2, 1, "zzzz") writer.write(graph) self.assertIn(out.getvalue(), set([correct_output_a, correct_output_b]))
def test_write(self): correct_output = """graph [ directed 1 node [ id 0 label "1" a 1 abb "[1, 2]" bb 2 ] node [ id 1 label "2" ] node [ id 2 label "3" ] node [ id 3 label "4" ] node [ id 4 label "5" ] edge [ source 0 target 1 ] edge [ source 0 target 3 x "x" ] edge [ source 1 target 2 ] edge [ source 2 target 3 ] edge [ source 2 target 4 ] edge [ source 4 target 1 label "zzzz" ] ]""" out = StringIO() writer = GmlWriter(out) graph = DiGraph([(1,2), (2,3), (3,4), (3,5)]) graph.update_node(1, {'a' : 1, 'bb' : 2, 'abb' : [1, 2] }) graph.add_edge(1, 4, {'x' : 'x'}) graph.add_edge(5, 2, "zzzz") writer.write(graph) self.assertEqual(correct_output, out.getvalue())