def test_node_not_in_graph(self, target_node, test_input):
        """Should raise an error if the target_node is not found in the graph"""

        sm = StructureModel()
        sm.add_edges_from(test_input)

        with pytest.raises(
                NodeNotFound,
                match=f"Node {target_node} not found in the graph",
        ):
            sm.get_markov_blanket(target_node)
    def test_instance_type(self):
        """The subgraph returned should still be a StructureModel instance"""

        sm = StructureModel()
        sm.add_edges_from([(0, 1), (1, 2), (1, 3), (4, 6)])
        subgraph = sm.get_markov_blanket(2)

        assert isinstance(subgraph, StructureModel)
    def test_get_markov_blanket_string(self, target_node, test_input,
                                       expected):
        """Should be able to return the subgraph with the specified node"""

        sm = StructureModel()
        sm.add_edges_from(test_input)
        blanket = sm.get_markov_blanket(target_node)
        expected_graph = StructureModel()
        expected_graph.add_edges_from(expected)

        assert set(blanket.nodes) == set(expected_graph.nodes)
        assert set(blanket.edges) == set(expected_graph.edges)
    def test_get_markov_blanket_multiple(self, target_nodes, test_input,
                                         expected):
        """Should be able to return Markov blanket with the specified list of nodes"""

        sm = StructureModel()
        sm.add_edges_from(test_input)
        blanket = sm.get_markov_blanket(target_nodes)
        expected_graph = StructureModel()
        expected_graph.add_edges_from(expected)

        assert set(blanket.nodes) == set(expected_graph.nodes)
        assert set(blanket.edges) == set(expected_graph.edges)
    def test_isolates(self):
        """Should return an isolated node"""

        nodes = [1, 3, 5, 2, 7]
        sm = StructureModel()
        sm.add_nodes_from(nodes)
        blanket = sm.get_markov_blanket(1)

        expected_graph = StructureModel()
        expected_graph.add_node(1)

        assert set(blanket.nodes) == set(expected_graph.nodes)
        assert set(blanket.edges) == set(expected_graph.edges)
    def test_isolates_nodes_and_edges(self):
        """Should be able to return the subgraph with the specified node"""

        edges = [(0, 1), (1, 2), (1, 3), (5, 6), (4, 5)]
        isolated_nodes = [7, 8, 9]
        sm = StructureModel()
        sm.add_edges_from(edges)
        sm.add_nodes_from(isolated_nodes)
        subgraph = sm.get_markov_blanket(5)
        expected_edges = [(5, 6), (4, 5)]
        expected_graph = StructureModel()
        expected_graph.add_edges_from(expected_edges)

        assert set(subgraph.nodes) == set(expected_graph.nodes)
        assert set(subgraph.edges) == set(expected_graph.edges)