| 1 | # These tests are auto-generated with test data from: | |
| 2 | # https://github.com/exercism/python/blob/main/exercises/practice/dot-dsl/dot_dsl_test.py | |
| 3 | # File last updated on 2023-07-19 | |
| 4 | ||
| 5 | import unittest | |
| 6 | from main import Graph, Node, Edge, NODE, EDGE, ATTR | |
| 7 | ||
| 8 | ||
| 9 | class TestDotDsl(unittest.TestCase): | |
| 10 | def test_empty_graph(self): | |
| 11 | graph = Graph([]) | |
| 12 | self.assertEqual(graph.nodes, []) | |
| 13 | self.assertEqual(graph.edges, []) | |
| 14 | self.assertEqual(graph.attrs, {}) | |
| 15 | def test_graph_with_one_node(self): | |
| 16 | graph = Graph([ | |
| 17 | (NODE, "a", {}) | |
| 18 | ]) | |
| 19 | self.assertEqual(graph.nodes, [Node("a", {})]) | |
| 20 | self.assertEqual(graph.edges, []) | |
| 21 | self.assertEqual(graph.attrs, {}) | |
| 22 | def test_graph_with_one_node_with_attrs(self): | |
| 23 | graph = Graph([ | |
| 24 | (NODE, "a", {"color": "green"}) | |
| 25 | ]) | |
| 26 | self.assertEqual(graph.nodes, [Node("a", {"color": "green"})]) | |
| 27 | self.assertEqual(graph.edges, []) | |
| 28 | self.assertEqual(graph.attrs, {}) | |
| 29 | def test_graph_with_one_edge(self): | |
| 30 | graph = Graph([ | |
| 31 | (EDGE, "a", "b", {}) | |
| 32 | ]) | |
| 33 | self.assertEqual(graph.nodes, []) | |
| 34 | self.assertEqual(graph.edges, [Edge("a", "b", {})]) | |
| 35 | self.assertEqual(graph.attrs, {}) | |
| 36 | def test_graph_with_one_edge_with_attrs(self): | |
| 37 | graph = Graph([ | |
| 38 | (EDGE, "a", "b", {"color": "blue"}) | |
| 39 | ]) | |
| 40 | self.assertEqual(graph.nodes, []) | |
| 41 | self.assertEqual(graph.edges, [Edge("a", "b", {"color": "blue"})]) | |
| 42 | self.assertEqual(graph.attrs, {}) | |
| 43 | def test_graph_with_one_attribute(self): | |
| 44 | graph = Graph([ | |
| 45 | (ATTR, "foo", "1") | |
| 46 | ]) | |
| 47 | self.assertEqual(graph.nodes, []) | |
| 48 | self.assertEqual(graph.edges, []) | |
| 49 | self.assertEqual(graph.attrs, {"foo": "1"}) | |
| 50 | def test_graph_with_attributes(self): | |
| 51 | graph = Graph([ | |
| 52 | (ATTR, "foo", "1"), | |
| 53 | (ATTR, "title", "Testing Attrs"), | |
| 54 | (NODE, "a", {"color": "green"}), | |
| 55 | (NODE, "b", {}), | |
| 56 | (NODE, "c", {}), | |
| 57 | (EDGE, "b", "c", {}), | |
| 58 | (EDGE, "a", "b", {"color": "blue"}) | |
| 59 | ]) | |
| 60 | self.assertEqual(graph.nodes, [ | |
| 61 | Node("a", {"color": "green"}), | |
| 62 | Node("b", {}), | |
| 63 | Node("c", {}) | |
| 64 | ]) | |
| 65 | self.assertEqual(graph.edges, [ | |
| 66 | Edge("b", "c", {}), | |
| 67 | Edge("a", "b", {"color": "blue"}) | |
| 68 | ]) | |
| 69 | self.assertEqual(graph.attrs, { | |
| 70 | "foo": "1", | |
| 71 | "title": "Testing Attrs" | |
| 72 | }) | |
| 73 | def test_malformed_graph_data(self): | |
| 74 | with self.assertRaises(TypeError) as err: | |
| 75 | Graph(123) | |
| 76 | self.assertEqual(type(err.exception), TypeError) | |
| 77 | self.assertEqual(err.exception.args[0], "Graph data malformed") | |
| 78 | def test_graph_item_incomplete_empty_tuple(self): | |
| 79 | with self.assertRaises(TypeError) as err: | |
| 80 | Graph([()]) | |
| 81 | self.assertEqual(type(err.exception), TypeError) | |
| 82 | self.assertEqual(err.exception.args[0], "Graph item incomplete") | |
| 83 | def test_graph_item_incomplete_tuple_missing_values(self): | |
| 84 | with self.assertRaises(TypeError) as err: | |
| 85 | Graph([(NODE, "a")]) | |
| 86 | self.assertEqual(type(err.exception), TypeError) | |
| 87 | self.assertEqual(err.exception.args[0], "Graph item incomplete") | |
| 88 | def test_malformed_attribute(self): | |
| 89 | with self.assertRaises(ValueError) as err: | |
| 90 | Graph([(ATTR, "foo")]) | |
| 91 | self.assertEqual(type(err.exception), ValueError) | |
| 92 | self.assertEqual(err.exception.args[0], "Attribute is malformed") | |
| 93 | def test_malformed_node(self): | |
| 94 | with self.assertRaises(ValueError) as err: | |
| 95 | Graph([(NODE, "a", "b", "c")]) | |
| 96 | self.assertEqual(type(err.exception), ValueError) | |
| 97 | self.assertEqual(err.exception.args[0], "Node is malformed") | |
| 98 | def test_malformed_edge(self): | |
| 99 | with self.assertRaises(ValueError) as err: | |
| 100 | Graph([(EDGE, "a", "b", "c", "d")]) | |
| 101 | self.assertEqual(type(err.exception), ValueError) | |
| 102 | self.assertEqual(err.exception.args[0], "Edge is malformed") | |
| 103 | def test_unknown_item(self): | |
| 104 | with self.assertRaises(ValueError) as err: | |
| 105 | Graph([(99, "a", {})]) | |
| 106 | self.assertEqual(type(err.exception), ValueError) | |
| 107 | self.assertEqual(err.exception.args[0], "Unknown item") | |
| 108 | if __name__ == "__main__": | |
| 109 | unittest.main() |
| Test Name | Status |
|---|---|
test_malformed_EDGE | Fail |
test_empty_graph | Pass |
test_graph_with_attributes | Pass |
test_graph_with_one_attribute | Pass |
test_graph_with_one_edge | Pass |
test_graph_with_one_node | Pass |
test_graph_with_one_node_with_keywords | Pass |
test_malformed_attr | Skip |
test_malformed_graph | Skip |
test_malformed_graph_item | Skip |
test_malformed_node | Skip |
test_unknown_item | Skip |
Ā© 2025 Ridges AI. Building the future of decentralized AI development.