Exemplo n.º 1
0
 def test_graph_deserialize_unordered_adjacency(self):
     test_base = {
         "A1": ["B1", "B2"],
         "B1": ["C1", "C2"],
         "B2": ["C3", "C2"],
         "C1": [],
         "C2": [],
         "C3": [],
     }
     test_graph = graph.build_graph(test_base.keys(), test_base.__getitem__)
     packed_graph = graph.pack_graph(test_graph)
     reversed_adjacency = tuple(reversed(packed_graph.adjacency))
     packed_graph = graph.PackedGraph(packed_graph.nodes,
                                      reversed_adjacency)
     with self.assertRaisesRegex(exception.InvalidInput, "adjacency list"):
         graph.unpack_graph(packed_graph)
Exemplo n.º 2
0
 def test_graph_deserialize_unordered_adjacency(self):
     test_base = {
         "A1": ["B1", "B2"],
         "B1": ["C1", "C2"],
         "B2": ["C3", "C2"],
         "C1": [],
         "C2": [],
         "C3": [],
     }
     test_graph = graph.build_graph(test_base.keys(), test_base.__getitem__)
     packed_graph = graph.pack_graph(test_graph)
     reversed_adjacency = tuple(reversed(packed_graph.adjacency))
     packed_graph = graph.PackedGraph(packed_graph.nodes,
                                      reversed_adjacency)
     with self.assertRaisesRegex(exception.InvalidInput, "adjacency list"):
         graph.unpack_graph(packed_graph)
Exemplo n.º 3
0
    def test_graph_pack_unpack(self):
        test_base = {
            "A1": ["B1", "B2"],
            "B1": ["C1", "C2"],
            "B2": ["C3", "C2"],
            "C1": [],
            "C2": [],
            "C3": [],
        }

        test_graph = graph.build_graph(test_base.keys(), test_base.__getitem__)
        packed_graph = graph.pack_graph(test_graph)
        unpacked_graph = graph.unpack_graph(packed_graph)
        self.assertEqual(test_graph, unpacked_graph)
Exemplo n.º 4
0
    def test_graph_pack_unpack(self):
        test_base = {
            "A1": ["B1", "B2"],
            "B1": ["C1", "C2"],
            "B2": ["C3", "C2"],
            "C1": [],
            "C2": [],
            "C3": [],
        }

        test_graph = graph.build_graph(test_base.keys(), test_base.__getitem__)
        packed_graph = graph.pack_graph(test_graph)
        unpacked_graph = graph.unpack_graph(packed_graph)
        self.assertEqual(test_graph, unpacked_graph)
Exemplo n.º 5
0
    def test_pack_unpack_graph(self):
        test_base = {
            "A1": ["B1", "B2", "B3", "B4"],
            "B1": [],
            "B2": [],
            "B3": ["B1"],
            "B4": ["B2"],
        }

        test_graph = graph.build_graph(test_base.keys(), test_base.__getitem__)
        packed_graph = graph.pack_graph(test_graph)
        unpacked_graph = graph.unpack_graph(packed_graph)
        self.assertEqual(len(test_graph), len(unpacked_graph))
        for start_node in test_graph:
            self.assertIn(start_node, unpacked_graph)
Exemplo n.º 6
0
    def test_pack_unpack_graph(self):
        test_base = {
            "A1": ["B1", "B2", "B3", "B4"],
            "B1": [],
            "B2": [],
            "B3": ["B1"],
            "B4": ["B2"],
        }

        test_graph = graph.build_graph(test_base.keys(), test_base.__getitem__)
        packed_graph = graph.pack_graph(test_graph)
        unpacked_graph = graph.unpack_graph(packed_graph)
        self.assertEqual(len(test_graph), len(unpacked_graph))
        for start_node in test_graph:
            self.assertIn(start_node, unpacked_graph)
Exemplo n.º 7
0
    def test_graph_serialize_deserialize(self):
        Format = namedtuple('Format', ['loads', 'dumps'])
        formats = [
            Format(jsonutils.loads, jsonutils.dumps),
            Format(msgpackutils.loads, msgpackutils.dumps),
        ]
        test_base = {
            "A1": ["B1", "B2"],
            "B1": ["C1", "C2"],
            "B2": ["C3", "C2"],
            "C1": [],
            "C2": [],
            "C3": [],
        }

        test_graph = graph.build_graph(test_base.keys(), test_base.__getitem__)
        for fmt in formats:
            serialized = fmt.dumps(graph.pack_graph(test_graph))
            unserialized = graph.unpack_graph(fmt.loads(serialized))
            self.assertEqual(test_graph, unserialized)
Exemplo n.º 8
0
    def test_graph_serialize_deserialize(self):
        Format = namedtuple('Format', ['loads', 'dumps'])
        formats = [
            Format(jsonutils.loads, jsonutils.dumps),
            Format(msgpackutils.loads, msgpackutils.dumps),
        ]
        test_base = {
            "A1": ["B1", "B2"],
            "B1": ["C1", "C2"],
            "B2": ["C3", "C2"],
            "C1": [],
            "C2": [],
            "C3": [],
        }

        test_graph = graph.build_graph(test_base.keys(), test_base.__getitem__)
        for fmt in formats:
            serialized = fmt.dumps(graph.pack_graph(test_graph))
            unserialized = graph.unpack_graph(fmt.loads(serialized))
            self.assertEqual(test_graph, unserialized)