Exemplo n.º 1
0
 def create_runnable_graph_from_node(self, node):
     graph = QueryGraph()
     graph.add_node(copy(node))
     depList = node.get_dependencies()
     while len(depList) != 0:
         [graph.add_node(copy(x)) for x in depList]
         dependentNodes = [x.get_dependencies() for x in depList]
         depList = [item for sublist in dependentNodes for item in sublist]
     return graph
Exemplo n.º 2
0
 def create_runnable_graph_from_node(self, node):
     graph = QueryGraph()
     graph.add_node(copy(node))
     depList = node.get_dependencies()
     while len(depList) != 0:
         [graph.add_node(copy(x)) for x in depList]
         dependentNodes = [x.get_dependencies() for x in depList]
         depList = [item for sublist in dependentNodes for item in sublist]
     return graph
Exemplo n.º 3
0
    def test_add_with_replacement_replaces_proper_nodes(self):
        oldGraph = QueryGraph()
        node = SqlCTENode("test", "Im the text content of the test node")
        oldGraph.add_node(node)
        newNode = SqlCTENode("test", "Im the text content of the test node")
        newGraph = QueryGraph()
        newGraph.add_node(newNode)

        oldGraph.add_query(newGraph, replace=True)

        self.assertTrue(newNode is oldGraph.node_lookup["test"])
Exemplo n.º 4
0
    def test_value_replace_doesnt_change_structure(self):
        oldGraph = QueryGraph()
        node = SqlCTENode("test", "Im the text content of the test node")
        oldGraph.add_node(node)
        newNode = SqlCTENode("test2", "Im the text content of the test node")
        newGraph = QueryGraph()
        newGraph.add_node(newNode)

        oldGraph.value_replace(newGraph)

        self.assertTrue(node is oldGraph.node_lookup["test"])
        self.assertEqual(len(oldGraph.node_lookup), 1)
Exemplo n.º 5
0
    def test_add_doesnt_replace_placeholder_nodes(self):
        oldGraph = QueryGraph()
        node = SqlCTENode("test", "Im the text content of the test node")
        oldGraph.add_node(node)
        newNode = PlaceholderNode("test",
                                  "Im the text content of the test node")
        newGraph = QueryGraph()
        newGraph.add_node(newNode)

        oldGraph.add_query(newGraph)

        self.assertTrue(node is oldGraph.node_lookup["test"])
Exemplo n.º 6
0
    def test_value_replace_updates_text(self):
        oldGraph = QueryGraph()
        oldGraph.add_node(SqlCTENode("test", "Im the text content of the test node"))

        newGraph = QueryGraph()
        newGraph.add_node(SqlCTENode("test", "im the new content"))

        oldGraph.value_replace(newGraph)

        self.assertEqual(oldGraph.get_node_by_name("test").get_text(),"im the new content")
Exemplo n.º 7
0
    def test_truncated_placeholder_keeps_dependencies(self):

        graph = QueryGraph()

        node = SqlCTENode("test", "test")
        node1 = SqlCTENode("test1", "test")
        node2 = SqlCTENode("test2", "test")
        node3 = SqlCTENode("test3", "test")

        node.add_dependency_node(node1)
        node1.add_dependency_node(node2)
        node2.add_dependency_node(node3)
        graph.add_node(node)
        graph.add_node(node1)
        graph.add_node(node2)
        graph.add_node(node3)

        factory = QueryGraphFactory()
        testGraph = factory.create_truncated_runnable_graph_from_node(
            node, ["test2"])

        self.assertEqual(type(testGraph.get_node_by_name("test2")),
                         PlaceholderNode)
        self.assertEqual(
            testGraph.get_node_by_name("test2").get_dependencies(),
            node2.get_dependencies())
        self.assertEqual(len(testGraph.node_lookup), 3)
Exemplo n.º 8
0
    def test_value_replace_updates_docstring(self):
        oldGraph = QueryGraph()
        node = SqlCTENode("test", "Im the text content of the test node")
        node.set_docstring("im a doc string")
        oldGraph.add_node(node)
        newNode = SqlCTENode("test", "Im the text content of the test node")
        newNode.set_docstring("im a new doc string")
        newGraph = QueryGraph()
        newGraph.add_node(newNode)

        oldGraph.value_replace(newGraph)

        self.assertEqual(oldGraph.get_node_by_name("test").get_docstring(),"im a new doc string")
Exemplo n.º 9
0
    def test_node_list_contains_all_nodes(self):
        graph = QueryGraph()
        node = SqlCTENode("test", "test")
        node1 = SqlCTENode("test1", "test")
        node2 = SqlCTENode("test2", "test")
        node3 = SqlCTENode("test3", "test")
        graph.add_node(node)
        graph.add_node(node1)
        graph.add_node(node2)
        graph.add_node(node3)

        for n in [node, node2, node3, node1]:
            self.assertEquals([n], graph.get_ordered_node_list_from_node(n))
Exemplo n.º 10
0
    def load(self):
        if os.path.isfile(self.file_name) and not self.recreate:
            with open(self.file_name, "rb") as data_file:
                graph = pickle.load(data_file)
        else:
            graph = QueryGraph()

        return graph
Exemplo n.º 11
0
    def test_add_doesnt_replace_placeholder_nodes(self):
        oldGraph = QueryGraph()
        node = SqlCTENode("test", "Im the text content of the test node")
        oldGraph.add_node(node)
        newNode = PlaceholderNode("test", "Im the text content of the test node")
        newGraph = QueryGraph()
        newGraph.add_node(newNode)

        oldGraph.add_query(newGraph)

        self.assertTrue(node is oldGraph.node_lookup["test"])
Exemplo n.º 12
0
    def test_add_with_replacement_replaces_proper_nodes(self):
        oldGraph = QueryGraph()
        node = SqlCTENode("test", "Im the text content of the test node")
        oldGraph.add_node(node)
        newNode = SqlCTENode("test", "Im the text content of the test node")
        newGraph = QueryGraph()
        newGraph.add_node(newNode)

        oldGraph.add_query(newGraph, replace = True)

        self.assertTrue(newNode is oldGraph.node_lookup["test"])
Exemplo n.º 13
0
    def test_value_replace_doesnt_change_structure(self):
        oldGraph = QueryGraph()
        node = SqlCTENode("test", "Im the text content of the test node")
        oldGraph.add_node(node)
        newNode = SqlCTENode("test2", "Im the text content of the test node")
        newGraph = QueryGraph()
        newGraph.add_node(newNode)

        oldGraph.value_replace(newGraph)

        self.assertTrue(node is oldGraph.node_lookup["test"])
        self.assertEqual(len(oldGraph.node_lookup), 1)
Exemplo n.º 14
0
    def test_node_list_contains_all_nodes(self):
        graph = QueryGraph()
        node = SqlCTENode("test", "test")
        node1 = SqlCTENode("test1", "test")
        node2 = SqlCTENode("test2", "test")
        node3 = SqlCTENode("test3", "test")

        node.add_dependency_node(node1)
        node1.add_dependency_node(node2)
        node2.add_dependency_node(node3)
        graph.add_node(node)
        graph.add_node(node1)
        graph.add_node(node2)
        graph.add_node(node3)

        self.assertEquals([node3, node2, node1, node],
                          graph.get_ordered_node_list_from_node(node))
        self.assertEquals([node3, node2, node1],
                          graph.get_ordered_node_list_from_node(node1))
Exemplo n.º 15
0
    def test_node_list_contains_all_nodes(self):
        graph = QueryGraph()
        node = SqlCTENode("test", "test")
        node1 = SqlCTENode("test1", "test")
        node2 = SqlCTENode("test2", "test")
        node3 = SqlCTENode("test3", "test")
        graph.add_node(node)
        graph.add_node(node1)
        graph.add_node(node2)
        graph.add_node(node3)

        for n in [node, node2, node3, node1]:
            self.assertEquals([n], graph.get_ordered_node_list_from_node(n))
Exemplo n.º 16
0
    def test_node_list_contains_all_nodes(self):
        graph = QueryGraph()
        node = SqlCTENode("test", "test")
        node1 = SqlCTENode("test1", "test")
        node2 = SqlCTENode("test2", "test")
        node3 = SqlCTENode("test3", "test")

        node.add_dependency_node(node1)
        node1.add_dependency_node(node2)
        node2.add_dependency_node(node3)
        graph.add_node(node)
        graph.add_node(node1)
        graph.add_node(node2)
        graph.add_node(node3)

        self.assertEquals([node3, node2, node1, node], graph.get_ordered_node_list_from_node(node))
        self.assertEquals([node3, node2, node1], graph.get_ordered_node_list_from_node(node1))
Exemplo n.º 17
0
 def create_truncated_runnable_graph_from_node(self, node, stopping_names: List[str]):
     graph = QueryGraph()
     graph.add_node(node)
     depList = node.get_dependencies()
     while len(depList) != 0:
         stoppedList, addList = [x for x in depList if x.get_name() in stopping_names], [x for x in depList if x.get_name() not in stopping_names]
         [graph.add_node(copy(x)) for x in addList]
         for item in stoppedList:
             placeholderNode = PlaceholderNode(item.get_name(), "")
             placeholderNode.dependencies = item.get_dependencies()
             graph.add_node(placeholderNode)
         dependentNodes = [x.get_dependencies() for x in depList if x not in stoppedList]
         depList = [item for sublist in dependentNodes for item in sublist]
     return graph
Exemplo n.º 18
0
 def create_truncated_runnable_graph_from_node(self, node,
                                               stopping_names: List[str]):
     graph = QueryGraph()
     graph.add_node(node)
     depList = node.get_dependencies()
     while len(depList) != 0:
         stoppedList, addList = [
             x for x in depList if x.get_name() in stopping_names
         ], [x for x in depList if x.get_name() not in stopping_names]
         [graph.add_node(copy(x)) for x in addList]
         for item in stoppedList:
             placeholderNode = PlaceholderNode(item.get_name(), "")
             placeholderNode.dependencies = item.get_dependencies()
             graph.add_node(placeholderNode)
         dependentNodes = [
             x.get_dependencies() for x in depList if x not in stoppedList
         ]
         depList = [item for sublist in dependentNodes for item in sublist]
     return graph
Exemplo n.º 19
0
    def extract_connected_graph_of_nodes(self, query_graph: QueryGraph,
                                         node: Node):
        graph = QueryGraph()

        total_included = [node]
        additions = True
        while additions:
            additions = False

            for nodeName in query_graph.node_lookup:
                node_considered = query_graph.node_lookup[nodeName]
                if node_considered in total_included:
                    continue
                if any([
                        node_x in node_considered.get_dependencies()
                        or node_considered in node_x.get_dependencies()
                        for node_x in total_included
                ]):
                    total_included.append(node_considered)
                    additions = True

        return self.create_graph_from_node_list(
            [copy(x) for x in total_included])
Exemplo n.º 20
0
    def test_truncated_placeholder_keeps_dependencies(self):

        graph = QueryGraph()

        node = SqlCTENode("test", "test")
        node1 = SqlCTENode("test1", "test")
        node2 = SqlCTENode("test2", "test")
        node3 = SqlCTENode("test3", "test")

        node.add_dependency_node(node1)
        node1.add_dependency_node(node2)
        node2.add_dependency_node(node3)
        graph.add_node(node)
        graph.add_node(node1)
        graph.add_node(node2)
        graph.add_node(node3)

        factory = QueryGraphFactory()
        testGraph = factory.create_truncated_runnable_graph_from_node(node, ["test2"])

        self.assertEqual(type(testGraph.get_node_by_name("test2")), PlaceholderNode)
        self.assertEqual(testGraph.get_node_by_name("test2").get_dependencies(), node2.get_dependencies())
        self.assertEqual(len(testGraph.node_lookup), 3)
Exemplo n.º 21
0
    def extract_graph_between_nodes(self, start_node : Node, end_node : Node):
        graph = QueryGraph()
        graph.add_node(start_node)

        return graph
Exemplo n.º 22
0
    def create_graph_from_node_list(self, node_list: List[Node]):
        graph = QueryGraph()
        for node in node_list:
            graph.add_node(node)

        return graph
Exemplo n.º 23
0
    def test_add_replace_segment_updates_dependencies(self):
        oldGraph = QueryGraph()
        node = SqlCTENode("test", "Im the text content of the test node")
        node1 = SqlCTENode("test1", "Im the text content of the test node")
        node.add_dependency_node(node1)
        oldGraph.add_node(node)
        oldGraph.add_node(node1)

        newNode = PlaceholderNode("test", "Im the text content of the test node")
        newNode2 = SqlCTENode("test2", "Im the text content of the test node")
        newNode1 = PlaceholderNode("test1", "Im the text content of the test node")
        newNode.add_dependency_node(newNode2)
        newNode2.add_dependency_node(newNode1)

        newGraph = QueryGraph()

        newGraph.add_node(newNode)
        newGraph.add_node(newNode2)
        newGraph.add_node(newNode1)

        oldGraph.add_query(newGraph)

        self.assertEqual(oldGraph.get_node_by_name("test").get_dependencies(), [newNode2])
Exemplo n.º 24
0
 def test_add_node(self):
     graph = QueryGraph()
     node = SqlCTENode("test", "test")
     graph.add_node(node)
     self.assertEqual(graph.get_node_by_name("test"), node)
Exemplo n.º 25
0
    def test_value_replace_updates_docstring(self):
        oldGraph = QueryGraph()
        node = SqlCTENode("test", "Im the text content of the test node")
        node.set_docstring("im a doc string")
        oldGraph.add_node(node)
        newNode = SqlCTENode("test", "Im the text content of the test node")
        newNode.set_docstring("im a new doc string")
        newGraph = QueryGraph()
        newGraph.add_node(newNode)

        oldGraph.value_replace(newGraph)

        self.assertEqual(
            oldGraph.get_node_by_name("test").get_docstring(),
            "im a new doc string")
Exemplo n.º 26
0
    def test_value_replace_updates_text(self):
        oldGraph = QueryGraph()
        oldGraph.add_node(
            SqlCTENode("test", "Im the text content of the test node"))

        newGraph = QueryGraph()
        newGraph.add_node(SqlCTENode("test", "im the new content"))

        oldGraph.value_replace(newGraph)

        self.assertEqual(
            oldGraph.get_node_by_name("test").get_text(), "im the new content")
Exemplo n.º 27
0
 def test_add_node(self):
     graph = QueryGraph()
     node = SqlCTENode("test", "test")
     graph.add_node(node)
     self.assertEqual(graph.get_node_by_name("test"), node)
Exemplo n.º 28
0
    def test_add_segment_updates_dependencies(self):
        oldGraph = QueryGraph()
        node = SqlCTENode("test", "Im the text content of the test node")
        node1 = SqlCTENode("test1", "Im the text content of the test node")
        node3 = SqlCTENode("test3", "Fill me!")
        node.add_dependency_node(node1)
        node.add_dependency_node(node3)
        oldGraph.add_node(node)
        oldGraph.add_node(node1)
        oldGraph.add_node(node3)

        newNode = PlaceholderNode("test",
                                  "Im the text content of the test node")
        newNode2 = SqlCTENode("test2", "Im the text content of the test node")
        newNode1 = PlaceholderNode("test1",
                                   "Im the text content of the test node")
        newNode.add_dependency_node(newNode2)
        newNode2.add_dependency_node(newNode1)

        newGraph = QueryGraph()

        newGraph.add_node(newNode)
        newGraph.add_node(newNode2)
        newGraph.add_node(newNode1)

        oldGraph.add_query(newGraph)

        self.assertTrue(
            newNode2 in oldGraph.get_node_by_name("test").get_dependencies())
        self.assertTrue(
            node3 in oldGraph.get_node_by_name("test").get_dependencies())
Exemplo n.º 29
0
    def test_add_replace_segment_updates_dependencies(self):
        oldGraph = QueryGraph()
        node = SqlCTENode("test", "Im the text content of the test node")
        node1 = SqlCTENode("test1", "Im the text content of the test node")
        node.add_dependency_node(node1)
        oldGraph.add_node(node)
        oldGraph.add_node(node1)

        newNode = PlaceholderNode("test",
                                  "Im the text content of the test node")
        newNode2 = SqlCTENode("test2", "Im the text content of the test node")
        newNode1 = PlaceholderNode("test1",
                                   "Im the text content of the test node")
        newNode.add_dependency_node(newNode2)
        newNode2.add_dependency_node(newNode1)

        newGraph = QueryGraph()

        newGraph.add_node(newNode)
        newGraph.add_node(newNode2)
        newGraph.add_node(newNode1)

        oldGraph.add_query(newGraph)

        self.assertEqual(
            oldGraph.get_node_by_name("test").get_dependencies(), [newNode2])
Exemplo n.º 30
0
    def test_add_segment_updates_dependencies(self):
        oldGraph = QueryGraph()
        node = SqlCTENode("test", "Im the text content of the test node")
        node1 = SqlCTENode("test1", "Im the text content of the test node")
        node3 = SqlCTENode("test3", "Fill me!")
        node.add_dependency_node(node1)
        node.add_dependency_node(node3)
        oldGraph.add_node(node)
        oldGraph.add_node(node1)
        oldGraph.add_node(node3)

        newNode = PlaceholderNode("test", "Im the text content of the test node")
        newNode2 = SqlCTENode("test2", "Im the text content of the test node")
        newNode1 = PlaceholderNode("test1", "Im the text content of the test node")
        newNode.add_dependency_node(newNode2)
        newNode2.add_dependency_node(newNode1)

        newGraph = QueryGraph()

        newGraph.add_node(newNode)
        newGraph.add_node(newNode2)
        newGraph.add_node(newNode1)

        oldGraph.add_query(newGraph)

        self.assertTrue(newNode2 in oldGraph.get_node_by_name("test").get_dependencies())
        self.assertTrue(node3 in oldGraph.get_node_by_name("test").get_dependencies())
Exemplo n.º 31
0
    def test_add_replace_segment_adds_new_node(self):
        oldGraph = QueryGraph()
        node = SqlCTENode("test", "Im the text content of the test node")
        node1 = SqlCTENode("test1", "Im the text content of the test node")
        node.add_dependency_node(node1)
        oldGraph.add_node(node)
        oldGraph.add_node(node1)

        newNode = PlaceholderNode("test",
                                  "Im the text content of the test node")
        newNode2 = SqlCTENode("test2", "Im the text content of the test node")
        newNode1 = PlaceholderNode("test1",
                                   "Im the text content of the test node")
        newNode.add_dependency_node(newNode2)
        newNode2.add_dependency_node(newNode1)

        newGraph = QueryGraph()

        newGraph.add_node(newNode)
        newGraph.add_node(newNode2)
        newGraph.add_node(newNode1)

        oldGraph.add_query(newGraph)

        self.assertTrue(oldGraph.get_node_by_name("test2") is newNode2)
Exemplo n.º 32
0
    def create_graph_from_node_list(self, node_list: List[Node]):
        graph = QueryGraph()
        for node in node_list:
            graph.add_node(node)

        return graph
Exemplo n.º 33
0
    def test_add_replace_segment_adds_new_node(self):
        oldGraph = QueryGraph()
        node = SqlCTENode("test", "Im the text content of the test node")
        node1 = SqlCTENode("test1", "Im the text content of the test node")
        node.add_dependency_node(node1)
        oldGraph.add_node(node)
        oldGraph.add_node(node1)

        newNode = PlaceholderNode("test", "Im the text content of the test node")
        newNode2 = SqlCTENode("test2", "Im the text content of the test node")
        newNode1 = PlaceholderNode("test1", "Im the text content of the test node")
        newNode.add_dependency_node(newNode2)
        newNode2.add_dependency_node(newNode1)

        newGraph = QueryGraph()

        newGraph.add_node(newNode)
        newGraph.add_node(newNode2)
        newGraph.add_node(newNode1)

        oldGraph.add_query(newGraph)

        self.assertTrue(oldGraph.get_node_by_name("test2") is newNode2)
Exemplo n.º 34
0
    def extract_graph_between_nodes(self, start_node: Node, end_node: Node):
        graph = QueryGraph()
        graph.add_node(start_node)

        return graph