예제 #1
0
def test_flush_nodes_changing_node():
    # exact same test as non changing node except have to get different synonym map from flush_nodes
    node = KNode('MESH:D000096', type=node_types.CHEMICAL_SUBSTANCE)
    properties = {'a': 'some prop'}
    node.properties = properties

    bf = BufferedWriter(rosetta_mock)

    bf.write_node(node)

    def write_transaction_mock(export_func, nodes, types):
        print(types)
        # make sure this is the right function
        assert export_func == export_node_chunk
        # make sure we have out node id in there
        assert node.id in nodes
        # get the node and see if the properties are preserved
        assert nodes[node.id].properties == properties
        # see if the types are expected
        assert nodes[node.id].export_labels == types == frozenset([
            "chemical_substance", "named_thing", "biological_entity",
            "molecular_entity"
        ])

    session = Mock()
    session.write_transaction = write_transaction_mock
    # pass the mock tester to bf and let it rip
    bf.flush_nodes(session)

    # make sure the synonym map we get here to be used for edge correction is sane
    assert 'MESH:D000096' in bf.synonym_map
    assert bf.synonym_map['MESH:D000096'] == 'CHEBI:15347'
예제 #2
0
def test_flush_nodes_non_normilizable():
    # exact same test as non changing node except have to get different synonym map from flush_nodes
    node = KNode('SOME:curie', type=node_types.CHEMICAL_SUBSTANCE)
    properties = {'a': 'some prop'}
    node.properties = properties

    bf = BufferedWriter(rosetta_mock)

    bf.write_node(node)

    def write_transaction_mock(export_func, nodes, types):
        print(types)
        # make sure this is the right function
        assert export_func == export_node_chunk
        # make sure we have out node id in there
        assert node.id in nodes
        # get the node and see if the properties are preserved
        assert nodes[node.id].properties == properties
        # see if the types are expected
        assert nodes[node.id].export_labels == []
        assert types == frozenset()

    session = Mock()
    session.write_transaction = write_transaction_mock
    # pass the mock tester to bf and let it rip
    bf.flush_nodes(session)

    # make sure the synonym map we get here to be used for edge correction is sane
    assert 'SOME:curie' in bf.synonym_map
    assert bf.synonym_map['SOME:curie'] == 'SOME:curie'
예제 #3
0
def test_flush_nodes_non_changing_node():
    # test if nodes are sent to export function if they are already assigned primary id
    node = KNode('CHEBI:15347', type=node_types.CHEMICAL_SUBSTANCE)
    properties = {'a': 'some prop'}
    node.properties = properties

    bf = BufferedWriter(rosetta_mock)
    # label_by_export_graph = ['this_should_be_overridden']
    # def mock_add_labels(node): node.add_export_labels(label_by_export_graph)
    # # patch export_graph.add_type_labels and see if its called
    # bf.export_graph.add_type_labels = mock_add_labels

    # we add the node
    bf.write_node(node)

    def write_transaction_mock(export_func, nodes, types):
        print(types)
        # make sure this is the right function
        assert export_func == export_node_chunk
        # make sure we have out node id in there
        assert node.id in nodes
        # get the node and see if the properties are preserved
        assert nodes[node.id].properties == properties
        # see if the types are expected
        assert nodes[node.id].export_labels == types == frozenset([
            "chemical_substance", "named_thing", "biological_entity",
            "molecular_entity"
        ])

    session = Mock()
    session.write_transaction = write_transaction_mock
    # pass the mock tester to bf and let it rip
    bf.flush_nodes(session)

    # make sure the synonym map we get here to be used for edge correction is sane
    assert 'CHEBI:15347' in bf.synonym_map
    assert bf.synonym_map['CHEBI:15347'] == 'CHEBI:15347'