Esempio n. 1
0
    def test_malformed_graph_item(self):
        with self.assertRaises(TypeError) as err:
            Graph([()])
        self.assertEqual(type(err.exception), TypeError)
        self.assertEqual(err.exception.args[0], "Graph item incomplete")

        with self.assertRaises(TypeError) as err:
            Graph([(ATTR, )])
        self.assertEqual(type(err.exception), TypeError)
        self.assertEqual(err.exception.args[0], "Graph item incomplete")
Esempio n. 2
0
    def test_malformed_graph(self):
        with self.assertRaises(TypeError) as err:
            Graph(1)
        self.assertEqual(type(err.exception), TypeError)
        self.assertEqual(err.exception.args[0], "Graph data malformed")

        with self.assertRaises(TypeError) as err:
            Graph("problematic")
        self.assertEqual(type(err.exception), TypeError)
        self.assertEqual(err.exception.args[0], "Graph data malformed")
Esempio n. 3
0
    def test_graph_with_attributes(self):
        g = Graph(
            [
                (ATTR, "foo", "1"),
                (ATTR, "title", "Testing Attrs"),
                (NODE, "a", {"color": "green"}),
                (NODE, "c", {}),
                (NODE, "b", {"label": "Beta!"}),
                (EDGE, "b", "c", {}),
                (EDGE, "a", "b", {"color": "blue"}),
                (ATTR, "bar", "true"),
            ]
        )

        self.assertEqual(
            g.nodes,
            [
                Node("a", {"color": "green"}),
                Node("c", {}),
                Node("b", {"label": "Beta!"}),
            ],
        )
        self.assertEqual(
            g.edges, [Edge("b", "c", {}), Edge("a", "b", {"color": "blue"})]
        )
        self.assertEqual(g.attrs, {"foo": "1", "title": "Testing Attrs", "bar": "true"})
Esempio n. 4
0
 def test_malformed_node(self):
     with self.assertRaisesWithMessage(ValueError):
         Graph([(NODE, 1, 2, 3)])
Esempio n. 5
0
 def test_malformed_attr(self):
     with self.assertRaisesWithMessage(ValueError):
         Graph([(ATTR, 1, 2, 3)])
Esempio n. 6
0
    def test_malformed_graph_item(self):
        with self.assertRaisesWithMessage(TypeError):
            Graph([()])

        with self.assertRaisesWithMessage(TypeError):
            Graph([(ATTR, )])
Esempio n. 7
0
    def test_malformed_graph(self):
        with self.assertRaisesWithMessage(TypeError):
            Graph(1)

        with self.assertRaisesWithMessage(TypeError):
            Graph("problematic")
Esempio n. 8
0
    def test_empty_graph(self):
        g = Graph()

        self.assertEqual(g.nodes, [])
        self.assertEqual(g.edges, [])
        self.assertEqual(g.attrs, {})
Esempio n. 9
0
    def test_graph_with_one_attribute(self):
        g = Graph([(ATTR, "foo", "1")])

        self.assertEqual(g.nodes, [])
        self.assertEqual(g.edges, [])
        self.assertEqual(g.attrs, {"foo": "1"})
Esempio n. 10
0
 def test_unknown_item(self):
     with self.assertRaises(ValueError) as err:
         Graph([(99, 1, 2)])
     self.assertEqual(type(err.exception), ValueError)
     self.assertEqual(err.exception.args[0], "Unknown item")
Esempio n. 11
0
    def test_graph_with_one_node_with_keywords(self):
        g = Graph([(NODE, "a", {"color": "green"})])

        self.assertEqual(g.nodes, [Node("a", {"color": "green"})])
        self.assertEqual(g.edges, [])
        self.assertEqual(g.attrs, {})
Esempio n. 12
0
    def test_graph_with_one_node(self):
        g = Graph([(NODE, "a", {})])

        self.assertEqual(g.nodes, [Node("a", {})])
        self.assertEqual(g.edges, [])
        self.assertEqual(g.attrs, {})
Esempio n. 13
0
 def test_malformed_EDGE(self):
     with self.assertRaises(ValueError) as err:
         Graph([(EDGE, 1, 2)])
     self.assertEqual(type(err.exception), ValueError)
     self.assertEqual(err.exception.args[0], "Edge is malformed")
Esempio n. 14
0
 def test_malformed_node(self):
     with self.assertRaises(ValueError) as err:
         Graph([(NODE, 1, 2, 3)])
     self.assertEqual(type(err.exception), ValueError)
     self.assertEqual(err.exception.args[0], "Node is malformed")
Esempio n. 15
0
 def test_malformed_attr(self):
     with self.assertRaises(ValueError) as err:
         Graph([(ATTR, 1, 2, 3)])
     self.assertEqual(type(err.exception), ValueError)
     self.assertEqual(err.exception.args[0], "Attribute is malformed")
Esempio n. 16
0
 def test_malformed_EDGE(self):
     with self.assertRaisesWithMessage(ValueError):
         Graph([(EDGE, 1, 2)])
Esempio n. 17
0
 def test_unknown_item(self):
     with self.assertRaisesWithMessage(ValueError):
         Graph([(99, 1, 2)])
Esempio n. 18
0
    def test_graph_with_one_edge(self):
        g = Graph([(EDGE, "a", "b", {})])

        self.assertEqual(g.nodes, [])
        self.assertEqual(g.edges, [Edge("a", "b", {})])
        self.assertEqual(g.attrs, {})